Closed ghost closed 3 years ago
It isn't possible at the moment.
The Parameter
is missing the example
and examples
fields required type.
https://github.com/wI2L/fizz/blob/bbaa01a9f70702e7c16baa507eefe416faaf67cb/openapi/spec.go#L94
The Schema
type is also missing the example
field. https://github.com/wI2L/fizz/blob/bbaa01a9f70702e7c16baa507eefe416faaf67cb/openapi/spec.go#L145
Once those fields are added, we could add a new OperationOption
to add an example for a parameter, like fizz.Example(value interface{}, summary string)
.
Would it work for you ?
Note that the OpenAPI 3 spec defines the examples
and example
fields. The former let you defines an example mapped to a specific media type, while the latter doesn't. It is also possible to add an example within a Schema
, but schemas are generated based on the Go types the API is using, and I can't think of a simple way to allow a user to define it without using a global function to register an example per type.
That is true, but we can generate example by set tag example
on struct fields instead add fizz.Example(value interface{}, summary string)
. It's would be more simple, IMO.
Yes, you are right. But this would be scoped to the example
field only, which I guess is good enough. There's always the possibility to edit the generated spec for advanced use cases.
Feel free to send a PR, otherwise I'll look at it when I have some time.
How define example values for parameters?