Prerequisites
Fastify version
4
Plugin version
7.3
Node.js version
16
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
20
Description
schema object in Open API spec follows the JSON Schema standard as mentioned here.
example field is deprecated as mentioned here.
examples field is an array as mentioned here in the JSON schema spec.
But, fastify-swagger generates the examples field as an object using this method convertExamplesArrayToObject, which breaks some implementations of Open API spec viewers.
Also, note, not every examples field is supposed to be an array, only when JSON schema is expected. For example, the examples of the response object are indeed an object, as mentioned here.
Steps to Reproduce
Generate open api spec when you have validation schema like,
import { Type as t } from '@sinclair/typebox'
t.String({
examples: [ 'haha', 'haha2' ]
})
generates schema like,
schema:
type: string
examples:
haha:
value: haha
haha2:
value: haha2
Expected Behavior
schema:
type: string
examples:
- haha
- haha2
I think the solution would need to conditionally generate an example array in JSON Schema and an example object in other places.
Prerequisites
Fastify version
4
Plugin version
7.3
Node.js version
16
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
20
Description
schemaobject in Open API spec follows the JSON Schema standard as mentioned here.examplefield is deprecated as mentioned here.examplesfield is an array as mentioned here in the JSON schema spec.But, fastify-swagger generates the examples field as an object using this method
convertExamplesArrayToObject, which breaks some implementations of Open API spec viewers.Also, note, not every examples field is supposed to be an array, only when JSON schema is expected. For example, the examples of the response object are indeed an object, as mentioned here.
Steps to Reproduce
Generate open api spec when you have validation schema like,
generates schema like,
Expected Behavior
I think the solution would need to conditionally generate an example array in JSON Schema and an example object in other places.