-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
Include shared schemas in response #172
Comments
What does it mean “it works”? @Eomm is the master of shared schemas, he might take a look here as well. |
Using "bar#" (which is not a common/shared schema) works. Shared schema doesn't. |
This should work (with last
When you write |
I thought I tested that case and it didn't work, but I'll try again in the morning. |
UnhandledPromiseRejectionWarning: TypeError: Cannot read property '$ref' of undefined |
Looking here: Line 96 in c41d37c
Maybe, the shared schemas are not provided to swagger. I can't go deeper now, could you check it? |
when using 'bar#', the schema is transformed to an object, with the ref it's not. I've decided to move forward with multiple schema files instead of common.json. |
Going back and forth experimenting with the schemas. I found some inconsistencies: works: body: { $ref: '/foo.json#/definitions/bar' } fails: response: {
200: { $ref: '/foo.json#/definitions/bar' }
}
Then I tried response: {
200: '/foo.json#/definitions/bar'
}
|
Yeah, that doesn't surprise me:
For the trouble:
|
It's a long list ... I selected the path that might be the one you're looking for:
started the project from scratch, so the dependencies should all be up-to-date. If you point me into the direction, I'm happy to help fix this, as I need it in my current project. |
Sorry @PatrickHeneise , I missed your comment. Did you solve meanwhile? Otherwise, I will check this problem in next days |
No, I worked around the issue by placing the schema I need in |
I've almost the same problem. The swagger doesn't recognize some shared schemas. There are 4 routes: GET /api/auth-broken -> fails in UI with Could not resolve reference: undefined undefined Are there any ways to avoid this? Or should we waiting for fixing? |
Came across the same issue today. This works, when the response is of type array response: {
200: {
description: 'Successful response',
type: 'array',
items: {
$ref: '#Journal',
},
},
}, But this doesn't work when response is an object. I don't know if this is the intended behaviour. response: {
200: {
description: 'Successful response',
type: 'object',
$ref: '#Journal',
},
}, As a workaround, I used response: {
200: {
description: 'Successful response',
type: 'object',
...(fastify.getSchema('#Journal') as object), // silence typescript
},
}, Option 2. response: {
200: fastify.getSchema('#Journal')
}, |
Does anybody here have a full example of referencing the models from dynamic routes the Swagger way? "responses": {
"500": {
"schema": {
"$ref": "#/definitions/ErrorModel"
}
}
} I've tried to put "definitions" into their place in the plugin options, but that did not work. Should it be a separate feature request? |
So when I did addSchema({
$id: 'shared',
definitions
}); then this response definition does not blow up fastify
However, in this case the schema is nested and the path is transformed in output: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Using: fastify.addSchema({
$id: 'shared',
type: 'object',
definitions: {
internalServerErrorResponse: {
type: 'object',
description: '500 Internal Server Error',
properties: {
message: {
type: 'string',
description: 'Error message',
example: 'Some internal error message'
}
}
}
}
}) And then use the shared definition: 500: {
$ref: 'shared#/definitions/internalServerErrorResponse'
} I will get: |
OpenAPI v3 component responses also doesn't work in Fastify Swagger, so I created a ticket for that: #793 |
Now I'm using fastify.addSchema({
$id: 'internalServerErrorResponse',
type: 'object',
description: '500 Internal Server Error',
properties: {
message: {
type: 'string',
description: 'Error message',
example: 'Some internal error message'
}
}
}) Then use it in your schema like this: schema: {
description: 'example',
response: {
500: {
$ref: 'internalServerErrorResponse#'
}
}
} This ALMOST works.. Except the description message still says "Default Response" in Swagger UI: |
I use a shared schema:
And trying to use that schema in the response validation:
It works perfectly fine in a list/index route:
but not for get /:id
I'm trying to track down the issue but would appreciate a hint to where to start. Everything works fine if I add the schema "bar" individually before:
The text was updated successfully, but these errors were encountered: