Skip to content

Commit

Permalink
move to separate test
Browse files Browse the repository at this point in the history
  • Loading branch information
candiduslynx committed Sep 26, 2023
1 parent 5fe0827 commit 6f92551
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 146 deletions.
20 changes: 2 additions & 18 deletions fixtures/allow_additional_props.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,7 @@
"type": "array"
},
"anything": true,
"raw": true,
"min_len": {
"items": {
"type": "string",
"minLength": 2
},
"type": "array"
},
"min_val": {
"items": {
"type": "number",
"minimum": 2.5
},
"type": "array"
}
"raw": true
},
"type": "object",
"required": [
Expand All @@ -236,9 +222,7 @@
"Baz",
"color",
"roles",
"raw",
"min_len",
"min_val"
"raw"
]
}
}
Expand Down
31 changes: 31 additions & 0 deletions fixtures/array_handling.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/invopop/jsonschema/array-handler",
"$ref": "#/$defs/ArrayHandler",
"$defs": {
"ArrayHandler": {
"properties": {
"min_len": {
"items": {
"type": "string",
"minLength": 2
},
"type": "array"
},
"min_val": {
"items": {
"type": "number",
"minimum": 2.5
},
"type": "array"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"min_len",
"min_val"
]
}
}
}
20 changes: 2 additions & 18 deletions fixtures/defaults_expanded_toplevel.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,7 @@
"type": "array"
},
"anything": true,
"raw": true,
"min_len": {
"items": {
"type": "string",
"minLength": 2
},
"type": "array"
},
"min_val": {
"items": {
"type": "number",
"minimum": 2.5
},
"type": "array"
}
"raw": true
},
"additionalProperties": false,
"type": "object",
Expand All @@ -237,8 +223,6 @@
"Baz",
"color",
"roles",
"raw",
"min_len",
"min_val"
"raw"
]
}
20 changes: 2 additions & 18 deletions fixtures/ignore_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,7 @@
"type": "array"
},
"anything": true,
"raw": true,
"min_len": {
"items": {
"type": "string",
"minLength": 2
},
"type": "array"
},
"min_val": {
"items": {
"type": "number",
"minimum": 2.5
},
"type": "array"
}
"raw": true
},
"additionalProperties": false,
"type": "object",
Expand All @@ -231,9 +217,7 @@
"Baz",
"color",
"roles",
"raw",
"min_len",
"min_val"
"raw"
]
}
}
Expand Down
20 changes: 2 additions & 18 deletions fixtures/no_reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,7 @@
"type": "array"
},
"anything": true,
"raw": true,
"min_len": {
"items": {
"type": "string",
"minLength": 2
},
"type": "array"
},
"min_val": {
"items": {
"type": "number",
"minimum": 2.5
},
"type": "array"
}
"raw": true
},
"additionalProperties": false,
"type": "object",
Expand All @@ -226,8 +212,6 @@
"Baz",
"color",
"roles",
"raw",
"min_len",
"min_val"
"raw"
]
}
20 changes: 2 additions & 18 deletions fixtures/no_reference_anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,7 @@
"type": "array"
},
"anything": true,
"raw": true,
"min_len": {
"items": {
"type": "string",
"minLength": 2
},
"type": "array"
},
"min_val": {
"items": {
"type": "number",
"minimum": 2.5
},
"type": "array"
}
"raw": true
},
"additionalProperties": false,
"type": "object",
Expand All @@ -228,8 +214,6 @@
"Baz",
"color",
"roles",
"raw",
"min_len",
"min_val"
"raw"
]
}
16 changes: 1 addition & 15 deletions fixtures/required_from_jsontags.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,7 @@
"type": "array"
},
"anything": true,
"raw": true,
"min_len": {
"items": {
"type": "string",
"minLength": 2
},
"type": "array"
},
"min_val": {
"items": {
"type": "number",
"minimum": 2.5
},
"type": "array"
}
"raw": true
},
"additionalProperties": false,
"type": "object",
Expand Down
20 changes: 2 additions & 18 deletions fixtures/test_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,7 @@
"type": "array"
},
"anything": true,
"raw": true,
"min_len": {
"items": {
"type": "string",
"minLength": 2
},
"type": "array"
},
"min_val": {
"items": {
"type": "number",
"minimum": 2.5
},
"type": "array"
}
"raw": true
},
"additionalProperties": false,
"type": "object",
Expand All @@ -238,9 +224,7 @@
"Baz",
"color",
"roles",
"raw",
"min_len",
"min_val"
"raw"
]
}
}
Expand Down
20 changes: 2 additions & 18 deletions fixtures/test_user_assign_anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,7 @@
"type": "array"
},
"anything": true,
"raw": true,
"min_len": {
"items": {
"type": "string",
"minLength": 2
},
"type": "array"
},
"min_val": {
"items": {
"type": "number",
"minimum": 2.5
},
"type": "array"
}
"raw": true
},
"additionalProperties": false,
"type": "object",
Expand All @@ -240,9 +226,7 @@
"Baz",
"color",
"roles",
"raw",
"min_len",
"min_val"
"raw"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ func (t *Schema) arrayKeywords(tags []string) {
case "integer":
t.Items.numericalKeywords(tags)
case "array":
t.Items.arrayKeywords(tags)
// explicitly don't support traversal for the [][]..., as it's unclear where the array tags belong
case "boolean":
t.Items.booleanKeywords(tags)
}
Expand Down
16 changes: 12 additions & 4 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ type TestUser struct {
// Test for raw JSON
Anything any `json:"anything,omitempty"`
Raw json.RawMessage `json:"raw"`

// Test for minLength working for string slice
MinLen []string `json:"min_len" jsonschema:"minLength=2"`
MinVal []float64 `json:"min_val" jsonschema:"minimum=2.5"`
}

type CustomTime time.Time
Expand Down Expand Up @@ -592,3 +588,15 @@ func TestNumberHandling(t *testing.T) {
fixtureContains(t, "fixtures/number_handling.json", `"default": 12`)
fixtureContains(t, "fixtures/number_handling.json", `"default": 12.5`)
}

func TestArrayHandling(t *testing.T) {
type ArrayHandler struct {
MinLen []string `json:"min_len" jsonschema:"minLength=2"`
MinVal []float64 `json:"min_val" jsonschema:"minimum=2.5"`
}

r := &Reflector{}
compareSchemaOutput(t, "fixtures/array_handling.json", r, &ArrayHandler{})
fixtureContains(t, "fixtures/array_handling.json", `"minLength": 2`)
fixtureContains(t, "fixtures/array_handling.json", `"minimum": 2.5`)
}

0 comments on commit 6f92551

Please sign in to comment.