serDes is not working with OpenAPI parameters
See original GitHub issueDescribe the bug When there is described parameter with format in parameters section they are not handled by serDes.
To Reproduce
Add format: customOne
in requestBody
and in parameters
and define handler in serDes
, only the requestBody
will be handled.
Actual behavior
Only the requestBody
formats are handled by serDes
definitions.
Expected behavior
All inputs must be handled by serDes
definitions.
Examples and context
index.js
const OpenApiValidator = require("express-openapi-validator");
const express = require("express");
const http = require("http");
const app = express();
app.use(express.json());
app.use(express.text());
app.use(express.urlencoded({ extended: false }));
app.use(
OpenApiValidator.middleware({
apiSpec: "./openapi.yaml",
unknownFormats: ["customOne"],
serDes: [
{
format: "customOne",
deserialize: (s) => {
return { customObjectValue: s };
},
serialize: (o) => o.toString(),
}],
},
),
);
app.post("/test/:param1", function(req, res, next) {
res.json({
"req.params.param1": req.params.param1,
"typeof.req.params.param1": typeof req.params.param1, // fail
"req.params.param2": req.query.param2,
"typeof.req.params.param2": typeof req.query.param2, // fail
"req.params.param3": req.body.param3,
"typeof.req.params.param3": typeof req.body.param3, // success
});
});
http.createServer(app).listen(3001);
console.log("http://127.0.0.1:3001/");
openapi.yaml
openapi: "3.0.0"
info:
version: 1.0.0
title: api-test-gateway
paths:
/test/{param1}:
post:
description: Test serializations
parameters:
- name: param1
in: path
required: true
schema:
type: string
format: customOne
- name: param2
in: query
required: true
schema:
type: string
format: customOne
requestBody:
content:
application/json:
schema:
type: object
required:
- param3
properties:
param3:
type: string
format: customOne
responses:
"200":
description: Successful response
content:
application/json:
schema:
type: object
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (9 by maintainers)
Top Results From Across the Web
express-openapi-validator - Bountysource
Describe the bug. When there is described parameter with format in parameters section they are not handled by serDes. To Reproduce
Read more >Parameter(required = false) not working in swagger open api v3
my problem is with annotation @Parameter that belongs to io.swagger.v3.oas.annotations.Parameter. by default should be required = false, but as ...
Read more >JSON Schema Serializer and Deserializer
Both the JSON Schema serializer and deserializer can be configured to fail if the payload is not valid for the given schema. This...
Read more >Parameter Serialization - Swagger
OpenAPI 3.0 supports arrays and objects in operation parameters (path, ... style and explode cover the most common serialization methods, but not all....
Read more >Working with OpenAPI definitions for HTTP APIs
As another example, while OpenAPI allows users to define an API with multiple security requirements attached to a particular operation, API Gateway does...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I found the issue: my parameters are declared under the route, not under the method, like this:
The issue also happens for basic types, so it’s not related to
serDes
.Hi @agavazov and @cdimascio Happy to see serDes feature is used. I try to have a look in the next two weeks.