-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Main schemas isolation #81
Comments
I think those two schemas are just wrong. You've written two schemas that self-referencially create schemas with conflicting identifiers. Every schema in the container should have a unique identifier. If schemas have conflicting identifiers then the schema author(s) have done it wrong. See https://json-schema.org/draft/2020-12/json-schema-core.html#name-the-id-keyword |
So users can't create two endpoints with the same nested schemas? So users can't create two endpoints with the same nested schemas? I thought that all context schemas that you add with @jsumners So you think that users should not create routes like that? fastify.post('/a', {
handler () { },
schema: {
type: 'object',
properties: {
a: { $id: 'globalId', type: 'string' },
b: { $ref: 'globalId' },
}
}
})
fastify.post('/b', {
handler () { },
schema: {
type: 'object',
properties: {
a: { $id: 'globalId', type: 'integer' },
b: { $ref: 'globalId' },
}
}
}) |
You are specifying anonymous schemas in that example. They do not have identifiers. Your |
You can reference the property either with json pointer or schema $id. I wrote valid JSON schema draft 7 syntaxes. + Ajv works in this way. |
I didn't say the schemas are invalid, only that the values used for the |
Ok, I wrote valid values in That's a quote from the link you sent me. |
Look at the example you linked. All |
fastify.post('/a', {
handler () { },
schema: {
$id: 'hello',
type: 'object',
properties: {
a: { $id: 'hello/globalId', type: 'string' },
b: { $ref: 'hello/globalId' },
}
}
})
fastify.post('/b', {
handler () { },
schema: {
$id: 'hello',
type: 'object',
properties: {
a: { $id: 'hello/globalId', type: 'integer' },
b: { $ref: 'hello/globalId' },
}
}
}) |
I'm sorry, I really don't understand what you are trying to prove. As I originally stated, schema identifiers are URIs by spec (https://json-schema.org/draft/2020-12/json-schema-core.html#name-the-id-keyword). URIs, by spec (https://www.rfc-editor.org/rfc/rfc3986#section-1.1), are unique globally:
Therefore, schemas in a schema container, e.g. an AJV instance, can either be anonymous or identified by identifiers specified by their |
I'm talking about isolation. I'm asking maybe two route schemas shouldn't be in the same container. fastify.addSchema(/* A */)
fastify.addSchema(/* B */)
fastify.post('/foo', {
handler () { },
schema: { /* C */ }
})
fastify.post('/bar', {
handler () { },
schema: { /* D */ }
}) Maybe we should have 2 containers: { 'A', 'B', 'C' } and { 'A', 'B', 'D' } |
If you and someone else will confirm that it's a user's responsibility to manage conflicts between routes' schemas, that they are in the same namespace, and that they can be referenced to each other, I would be ok with it. |
I think your test is a reasonable use case but creating an ajv container for each route is overkilling. We could set the Unluckily, because of the
|
@Eomm It looks like addUsedSchema already resolves that. And the error was caused by type coercion. |
Prerequisites
Issue
I'm working on some optimization for FJS and trying to resolve the endpoints' schemas isolation. I was wondering how it was resolved here, but it turns out all endpoints' schemas are in the same context.
The problem is that you can define a nested schema in a global namespace.
The text was updated successfully, but these errors were encountered: