add exampleOption support
This commit is contained in:
parent
5d03152780
commit
1f5a0bfcc6
@ -162,6 +162,7 @@ type swaggerParameterObject struct {
|
|||||||
CollectionFormat string `json:"collectionFormat,omitempty"`
|
CollectionFormat string `json:"collectionFormat,omitempty"`
|
||||||
Default string `json:"default,omitempty"`
|
Default string `json:"default,omitempty"`
|
||||||
MinItems *int `json:"minItems,omitempty"`
|
MinItems *int `json:"minItems,omitempty"`
|
||||||
|
Example string `json:"example,omitempty"`
|
||||||
|
|
||||||
// Or you can explicitly refer to another type. If this is defined all
|
// Or you can explicitly refer to another type. If this is defined all
|
||||||
// other fields should be empty
|
// other fields should be empty
|
||||||
@ -171,10 +172,10 @@ type swaggerParameterObject struct {
|
|||||||
// core part of schema, which is common to itemsObject and schemaObject.
|
// core part of schema, which is common to itemsObject and schemaObject.
|
||||||
// http://swagger.io/specification/#itemsObject
|
// http://swagger.io/specification/#itemsObject
|
||||||
type schemaCore struct {
|
type schemaCore struct {
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Format string `json:"format,omitempty"`
|
Format string `json:"format,omitempty"`
|
||||||
Ref string `json:"$ref,omitempty"`
|
Ref string `json:"$ref,omitempty"`
|
||||||
Example json.RawMessage `json:"example,omitempty"`
|
Example string `json:"example,omitempty"`
|
||||||
|
|
||||||
Items *swaggerItemsObject `json:"items,omitempty"`
|
Items *swaggerItemsObject `json:"items,omitempty"`
|
||||||
// If the item is an enumeration include a list of all the *NAMES* of the
|
// If the item is an enumeration include a list of all the *NAMES* of the
|
||||||
|
@ -23,6 +23,7 @@ const (
|
|||||||
omitemptyOption = "omitempty"
|
omitemptyOption = "omitempty"
|
||||||
optionsOption = "options"
|
optionsOption = "options"
|
||||||
rangeOption = "range"
|
rangeOption = "range"
|
||||||
|
exampleOption = "example"
|
||||||
optionSeparator = "|"
|
optionSeparator = "|"
|
||||||
equalToken = "="
|
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) {
|
} else if strings.HasPrefix(option, optionalOption) || strings.HasPrefix(option, omitemptyOption) {
|
||||||
required = false
|
required = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(option, exampleOption) {
|
||||||
|
segs := strings.Split(option, equalToken)
|
||||||
|
if len(segs) == 2 {
|
||||||
|
sp.Example = segs[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sp.Required = required
|
sp.Required = required
|
||||||
}
|
}
|
||||||
@ -358,6 +366,13 @@ func renderStruct(member spec.Member) swaggerParameterObject {
|
|||||||
} else if strings.HasPrefix(option, optionalOption) || strings.HasPrefix(option, omitemptyOption) {
|
} else if strings.HasPrefix(option, optionalOption) || strings.HasPrefix(option, omitemptyOption) {
|
||||||
required = false
|
required = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(option, exampleOption) {
|
||||||
|
segs := strings.Split(option, equalToken)
|
||||||
|
if len(segs) == 2 {
|
||||||
|
sp.Example = segs[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sp.Required = required
|
sp.Required = required
|
||||||
}
|
}
|
||||||
@ -572,6 +587,11 @@ func schemaOfField(member spec.Member) swaggerSchemaObject {
|
|||||||
ret.Maximum = max
|
ret.Maximum = max
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case strings.HasPrefix(option, exampleOption):
|
||||||
|
segs := strings.Split(option, equalToken)
|
||||||
|
if len(segs) == 2 {
|
||||||
|
ret.Example = segs[1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user