bf51655a7b
Signed-off-by: Jacek J. Łakis <jacek.lakis@intel.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
42 lines
867 B
Go
42 lines
867 B
Go
package swagger
|
|
|
|
import "testing"
|
|
|
|
type Boat struct {
|
|
Length int `json:"-"` // on default, this makes the fields not required
|
|
Weight int `json:"-"`
|
|
}
|
|
|
|
// PostBuildModel is from swagger.ModelBuildable
|
|
func (b Boat) PostBuildModel(m *Model) *Model {
|
|
// override required
|
|
m.Required = []string{"Length", "Weight"}
|
|
|
|
// add model property (just to test is can be added; is this a real usecase?)
|
|
extraType := "string"
|
|
m.Properties.Put("extra", ModelProperty{
|
|
Description: "extra description",
|
|
DataTypeFields: DataTypeFields{
|
|
Type: &extraType,
|
|
},
|
|
})
|
|
return m
|
|
}
|
|
|
|
func TestCustomPostModelBuilde(t *testing.T) {
|
|
testJsonFromStruct(t, Boat{}, `{
|
|
"swagger.Boat": {
|
|
"id": "swagger.Boat",
|
|
"required": [
|
|
"Length",
|
|
"Weight"
|
|
],
|
|
"properties": {
|
|
"extra": {
|
|
"type": "string",
|
|
"description": "extra description"
|
|
}
|
|
}
|
|
}
|
|
}`)
|
|
}
|