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.28.1
Plugin version
No response
Node.js version
20.17.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
22h2
Description
When I add additional properties to a subschema in anyOf, I receive the following error:
TypeError: The value of '#/properties/snippet' does not match schema definition.
Code to reproduce:
importfastJsonfrom'fast-json-stringify';constprofileObject={snippet: {username: '',additionalProperty: '',},};constsnippetSchema={type: 'object',properties: {username: {type: 'string'}},required: ['username'],additionalProperties: false};constprofileSchemaOptional={type: 'object'asconst,properties: {snippet: snippetSchema},additionalProperties: false,$schema: 'http://json-schema.org/draft-07/schema#'};constoptionalStringify=fastJson(profileSchemaOptional);console.log(optionalStringify(profileObject));// okconstprofileSchemaNullable={type: 'object'asconst,properties: {snippet: {anyOf: [snippetSchema,{type: 'null'}// This line can be removed, but the error will persist.]}},additionalProperties: false,$schema: 'http://json-schema.org/draft-07/schema#'};constnullableStringify=fastJson(profileSchemaNullable);console.log(nullableStringify(profileObject));// throws error
Note: The optionalStringify(profileObject) call allows additional properties in snippetSchema, whereas nullableStringify(profileObject) does not allow them.
Link to code that reproduces the bug
No response
Expected Behavior
Subschemas within anyOf should be serialized just like normal subschemas.
If additionalProperties is not present or is set to false, every property that is not explicitly listed in the properties and patternProperties objects,will be ignored, as described in Missing fields.
Missing fields are ignored to avoid having to rewrite objects before serializing.
The text was updated successfully, but these errors were encountered:
I have already created an issue in the main repository at fastify/fastify#5647, but since the problem originates from fast-json-stringify, I have also opened an issue here.
FYI: When "type": ["string", "null"] is used instead of anyOf, it works well for nullable cases. I've submitted an issue to the zod-to-json-schema repository to support this feature. StefanTerdell/zod-to-json-schema#142
Since anyOf, oneOf, and allOf are logical validators in JSON Schema that manage how data matches against multiple criteria defined through sub-schemas, this seems to be the expected behavior.
Prerequisites
Fastify version
4.28.1
Plugin version
No response
Node.js version
20.17.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
22h2
Description
When I add additional properties to a subschema in
anyOf
, I receive the following error:Code to reproduce:
Note: The
optionalStringify(profileObject)
call allows additional properties insnippetSchema
, whereasnullableStringify(profileObject)
does not allow them.Link to code that reproduces the bug
No response
Expected Behavior
Subschemas within
anyOf
should be serialized just like normal subschemas.The text was updated successfully, but these errors were encountered: