Serdes Does Not Work for Items in Object in Array
See original GitHub issueDescribe 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"
}
]
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Array.includes() to find object in array - Stack Overflow
Array.includes compares by object identity just like obj === obj2 , so sadly this doesn't work unless the two items are references to...
Read more >Kafka Streams Data Types and Serialization
Every Kafka Streams application must provide Serdes (Serializer/Deserializer) for the data types of record keys and record values (e.g. java.lang.String or Avro ...
Read more >cocobelgica/AutoHotkey-SerDes: Serialize / de ... - GitHub
Serilaized output is similar to JSON except for escape sequences which follows AHK's specification. · Non-standard AHK objects such as COM, Func, FileObject, ......
Read more >for...in - JavaScript | MDN - MDN Web Docs
Objects created from built–in constructors like Array and Object have ... In general, it is best not to add, modify, or remove properties...
Read more >Querying arrays with complex types and nested structures
When you query tables within Athena, you do not need to create ROW data types, ... within an element inside an array, using...
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
We are waiting for the approve of the repository owner
This is now available in v5.0.0