You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.22.0
Plugin version
No response
Node.js version
18.x
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
not relevant
Description
PR#630 introduced new serialization for anyOf or oneOf in object schemas.
When these are defined on an object schema, the parsed value leaves a trailing comma which breaks the JSON standard.
Steps to Reproduce
importfastJsonfrom'fast-json-stringify'// A schema that defines that `prop1` is mandatory and either `prop2` or `prop3` must be provided// but both of these props can be provided as wellconstschema={type: 'object',properties: {prop1: {type: 'string'},prop2: {type: 'string'},prop3: {type: 'string'},},required: ['prop1'],anyOf: [{required: ['prop2']},{required: ['prop3']}],}conststringify=fastJson(schema)console.log(stringify({prop1: 'test',prop2: 'test2'}))// output: {"prop1":"test","prop2":"test2",}console.log(stringify({prop1: 'test',prop3: 'test3'}))// output: {"prop1":"test","prop3":"test3",}console.log(stringify({prop1: 'test',prop2: 'test2',prop3: 'test3'}))// output: {"prop1":"test","prop2":"test2","prop3":"test3",}
it's the same for oneOf instead of anyOf
Expected Behavior
return a proper stringified version of the object provided without the trailing comma.
The text was updated successfully, but these errors were encountered:
Prerequisites
Fastify version
4.22.0
Plugin version
No response
Node.js version
18.x
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
not relevant
Description
PR#630 introduced new serialization for
anyOf
oroneOf
in object schemas.When these are defined on an object schema, the parsed value leaves a trailing comma which breaks the JSON standard.
Steps to Reproduce
it's the same for
oneOf
instead ofanyOf
Expected Behavior
return a proper stringified version of the object provided without the trailing comma.
The text was updated successfully, but these errors were encountered: