New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: reset json pointer in merged allOf schema #482
Conversation
@@ -493,6 +493,7 @@ function mergeAllOfSchema (location, schema, mergedSchema) { | |||
mergedSchema.$id = `merged_${randomUUID()}` | |||
ajvInstance.addSchema(mergedSchema) | |||
location.schemaId = mergedSchema.$id | |||
location.jsonPointer = '#' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it be problem of deeply nested schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should work with nested schemas. Can you provide an example of what you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get my answer when I create the example.
Here comes one problem related to previous fix.
Recursive $ref
will be a problem when using allOf
.
It may not be a good usage.
{
$id: 'base',
anyOf: [
{
type: 'object',
allOf: [
{
properties: {
a: {
anyOf: [
{ const: 'A1' },
{ const: 'A2' }
]
}
}
},
{
properties: {
b: { const: 'B' }
}
},
{
properties: {
c: {
oneOf: [
{ $ref: 'base' },
{ type: 'null' }
]
}
}
}
]
}
]
}
{
$id: 'base',
type: 'object',
allOf: [
{
properties: {
a: {
anyOf: [
{ const: 'A1' },
{ const: 'A2' }
]
}
}
},
{
properties: {
b: { const: 'B' }
}
},
{
properties: {
c: {
oneOf: [
{ $ref: 'base' },
{ type: 'null' }
]
}
}
}
]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can fix this. But there are some other problems with merging schemas that we should also. We can't use deepMerge for merging. I was trying to make it better #453, but it's not enough. We can check how json-schema-merge-allof works.
In general, we have some places where we have troubles (if/then, oneOf, anyOf, allOf, type array), bc json schema format designed for validation and described input types and we use json schema for serialization and ask people to describe output types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know another good library that uses json schema for serialization. @climba03003 @Eomm @mcollina If you know, please share a link. It will help in the design process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it worth an issue for discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Checklist
npm run test
andnpm run benchmark
and the Code of conduct
Fix #481
Fix fastify/fastify#4092
#480 sets merged schema as a location, but doesn't set json pointer to the root of this merged schema.