Open chuliang opened 1 year ago
@chuliang
Hello,
Regarding the feature itself, I'm not against it, but the implementation itself isn't what I would recommend. Instead of having to rely on unexported struct fields, we could instead provide a package function to register a description for each type (in a global map protected with a mutex). This could then in turn be used by the generator to generate the "components/schemas" part of the spec.
See newSchemaFromType
.
So, in terms of usage, this would give something like this:
type RouteInput struct {
FieldA string `json:"field_a" description:"field_a description"`
}
func init() {
fizz.RegisterSchemaDescription(RouteInput{}, "Description of the input schema")
}
wdyt ?
Hello @wI2L :) Thanks for your review.
I think fizz.RegisterSchemaDescription(...)
remove the benefit of Tonic to register input schema from the route function parameter.
I updated my PR with another way to provide a description for the RequestBody schema.
Is it better for you?
Allow to set a description to a schema used as request body
Example: Input struct:
Generated schema: