Skip to content

Commit

Permalink
[PIPE-1397] Fix exclusiveMin/exclusiveMax for jsonschema draft-7 (#29)
Browse files Browse the repository at this point in the history
* changing the type for exclusive min/max as per draft 7

* testcases update
  • Loading branch information
rajaanova authored and WC committed Sep 10, 2019
1 parent b85ba38 commit 6e2eb55
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 26 deletions.
6 changes: 2 additions & 4 deletions fixtures/allow_additional_props.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
"type": "boolean"
},
"age": {
"exclusiveMaximum": true,
"exclusiveMinimum": true,
"maximum": 120,
"minimum": 18,
"exclusiveMaximum": 120,
"exclusiveMinimum": 18,
"type": "integer"
},
"birth_date": {
Expand Down
6 changes: 2 additions & 4 deletions fixtures/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
"type": "boolean"
},
"age": {
"exclusiveMaximum": true,
"exclusiveMinimum": true,
"maximum": 120,
"minimum": 18,
"exclusiveMaximum": 120,
"exclusiveMinimum": 18,
"type": "integer"
},
"birth_date": {
Expand Down
12 changes: 4 additions & 8 deletions fixtures/defaults_expanded_toplevel.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
"type": "boolean"
},
"age": {
"exclusiveMaximum": true,
"exclusiveMinimum": true,
"maximum": 120,
"minimum": 18,
"exclusiveMaximum": 120,
"exclusiveMinimum": 18,
"type": "integer"
},
"birth_date": {
Expand Down Expand Up @@ -120,10 +118,8 @@
"type": "boolean"
},
"age": {
"exclusiveMaximum": true,
"exclusiveMinimum": true,
"maximum": 120,
"minimum": 18,
"exclusiveMaximum": 120,
"exclusiveMinimum": 18,
"type": "integer"
},
"birth_date": {
Expand Down
6 changes: 2 additions & 4 deletions fixtures/required_from_jsontags.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
"type": "boolean"
},
"age": {
"exclusiveMaximum": true,
"exclusiveMinimum": true,
"maximum": 120,
"minimum": 18,
"exclusiveMaximum": 120,
"exclusiveMinimum": 18,
"type": "integer"
},
"birth_date": {
Expand Down
2 changes: 1 addition & 1 deletion internal/testmodels/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type TestUser struct {

// Tests for jsonpb enum support
Feeling ProtoEnum `json:"feeling,omitempty"`
Age int `json:"age" jsonschema:"minimum=18,maximum=120,exclusiveMaximum=true,exclusiveMinimum=true"`
Age int `json:"age" jsonschema:"exclusiveMaximum=120,exclusiveMinimum=18"`
Email string `json:"email" jsonschema:"format=email"`

SecretNumber int `json:"secret_number,omitempty" jsonschema:"enum=9|30|28|52"`
Expand Down
10 changes: 5 additions & 5 deletions reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ type Type struct {
// RFC draft-wright-json-schema-validation-00, section 5
MultipleOf int `json:"multipleOf,omitempty"` // section 5.1
Maximum int `json:"maximum,omitempty"` // section 5.2
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"` // section 5.3
ExclusiveMaximum int `json:"exclusiveMaximum,omitempty"` // section 5.3
Minimum int `json:"minimum,omitempty"` // section 5.4
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"` // section 5.5
ExclusiveMinimum int `json:"exclusiveMinimum,omitempty"` // section 5.5
MaxLength int `json:"maxLength,omitempty"` // section 5.6
MinLength int `json:"minLength,omitempty"` // section 5.7
Pattern string `json:"pattern,omitempty"` // section 5.8
Expand Down Expand Up @@ -317,8 +317,8 @@ func (r *Reflector) reflectStruct(definitions Definitions, t reflect.Type) *Type
definitions[definitionsKey] = st
r.reflectStructFields(st, definitions, t)
r.addSubschemasForConditionalCases(st, definitions, t)

return &Type{Ref: "#/definitions/" + definitionsKey}

}

func (r *Reflector) reflectStructFields(st *Type, definitions Definitions, t reflect.Type) {
Expand Down Expand Up @@ -453,10 +453,10 @@ func (t *Type) numbericKeywords(tags []string) {
i, _ := strconv.Atoi(val)
t.Maximum = i
case "exclusiveMaximum":
b, _ := strconv.ParseBool(val)
b, _ := strconv.Atoi(val)
t.ExclusiveMaximum = b
case "exclusiveMinimum":
b, _ := strconv.ParseBool(val)
b, _ := strconv.Atoi(val)
t.ExclusiveMinimum = b
case "enum":
enum := strings.Split(val, "|")
Expand Down

0 comments on commit 6e2eb55

Please sign in to comment.