-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
bugmodelRelated to swagger generate model commandRelated to swagger generate model commandpending PRvalidatorRelated to codegen generation of validationsRelated to codegen generation of validations
Description
Problem statement
When using the maxProperties
property in a schema, then generated validation logic incorrectly checks the length of the base object as opposed to the length of the property that's being validated.
func (m *SomeThing) validateData(formats strfmt.Registry) error {
if swag.IsZero(m.Data) { // not required
return nil
}
nprops := len(m) // <-- ERROR: len(m) should be len(m.Data)
// maxProperties: 20
if nprops > 20 {
return errors.TooManyProperties("data", "body", 20)
}
return nil
}
Swagger specification
"SomeThing": {
"properties": {
"data": {
"additionalProperties": {
"type": "object"
},
"maxProperties": 20,
"type": "object",
"x-nullable": true
}
},
"type": "object"
},
Steps to reproduce
- Create a schema with a component schema that has the above content
- Generate models
swagger generate models -f ./spec.json -t ./out
- Generated code is non-compilable.
Environment
swagger version: v0.26.1
go version: go1.16.4 darwin/amd64
OS: MacOS
yaucp
Metadata
Metadata
Assignees
Labels
bugmodelRelated to swagger generate model commandRelated to swagger generate model commandpending PRvalidatorRelated to codegen generation of validationsRelated to codegen generation of validations