diff --git a/fixtures/allow_additional_props.json b/fixtures/allow_additional_props.json index 7b9edb0..7e89cf4 100644 --- a/fixtures/allow_additional_props.json +++ b/fixtures/allow_additional_props.json @@ -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": [ @@ -236,9 +222,7 @@ "Baz", "color", "roles", - "raw", - "min_len", - "min_val" + "raw" ] } } diff --git a/fixtures/array_handling.json b/fixtures/array_handling.json new file mode 100644 index 0000000..8b55d88 --- /dev/null +++ b/fixtures/array_handling.json @@ -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" + ] + } + } +} \ No newline at end of file diff --git a/fixtures/defaults_expanded_toplevel.json b/fixtures/defaults_expanded_toplevel.json index 4b1a121..09d592c 100644 --- a/fixtures/defaults_expanded_toplevel.json +++ b/fixtures/defaults_expanded_toplevel.json @@ -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", @@ -237,8 +223,6 @@ "Baz", "color", "roles", - "raw", - "min_len", - "min_val" + "raw" ] } \ No newline at end of file diff --git a/fixtures/ignore_type.json b/fixtures/ignore_type.json index d40d397..6e7f997 100644 --- a/fixtures/ignore_type.json +++ b/fixtures/ignore_type.json @@ -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", @@ -231,9 +217,7 @@ "Baz", "color", "roles", - "raw", - "min_len", - "min_val" + "raw" ] } } diff --git a/fixtures/no_reference.json b/fixtures/no_reference.json index e39ebaa..6efab45 100644 --- a/fixtures/no_reference.json +++ b/fixtures/no_reference.json @@ -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", @@ -226,8 +212,6 @@ "Baz", "color", "roles", - "raw", - "min_len", - "min_val" + "raw" ] } \ No newline at end of file diff --git a/fixtures/no_reference_anchor.json b/fixtures/no_reference_anchor.json index 9d926e3..d544d93 100644 --- a/fixtures/no_reference_anchor.json +++ b/fixtures/no_reference_anchor.json @@ -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", @@ -228,8 +214,6 @@ "Baz", "color", "roles", - "raw", - "min_len", - "min_val" + "raw" ] } \ No newline at end of file diff --git a/fixtures/required_from_jsontags.json b/fixtures/required_from_jsontags.json index 57e64b1..7173eaa 100644 --- a/fixtures/required_from_jsontags.json +++ b/fixtures/required_from_jsontags.json @@ -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", diff --git a/fixtures/test_user.json b/fixtures/test_user.json index 1fd1115..97d3b3b 100644 --- a/fixtures/test_user.json +++ b/fixtures/test_user.json @@ -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", @@ -238,9 +224,7 @@ "Baz", "color", "roles", - "raw", - "min_len", - "min_val" + "raw" ] } } diff --git a/fixtures/test_user_assign_anchor.json b/fixtures/test_user_assign_anchor.json index 1e57671..e5691bc 100644 --- a/fixtures/test_user_assign_anchor.json +++ b/fixtures/test_user_assign_anchor.json @@ -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", @@ -240,9 +226,7 @@ "Baz", "color", "roles", - "raw", - "min_len", - "min_val" + "raw" ] } } diff --git a/reflect.go b/reflect.go index e616cdc..a6f99ff 100644 --- a/reflect.go +++ b/reflect.go @@ -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) } diff --git a/reflect_test.go b/reflect_test.go index e937338..e97cdb9 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -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 @@ -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`) +}