add exampleOption support

This commit is contained in:
colakuma 2022-09-20 18:09:21 +08:00
parent 5d03152780
commit 1f5a0bfcc6
2 changed files with 25 additions and 4 deletions

View File

@ -162,6 +162,7 @@ type swaggerParameterObject struct {
CollectionFormat string `json:"collectionFormat,omitempty"`
Default string `json:"default,omitempty"`
MinItems *int `json:"minItems,omitempty"`
Example string `json:"example,omitempty"`
// Or you can explicitly refer to another type. If this is defined all
// other fields should be empty
@ -171,10 +172,10 @@ type swaggerParameterObject struct {
// core part of schema, which is common to itemsObject and schemaObject.
// http://swagger.io/specification/#itemsObject
type schemaCore struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Ref string `json:"$ref,omitempty"`
Example json.RawMessage `json:"example,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Ref string `json:"$ref,omitempty"`
Example string `json:"example,omitempty"`
Items *swaggerItemsObject `json:"items,omitempty"`
// If the item is an enumeration include a list of all the *NAMES* of the

View File

@ -23,6 +23,7 @@ const (
omitemptyOption = "omitempty"
optionsOption = "options"
rangeOption = "range"
exampleOption = "example"
optionSeparator = "|"
equalToken = "="
)
@ -189,6 +190,13 @@ func renderServiceRoutes(service spec.Service, groups []spec.Group, paths swagge
} else if strings.HasPrefix(option, optionalOption) || strings.HasPrefix(option, omitemptyOption) {
required = false
}
if strings.HasPrefix(option, exampleOption) {
segs := strings.Split(option, equalToken)
if len(segs) == 2 {
sp.Example = segs[1]
}
}
}
sp.Required = required
}
@ -358,6 +366,13 @@ func renderStruct(member spec.Member) swaggerParameterObject {
} else if strings.HasPrefix(option, optionalOption) || strings.HasPrefix(option, omitemptyOption) {
required = false
}
if strings.HasPrefix(option, exampleOption) {
segs := strings.Split(option, equalToken)
if len(segs) == 2 {
sp.Example = segs[1]
}
}
}
sp.Required = required
}
@ -572,6 +587,11 @@ func schemaOfField(member spec.Member) swaggerSchemaObject {
ret.Maximum = max
}
}
case strings.HasPrefix(option, exampleOption):
segs := strings.Split(option, equalToken)
if len(segs) == 2 {
ret.Example = segs[1]
}
}
}
}