Describe the bug
Serdes performs well on properties in an object. However, when the owning object is part of an array, then serialize is never called.
To Reproduce
git clone https://github.com/cdimascio/express-openapi-validator.git
npm run deps && npm i
cd express-openapi-validator/examples/7-response-date-serialization
npm start
GET http://localhost:3000/v1/date-time
The above works fine.
Let's now modify the route in app.js to return an array of objects:
app.get('/v1/date-time', function (req, res, next) {
res.json(
// {
// id: 1,
// created_at: new Date(),
// }
[
{
id: 1,
created_at: new Date(),
}
]
);
});
We'll also modify the schema in api.yaml:
/date-time:
get:
responses:
200:
description: date-time handler
content:
application/json:
schema:
# type: object
# properties:
# created_at:
# type: string
# format: date-time
# id:
# type: number
type: array
items:
type: object
properties:
created_at:
type: string
format: date-time
id:
type: number
Actual behavior
{
"message": ".response[0].created_at should be string",
"errors": [
{
"path": ".response[0].created_at",
"message": "should be string",
"errorCode": "type.openapi.validation"
}
]
}
Expected behavior
[
{
"id": 1,
"created_at": "2022-01-20T17:40:41.816Z"
}
]
Describe the bug
Serdes performs well on properties in an object. However, when the owning object is part of an array, then
serializeis never called.To Reproduce
git clone https://github.com/cdimascio/express-openapi-validator.gitnpm run deps && npm icd express-openapi-validator/examples/7-response-date-serializationnpm startGET http://localhost:3000/v1/date-timeThe above works fine.
Let's now modify the route in
app.jsto return an array of objects:We'll also modify the schema in
api.yaml:Actual behavior
Expected behavior