Prerequisites
🚀 Feature Proposal
Support distinct examples name for request body, params, etc..
Motivation
The openapi v3 spec supports adding a distinct name and summary for each example as shown here
https://swagger.io/docs/specification/adding-examples/
parameters:
- in: query
name: limit
schema:
type: integer
maximum: 50
examples: # Multiple examples
zero: # Distinct name
value: 0 # Example value
summary: A sample limit value # Optional description
max: # Distinct name
value: 50 # Example value
summary: A sample limit value # Optional description
unfortunately, it seems like an object format which is not allowed in the current implementation due to the dependency on fast-json-stringify and it's schema validator
https://github.com/fastify/fast-json-stringify/blob/4f6f7b809fc7148a40e8f07cc81a658757e81b68/lib/schema-validator.js#L203C1-L206C2
There's probably a good reason for that. but I'm wondering if there's a way around it?
I'm happy to contribute once I have a decent understanding on what can be done
Example
The current convertor implementation in this library forces examples to be named as example 1, example 2, ...
|
function convertExamplesArrayToObject (examples) { |
|
return examples.reduce((examplesObject, example, index) => { |
|
if (typeof example === 'object') { |
|
examplesObject['example' + (index + 1)] = { value: example } |
|
} else { |
|
examplesObject[example] = { value: example } |
|
} |
|
|
|
return examplesObject |
|
}, {}) |
|
} |
Prerequisites
🚀 Feature Proposal
Support distinct examples name for request body, params, etc..
Motivation
The openapi v3 spec supports adding a distinct name and summary for each example as shown here
https://swagger.io/docs/specification/adding-examples/
unfortunately, it seems like an object format which is not allowed in the current implementation due to the dependency on
fast-json-stringifyand it's schema validatorhttps://github.com/fastify/fast-json-stringify/blob/4f6f7b809fc7148a40e8f07cc81a658757e81b68/lib/schema-validator.js#L203C1-L206C2
There's probably a good reason for that. but I'm wondering if there's a way around it?
I'm happy to contribute once I have a decent understanding on what can be done
Example
The current convertor implementation in this library forces examples to be named as
example 1,example 2, ...fastify-swagger/lib/spec/openapi/utils.js
Lines 148 to 158 in 5277980