Closed gusparr28 closed 1 year ago
This question is totally unclear to me.
Maybe Add examples to the schema
?
Yup, that's what I'm asking for. I tried that solution before opening the issue but didn't work for me. I have this body:
body: {
type: 'object',
required: ['username', 'password', 'trustId'],
properties: {
username: {
description: 'Username for login',
type: 'string',
},
password: {
description: 'Password for login',
type: 'string',
},
trustId: {
description: 'Device trust id',
type: 'string',
},
},
examples: [
{
username: '123456785',
},
{
password: 'Testtest1!',
},
{
trustId: v4(),
},
],
}
and I can't see the example values in my Swagger UI
Could you add a Minimal, Reproducible Example?
Without it, we are unable to help you.
You should use example and not examples property. https://swagger.io/docs/specification/adding-examples/
You should use example and not examples property. https://swagger.io/docs/specification/adding-examples/
it looks like example property does not exist
Just tried these both and I got compiling error:
body: {
type: 'object',
required: ['username', 'password', 'trustId'],
properties: {
username: {
description: 'Username for login',
type: 'string',
},
password: {
description: 'Password for login',
type: 'string',
},
trustId: {
description: 'Device trust id',
type: 'string',
},
},
example: {
username: '123456785',
password: 'Testtest1!',
trustId: v4(),
},
}
body: {
type: 'object',
required: ['username', 'password', 'trustId'],
properties: {
username: {
description: 'Username for login',
type: 'string',
},
password: {
description: 'Password for login',
type: 'string',
},
trustId: {
description: 'Device trust id',
type: 'string',
},
},
example: [
{
username: '123456785',
},
{
password: 'Testtest1!',
},
{
trustId: v4(),
},
],
}
err: {
"type": "FastifyError",
"message": "Failed building the validation schema for POST:, due to error strict mode: unknown keyword: \"example\"",
"stack":
FastifyError: Failed building the validation schema for POST, due to error strict mode: unknown keyword: "example"
"name": "FastifyError",
"code": "FST_ERR_SCH_VALIDATION_BUILD",
"statusCode": 500
}
You could also try to put the example into each property.
You could also try to put the example into each property.
it was my first try but didn't work, still got compiling error. In response body works like a charm, but in request body I don't find a way of how to add example values. Already thinking to change to static mode
Just curious, are you using Swagger 2.0
or OpenAPI 3.0
.
AFAIK, if you are using Swagger 2.0
. There are NO example for body, only description.
I am closing this issue because I think it is a correct behavior.
If you are using OpenAPI 3.0
, then please provide a minimal reproducible code that we can run directly.
Prerequisites
Issue
No response