From 4038a3607709bdc3879c1e77cdf979a3e7f2683b Mon Sep 17 00:00:00 2001 From: conneroisu Date: Sat, 26 Oct 2024 09:49:56 -0400 Subject: [PATCH] added schema testdata back --- pkg/schema/schema_test.go | 2 +- pkg/schema/testdata/.gitignore | 1 + .../testdata/allow_additional_props.json | 229 +++++++++++++++++ pkg/schema/testdata/anyof.json | 91 +++++++ pkg/schema/testdata/array_handling.json | 34 +++ pkg/schema/testdata/array_type.json | 13 + pkg/schema/testdata/base_schema_id.json | 38 +++ pkg/schema/testdata/commas_in_pattern.json | 22 ++ pkg/schema/testdata/compact_date.json | 13 + pkg/schema/testdata/custom_additional.json | 24 ++ .../testdata/custom_base_schema_id.json | 207 ++++++++++++++++ pkg/schema/testdata/custom_map_type.json | 37 +++ pkg/schema/testdata/custom_slice_type.json | 32 +++ pkg/schema/testdata/custom_type.json | 20 ++ pkg/schema/testdata/custom_type_extend.json | 23 ++ .../testdata/custom_type_with_interface.json | 23 ++ .../testdata/defaults_expanded_toplevel.json | 228 +++++++++++++++++ pkg/schema/testdata/equals_in_pattern.json | 25 ++ pkg/schema/testdata/go_comments.json | 113 +++++++++ pkg/schema/testdata/ignore_type.json | 224 +++++++++++++++++ pkg/schema/testdata/inlining_embedded.json | 31 +++ .../testdata/inlining_embedded_anchored.json | 33 +++ pkg/schema/testdata/inlining_inheritance.json | 21 ++ pkg/schema/testdata/inlining_ptr.json | 17 ++ pkg/schema/testdata/inlining_tag.json | 17 ++ pkg/schema/testdata/keynamed.json | 52 ++++ pkg/schema/testdata/lookup.json | 22 ++ pkg/schema/testdata/lookup_expanded.json | 18 ++ pkg/schema/testdata/map_type.json | 10 + pkg/schema/testdata/no_reference.json | 217 ++++++++++++++++ pkg/schema/testdata/no_reference_anchor.json | 219 ++++++++++++++++ pkg/schema/testdata/nullable.json | 26 ++ pkg/schema/testdata/number_handling.json | 25 ++ pkg/schema/testdata/oneof.json | 104 ++++++++ pkg/schema/testdata/oneof_ref.json | 59 +++++ pkg/schema/testdata/recursive.json | 25 ++ .../testdata/required_from_jsontags.json | 218 ++++++++++++++++ pkg/schema/testdata/run.py | 13 + pkg/schema/testdata/schema_alias.json | 19 ++ pkg/schema/testdata/schema_alias_2.json | 31 +++ .../testdata/schema_property_alias.json | 31 +++ .../testdata/schema_with_expression.json | 20 ++ pkg/schema/testdata/schema_with_minimum.json | 20 ++ pkg/schema/testdata/test_config.json | 23 ++ .../testdata/test_description_override.json | 34 +++ pkg/schema/testdata/test_user.json | 231 +++++++++++++++++ .../testdata/test_user_assign_anchor.json | 233 ++++++++++++++++++ .../test_yaml_and_json_prefer_yaml.json | 30 +++ .../testdata/unsigned_int_handling.json | 47 ++++ pkg/schema/testdata/user_with_anchor.json | 20 ++ pkg/schema/testdata/with_custom_format.json | 31 +++ pkg/schema/testdata/yaml_inline.json | 29 +++ 52 files changed, 3324 insertions(+), 1 deletion(-) create mode 100644 pkg/schema/testdata/.gitignore create mode 100644 pkg/schema/testdata/allow_additional_props.json create mode 100644 pkg/schema/testdata/anyof.json create mode 100644 pkg/schema/testdata/array_handling.json create mode 100644 pkg/schema/testdata/array_type.json create mode 100644 pkg/schema/testdata/base_schema_id.json create mode 100644 pkg/schema/testdata/commas_in_pattern.json create mode 100644 pkg/schema/testdata/compact_date.json create mode 100644 pkg/schema/testdata/custom_additional.json create mode 100644 pkg/schema/testdata/custom_base_schema_id.json create mode 100644 pkg/schema/testdata/custom_map_type.json create mode 100644 pkg/schema/testdata/custom_slice_type.json create mode 100644 pkg/schema/testdata/custom_type.json create mode 100644 pkg/schema/testdata/custom_type_extend.json create mode 100644 pkg/schema/testdata/custom_type_with_interface.json create mode 100644 pkg/schema/testdata/defaults_expanded_toplevel.json create mode 100644 pkg/schema/testdata/equals_in_pattern.json create mode 100644 pkg/schema/testdata/go_comments.json create mode 100644 pkg/schema/testdata/ignore_type.json create mode 100644 pkg/schema/testdata/inlining_embedded.json create mode 100644 pkg/schema/testdata/inlining_embedded_anchored.json create mode 100644 pkg/schema/testdata/inlining_inheritance.json create mode 100644 pkg/schema/testdata/inlining_ptr.json create mode 100644 pkg/schema/testdata/inlining_tag.json create mode 100644 pkg/schema/testdata/keynamed.json create mode 100644 pkg/schema/testdata/lookup.json create mode 100644 pkg/schema/testdata/lookup_expanded.json create mode 100644 pkg/schema/testdata/map_type.json create mode 100644 pkg/schema/testdata/no_reference.json create mode 100644 pkg/schema/testdata/no_reference_anchor.json create mode 100644 pkg/schema/testdata/nullable.json create mode 100644 pkg/schema/testdata/number_handling.json create mode 100644 pkg/schema/testdata/oneof.json create mode 100644 pkg/schema/testdata/oneof_ref.json create mode 100644 pkg/schema/testdata/recursive.json create mode 100644 pkg/schema/testdata/required_from_jsontags.json create mode 100644 pkg/schema/testdata/run.py create mode 100644 pkg/schema/testdata/schema_alias.json create mode 100644 pkg/schema/testdata/schema_alias_2.json create mode 100644 pkg/schema/testdata/schema_property_alias.json create mode 100644 pkg/schema/testdata/schema_with_expression.json create mode 100644 pkg/schema/testdata/schema_with_minimum.json create mode 100644 pkg/schema/testdata/test_config.json create mode 100644 pkg/schema/testdata/test_description_override.json create mode 100644 pkg/schema/testdata/test_user.json create mode 100644 pkg/schema/testdata/test_user_assign_anchor.json create mode 100644 pkg/schema/testdata/test_yaml_and_json_prefer_yaml.json create mode 100644 pkg/schema/testdata/unsigned_int_handling.json create mode 100644 pkg/schema/testdata/user_with_anchor.json create mode 100644 pkg/schema/testdata/with_custom_format.json create mode 100644 pkg/schema/testdata/yaml_inline.json diff --git a/pkg/schema/schema_test.go b/pkg/schema/schema_test.go index 2a4c9bc..8d9b02a 100644 --- a/pkg/schema/schema_test.go +++ b/pkg/schema/schema_test.go @@ -451,7 +451,7 @@ func TestReflectFromType(t *testing.T) { s := r.ReflectFromType(typ) assert.EqualValues( t, - "https://github.com/conneroisu/groq-go/test-user", + "https://github.com/conneroisu/groq-go/pkg/schema/test-user", s.ID, ) diff --git a/pkg/schema/testdata/.gitignore b/pkg/schema/testdata/.gitignore new file mode 100644 index 0000000..5d3b7b7 --- /dev/null +++ b/pkg/schema/testdata/.gitignore @@ -0,0 +1 @@ +*.out.json \ No newline at end of file diff --git a/pkg/schema/testdata/allow_additional_props.json b/pkg/schema/testdata/allow_additional_props.json new file mode 100644 index 0000000..72be605 --- /dev/null +++ b/pkg/schema/testdata/allow_additional_props.json @@ -0,0 +1,229 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-user", + "$ref": "#/$defs/TestUser", + "$defs": { + "Bytes": { + "type": "string", + "contentEncoding": "base64" + }, + "GrandfatherType": { + "properties": { + "family_name": { + "type": "string" + } + }, + "type": "object", + "required": [ + "family_name" + ] + }, + "MapType": { + "type": "object" + }, + "TestUser": { + "properties": { + "id": { + "type": "integer" + }, + "some_base_property": { + "type": "integer" + }, + "grand": { + "$ref": "#/$defs/GrandfatherType" + }, + "SomeUntaggedBaseProperty": { + "type": "boolean" + }, + "PublicNonExported": { + "type": "integer" + }, + "MapType": { + "$ref": "#/$defs/MapType" + }, + "name": { + "type": "string", + "maxLength": 20, + "minLength": 1, + "pattern": ".*", + "title": "the name", + "description": "this is a property", + "default": "alex", + "readOnly": true, + "examples": [ + "joe", + "lucy" + ] + }, + "password": { + "type": "string", + "writeOnly": true + }, + "friends": { + "items": { + "type": "integer" + }, + "type": "array", + "description": "list of IDs, omitted when empty" + }, + "tags": { + "additionalProperties": { + "type": "string" + }, + "type": "object" + }, + "options": { + "type": "object" + }, + "TestFlag": { + "type": "boolean" + }, + "TestFlagFalse": { + "type": "boolean", + "default": false + }, + "TestFlagTrue": { + "type": "boolean", + "default": true + }, + "birth_date": { + "type": "string", + "format": "date-time" + }, + "website": { + "type": "string", + "format": "uri" + }, + "network_address": { + "type": "string", + "format": "ipv4" + }, + "photo": { + "type": "string", + "contentEncoding": "base64" + }, + "photo2": { + "$ref": "#/$defs/Bytes" + }, + "feeling": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "age": { + "type": "integer", + "maximum": 120, + "exclusiveMaximum": 121, + "minimum": 18, + "exclusiveMinimum": 17 + }, + "email": { + "type": "string", + "format": "email" + }, + "uuid": { + "type": "string", + "format": "uuid" + }, + "Baz": { + "type": "string", + "foo": [ + "bar", + "bar1" + ], + "hello": "world" + }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, + "color": { + "type": "string", + "enum": [ + "red", + "green", + "blue" + ] + }, + "rank": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ] + }, + "mult": { + "type": "number", + "enum": [ + 1.0, + 1.5, + 2.0 + ] + }, + "roles": { + "items": { + "type": "string", + "enum": [ + "admin", + "moderator", + "user" + ] + }, + "type": "array" + }, + "priorities": { + "items": { + "type": "integer", + "enum": [ + -1, + 0, + 1 + ] + }, + "type": "array" + }, + "offsets": { + "items": { + "type": "number", + "enum": [ + 1.570796, + 3.141592, + 6.283185 + ] + }, + "type": "array" + }, + "anything": true, + "raw": true + }, + "type": "object", + "required": [ + "id", + "some_base_property", + "grand", + "SomeUntaggedBaseProperty", + "PublicNonExported", + "MapType", + "name", + "password", + "TestFlag", + "photo", + "photo2", + "age", + "email", + "uuid", + "Baz", + "color", + "roles", + "raw" + ] + } + } +} diff --git a/pkg/schema/testdata/anyof.json b/pkg/schema/testdata/anyof.json new file mode 100644 index 0000000..c4033cb --- /dev/null +++ b/pkg/schema/testdata/anyof.json @@ -0,0 +1,91 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/root-any-of", + "$ref": "#/$defs/RootAnyOf", + "$defs": { + "ChildAnyOf": { + "anyOf": [ + { + "required": [ + "child1", + "child4" + ], + "title": "group1" + }, + { + "required": [ + "child2", + "child3" + ], + "title": "group2" + } + ], + "properties": { + "child1": { + "type": "string" + }, + "child2": { + "type": "string" + }, + "child3": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array" + } + ] + }, + "child4": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "RootAnyOf": { + "anyOf": [ + { + "required": [ + "field1", + "field4" + ], + "title": "group1" + }, + { + "required": [ + "field2" + ], + "title": "group2" + } + ], + "properties": { + "field1": { + "type": "string" + }, + "field2": { + "type": "string" + }, + "field3": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "array" + } + ] + }, + "field4": { + "type": "string" + }, + "child": { + "$ref": "#/$defs/ChildAnyOf" + } + }, + "additionalProperties": false, + "type": "object" + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/array_handling.json b/pkg/schema/testdata/array_handling.json new file mode 100644 index 0000000..5a2fea1 --- /dev/null +++ b/pkg/schema/testdata/array_handling.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/array-handler", + "$ref": "#/$defs/ArrayHandler", + "$defs": { + "ArrayHandler": { + "properties": { + "min_len": { + "items": { + "type": "string", + "minLength": 2 + }, + "type": "array", + "default": [ + "qwerty" + ] + }, + "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/pkg/schema/testdata/array_type.json b/pkg/schema/testdata/array_type.json new file mode 100644 index 0000000..7adf8ab --- /dev/null +++ b/pkg/schema/testdata/array_type.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/array-type", + "$ref": "#/$defs/ArrayType", + "$defs": { + "ArrayType": { + "items": { + "type": "string" + }, + "type": "array" + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/base_schema_id.json b/pkg/schema/testdata/base_schema_id.json new file mode 100644 index 0000000..7c52f31 --- /dev/null +++ b/pkg/schema/testdata/base_schema_id.json @@ -0,0 +1,38 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/schemas/lookup-user", + "$ref": "#/$defs/LookupUser", + "$defs": { + "LookupName": { + "properties": { + "first": { + "type": "string" + }, + "surname": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "first", + "surname" + ] + }, + "LookupUser": { + "properties": { + "name": { + "$ref": "#/$defs/LookupName" + }, + "alias": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/commas_in_pattern.json b/pkg/schema/testdata/commas_in_pattern.json new file mode 100644 index 0000000..c83b686 --- /dev/null +++ b/pkg/schema/testdata/commas_in_pattern.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/pattern-test", + "$ref": "#/$defs/PatternTest", + "$defs": { + "PatternTest": { + "properties": { + "with_pattern": { + "type": "string", + "maxLength": 50, + "minLength": 1, + "pattern": "[0-9]{1,4}" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "with_pattern" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/compact_date.json b/pkg/schema/testdata/compact_date.json new file mode 100644 index 0000000..780a080 --- /dev/null +++ b/pkg/schema/testdata/compact_date.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/compact-date", + "$ref": "#/$defs/CompactDate", + "$defs": { + "CompactDate": { + "type": "string", + "pattern": "^[0-9]{4}-[0-1][0-9]$", + "title": "Compact Date", + "description": "Short date that only includes year and month" + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/custom_additional.json b/pkg/schema/testdata/custom_additional.json new file mode 100644 index 0000000..b76230d --- /dev/null +++ b/pkg/schema/testdata/custom_additional.json @@ -0,0 +1,24 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/grandfather-type", + "$ref": "#/$defs/GrandfatherType", + "$defs": { + "GrandfatherType": { + "properties": { + "family_name": { + "type": "string" + }, + "ip_addr": { + "type": "string", + "format": "ipv4" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "family_name", + "ip_addr" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/custom_base_schema_id.json b/pkg/schema/testdata/custom_base_schema_id.json new file mode 100644 index 0000000..479abc6 --- /dev/null +++ b/pkg/schema/testdata/custom_base_schema_id.json @@ -0,0 +1,207 @@ +{ + "$schema": "http://json-schema.org/draft/2020-12/schema", + "$id": "http://example.com/schema/TestUser", + "$ref": "#/$defs/TestUser", + "$defs": { + "GrandfatherType": { + "properties": { + "family_name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "family_name" + ] + }, + "TestUser": { + "properties": { + "some_base_property": { + "type": "integer" + }, + "some_base_property_yaml": { + "type": "integer" + }, + "grand": { + "$ref": "#/$defs/GrandfatherType" + }, + "SomeUntaggedBaseProperty": { + "type": "boolean" + }, + "PublicNonExported": { + "type": "integer" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string", + "maxLength": 20, + "minLength": 1, + "pattern": ".*", + "title": "the name", + "description": "this is a property", + "default": "alex", + "readOnly": true, + "examples": [ + "joe", + "lucy" + ] + }, + "password": { + "type": "string", + "writeOnly": true + }, + "friends": { + "items": { + "type": "integer" + }, + "type": "array", + "description": "list of IDs, omitted when empty" + }, + "tags": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, + "options": { + "type": "object" + }, + "TestFlag": { + "type": "boolean" + }, + "birth_date": { + "type": "string", + "format": "date-time" + }, + "website": { + "type": "string", + "format": "uri" + }, + "network_address": { + "type": "string", + "format": "ipv4" + }, + "photo": { + "type": "string", + "contentEncoding": "base64" + }, + "photo2": { + "type": "string", + "contentEncoding": "base64" + }, + "feeling": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "age": { + "type": "integer", + "maximum": 120, + "exclusiveMaximum": 121, + "minimum": 18, + "exclusiveMinimum": 17 + }, + "email": { + "type": "string", + "format": "email" + }, + "Baz": { + "type": "string", + "foo": [ + "bar", + "bar1" + ], + "hello": "world" + }, + "color": { + "type": "string", + "enum": [ + "red", + "green", + "blue" + ] + }, + "rank": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ] + }, + "mult": { + "type": "number", + "enum": [ + 1, + 1.5, + 2 + ] + }, + "roles": { + "items": { + "type": "string", + "enum": [ + "admin", + "moderator", + "user" + ] + }, + "type": "array" + }, + "priorities": { + "items": { + "type": "integer", + "enum": [ + -1, + 0, + 1 + ] + }, + "type": "array" + }, + "offsets": { + "items": { + "type": "number", + "enum": [ + 1.570796, + 3.141592, + 6.283185 + ] + }, + "type": "array" + }, + "anything": true, + "raw": true + }, + "additionalProperties": false, + "type": "object", + "required": [ + "some_base_property", + "some_base_property_yaml", + "grand", + "SomeUntaggedBaseProperty", + "PublicNonExported", + "id", + "name", + "password", + "TestFlag", + "age", + "email", + "Baz", + "color", + "roles", + "raw" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/custom_map_type.json b/pkg/schema/testdata/custom_map_type.json new file mode 100644 index 0000000..baa287d --- /dev/null +++ b/pkg/schema/testdata/custom_map_type.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/custom-map-outer", + "$ref": "#/$defs/CustomMapOuter", + "$defs": { + "CustomMapOuter": { + "properties": { + "my_map": { + "$ref": "#/$defs/CustomMapType" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "my_map" + ] + }, + "CustomMapType": { + "items": { + "properties": { + "key": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "type": "object", + "required": [ + "key", + "value" + ] + }, + "type": "array" + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/custom_slice_type.json b/pkg/schema/testdata/custom_slice_type.json new file mode 100644 index 0000000..6efbf6d --- /dev/null +++ b/pkg/schema/testdata/custom_slice_type.json @@ -0,0 +1,32 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/custom-slice-outer", + "$ref": "#/$defs/CustomSliceOuter", + "$defs": { + "CustomSliceOuter": { + "properties": { + "slice": { + "$ref": "#/$defs/CustomSliceType" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "slice" + ] + }, + "CustomSliceType": { + "oneOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + } + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/custom_type.json b/pkg/schema/testdata/custom_type.json new file mode 100644 index 0000000..be653bb --- /dev/null +++ b/pkg/schema/testdata/custom_type.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/custom-type-field", + "$ref": "#/$defs/CustomTypeField", + "$defs": { + "CustomTypeField": { + "properties": { + "CreatedAt": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "CreatedAt" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/custom_type_extend.json b/pkg/schema/testdata/custom_type_extend.json new file mode 100644 index 0000000..78de818 --- /dev/null +++ b/pkg/schema/testdata/custom_type_extend.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/schema-extend-test", + "$ref": "#/$defs/SchemaExtendTest", + "$defs": { + "SchemaExtendTest": { + "properties": { + "LastName": { + "type": "string", + "description": "some extra words" + }, + "middle_name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "LastName" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/custom_type_with_interface.json b/pkg/schema/testdata/custom_type_with_interface.json new file mode 100644 index 0000000..93dbd12 --- /dev/null +++ b/pkg/schema/testdata/custom_type_with_interface.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/custom-type-field-with-interface", + "$ref": "#/$defs/CustomTypeFieldWithInterface", + "$defs": { + "CustomTimeWithInterface": { + "type": "string", + "format": "date-time" + }, + "CustomTypeFieldWithInterface": { + "properties": { + "CreatedAt": { + "$ref": "#/$defs/CustomTimeWithInterface" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "CreatedAt" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/defaults_expanded_toplevel.json b/pkg/schema/testdata/defaults_expanded_toplevel.json new file mode 100644 index 0000000..8b82e64 --- /dev/null +++ b/pkg/schema/testdata/defaults_expanded_toplevel.json @@ -0,0 +1,228 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-user", + "$defs": { + "Bytes": { + "type": "string", + "contentEncoding": "base64" + }, + "GrandfatherType": { + "properties": { + "family_name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "family_name" + ] + }, + "MapType": { + "type": "object" + } + }, + "properties": { + "id": { + "type": "integer" + }, + "some_base_property": { + "type": "integer" + }, + "grand": { + "$ref": "#/$defs/GrandfatherType" + }, + "SomeUntaggedBaseProperty": { + "type": "boolean" + }, + "PublicNonExported": { + "type": "integer" + }, + "MapType": { + "$ref": "#/$defs/MapType" + }, + "name": { + "type": "string", + "maxLength": 20, + "minLength": 1, + "pattern": ".*", + "title": "the name", + "description": "this is a property", + "default": "alex", + "readOnly": true, + "examples": [ + "joe", + "lucy" + ] + }, + "password": { + "type": "string", + "writeOnly": true + }, + "friends": { + "items": { + "type": "integer" + }, + "type": "array", + "description": "list of IDs, omitted when empty" + }, + "tags": { + "additionalProperties": { + "type": "string" + }, + "type": "object" + }, + "options": { + "type": "object" + }, + "TestFlag": { + "type": "boolean" + }, + "TestFlagFalse": { + "type": "boolean", + "default": false + }, + "TestFlagTrue": { + "type": "boolean", + "default": true + }, + "birth_date": { + "type": "string", + "format": "date-time" + }, + "website": { + "type": "string", + "format": "uri" + }, + "network_address": { + "type": "string", + "format": "ipv4" + }, + "photo": { + "type": "string", + "contentEncoding": "base64" + }, + "photo2": { + "$ref": "#/$defs/Bytes" + }, + "feeling": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "age": { + "type": "integer", + "maximum": 120, + "exclusiveMaximum": 121, + "minimum": 18, + "exclusiveMinimum": 17 + }, + "email": { + "type": "string", + "format": "email" + }, + "uuid": { + "type": "string", + "format": "uuid" + }, + "Baz": { + "type": "string", + "foo": [ + "bar", + "bar1" + ], + "hello": "world" + }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, + "color": { + "type": "string", + "enum": [ + "red", + "green", + "blue" + ] + }, + "rank": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ] + }, + "mult": { + "type": "number", + "enum": [ + 1.0, + 1.5, + 2.0 + ] + }, + "roles": { + "items": { + "type": "string", + "enum": [ + "admin", + "moderator", + "user" + ] + }, + "type": "array" + }, + "priorities": { + "items": { + "type": "integer", + "enum": [ + -1, + 0, + 1 + ] + }, + "type": "array" + }, + "offsets": { + "items": { + "type": "number", + "enum": [ + 1.570796, + 3.141592, + 6.283185 + ] + }, + "type": "array" + }, + "anything": true, + "raw": true + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "some_base_property", + "grand", + "SomeUntaggedBaseProperty", + "PublicNonExported", + "MapType", + "name", + "password", + "TestFlag", + "photo", + "photo2", + "age", + "email", + "uuid", + "Baz", + "color", + "roles", + "raw" + ] +} \ No newline at end of file diff --git a/pkg/schema/testdata/equals_in_pattern.json b/pkg/schema/testdata/equals_in_pattern.json new file mode 100644 index 0000000..21cf029 --- /dev/null +++ b/pkg/schema/testdata/equals_in_pattern.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/pattern-equals-test", + "$ref": "#/$defs/PatternEqualsTest", + "$defs": { + "PatternEqualsTest": { + "properties": { + "WithEquals": { + "type": "string", + "pattern": "foo=bar" + }, + "WithEqualsAndCommas": { + "type": "string", + "pattern": "foo,=bar" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "WithEquals", + "WithEqualsAndCommas" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/go_comments.json b/pkg/schema/testdata/go_comments.json new file mode 100644 index 0000000..99f454a --- /dev/null +++ b/pkg/schema/testdata/go_comments.json @@ -0,0 +1,113 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/examples/user", + "$ref": "#/$defs/User", + "$defs": { + "NamedPets": { + "additionalProperties": { + "$ref": "#/$defs/Pet" + }, + "type": "object", + "description": "NamedPets is a map of animal names to pets." + }, + "Pet": { + "properties": { + "name": { + "type": "string", + "title": "Name", + "description": "Name of the animal." + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name" + ], + "description": "Pet defines the user's fury friend." + }, + "Pets": { + "items": { + "$ref": "#/$defs/Pet" + }, + "type": "array", + "description": "Pets is a collection of Pet objects." + }, + "Plant": { + "properties": { + "variant": { + "type": "string", + "title": "Variant", + "description": "This comment will be used" + }, + "multicellular": { + "type": "boolean", + "title": "Multicellular", + "description": "Multicellular is true if the plant is multicellular" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "variant" + ], + "description": "Plant represents the plants the user might have and serves as a test of structs inside a `type` set." + }, + "User": { + "properties": { + "id": { + "type": "integer", + "description": "Unique sequential identifier." + }, + "name": { + "type": "string", + "maxLength": 20, + "minLength": 1, + "pattern": ".*", + "title": "the name", + "description": "this is a property", + "default": "alex", + "examples": [ + "joe", + "lucy" + ] + }, + "friends": { + "items": { + "type": "integer" + }, + "type": "array", + "description": "list of IDs, omitted when empty" + }, + "tags": { + "type": "object" + }, + "pets": { + "$ref": "#/$defs/Pets", + "description": "An array of pets the user cares for." + }, + "named_pets": { + "$ref": "#/$defs/NamedPets", + "description": "Set of animal names to pets" + }, + "plants": { + "items": { + "$ref": "#/$defs/Plant" + }, + "type": "array", + "title": "Plants", + "description": "Set of plants that the user likes" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "name", + "pets", + "named_pets", + "plants" + ], + "description": "User is used as a base to provide tests for comments." + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/ignore_type.json b/pkg/schema/testdata/ignore_type.json new file mode 100644 index 0000000..08d680e --- /dev/null +++ b/pkg/schema/testdata/ignore_type.json @@ -0,0 +1,224 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-user", + "$ref": "#/$defs/TestUser", + "$defs": { + "Bytes": { + "type": "string", + "contentEncoding": "base64" + }, + "GrandfatherType": { + "properties": {}, + "additionalProperties": false, + "type": "object" + }, + "MapType": { + "type": "object" + }, + "TestUser": { + "properties": { + "id": { + "type": "integer" + }, + "some_base_property": { + "type": "integer" + }, + "grand": { + "$ref": "#/$defs/GrandfatherType" + }, + "SomeUntaggedBaseProperty": { + "type": "boolean" + }, + "PublicNonExported": { + "type": "integer" + }, + "MapType": { + "$ref": "#/$defs/MapType" + }, + "name": { + "type": "string", + "maxLength": 20, + "minLength": 1, + "pattern": ".*", + "title": "the name", + "description": "this is a property", + "default": "alex", + "readOnly": true, + "examples": [ + "joe", + "lucy" + ] + }, + "password": { + "type": "string", + "writeOnly": true + }, + "friends": { + "items": { + "type": "integer" + }, + "type": "array", + "description": "list of IDs, omitted when empty" + }, + "tags": { + "additionalProperties": { + "type": "string" + }, + "type": "object" + }, + "options": { + "type": "object" + }, + "TestFlag": { + "type": "boolean" + }, + "TestFlagFalse": { + "type": "boolean", + "default": false + }, + "TestFlagTrue": { + "type": "boolean", + "default": true + }, + "birth_date": { + "type": "string", + "format": "date-time" + }, + "website": { + "type": "string", + "format": "uri" + }, + "network_address": { + "type": "string", + "format": "ipv4" + }, + "photo": { + "type": "string", + "contentEncoding": "base64" + }, + "photo2": { + "$ref": "#/$defs/Bytes" + }, + "feeling": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "age": { + "type": "integer", + "maximum": 120, + "exclusiveMaximum": 121, + "minimum": 18, + "exclusiveMinimum": 17 + }, + "email": { + "type": "string", + "format": "email" + }, + "uuid": { + "type": "string", + "format": "uuid" + }, + "Baz": { + "type": "string", + "foo": [ + "bar", + "bar1" + ], + "hello": "world" + }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, + "color": { + "type": "string", + "enum": [ + "red", + "green", + "blue" + ] + }, + "rank": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ] + }, + "mult": { + "type": "number", + "enum": [ + 1.0, + 1.5, + 2.0 + ] + }, + "roles": { + "items": { + "type": "string", + "enum": [ + "admin", + "moderator", + "user" + ] + }, + "type": "array" + }, + "priorities": { + "items": { + "type": "integer", + "enum": [ + -1, + 0, + 1 + ] + }, + "type": "array" + }, + "offsets": { + "items": { + "type": "number", + "enum": [ + 1.570796, + 3.141592, + 6.283185 + ] + }, + "type": "array" + }, + "anything": true, + "raw": true + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "some_base_property", + "grand", + "SomeUntaggedBaseProperty", + "PublicNonExported", + "MapType", + "name", + "password", + "TestFlag", + "photo", + "photo2", + "age", + "email", + "uuid", + "Baz", + "color", + "roles", + "raw" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/inlining_embedded.json b/pkg/schema/testdata/inlining_embedded.json new file mode 100644 index 0000000..1b43a70 --- /dev/null +++ b/pkg/schema/testdata/inlining_embedded.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/outer-named", + "$defs": { + "Inner": { + "properties": { + "Foo": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "Foo" + ] + } + }, + "properties": { + "text": { + "type": "string" + }, + "inner": { + "$ref": "#/$defs/Inner" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "inner" + ] +} \ No newline at end of file diff --git a/pkg/schema/testdata/inlining_embedded_anchored.json b/pkg/schema/testdata/inlining_embedded_anchored.json new file mode 100644 index 0000000..120ab9d --- /dev/null +++ b/pkg/schema/testdata/inlining_embedded_anchored.json @@ -0,0 +1,33 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/outer-named", + "$anchor": "OuterNamed", + "$defs": { + "Inner": { + "$anchor": "Inner", + "properties": { + "Foo": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "Foo" + ] + } + }, + "properties": { + "text": { + "type": "string" + }, + "inner": { + "$ref": "#/$defs/Inner" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "inner" + ] +} \ No newline at end of file diff --git a/pkg/schema/testdata/inlining_inheritance.json b/pkg/schema/testdata/inlining_inheritance.json new file mode 100644 index 0000000..85e3041 --- /dev/null +++ b/pkg/schema/testdata/inlining_inheritance.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/outer", + "properties": { + "TextNamed": { + "type": "string" + }, + "Text": { + "type": "string" + }, + "Foo": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "TextNamed", + "Foo" + ] +} \ No newline at end of file diff --git a/pkg/schema/testdata/inlining_ptr.json b/pkg/schema/testdata/inlining_ptr.json new file mode 100644 index 0000000..331fe7f --- /dev/null +++ b/pkg/schema/testdata/inlining_ptr.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/outer-ptr", + "properties": { + "Foo": { + "type": "string" + }, + "Text": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "Foo" + ] +} \ No newline at end of file diff --git a/pkg/schema/testdata/inlining_tag.json b/pkg/schema/testdata/inlining_tag.json new file mode 100644 index 0000000..f2e1b2d --- /dev/null +++ b/pkg/schema/testdata/inlining_tag.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/outer-inlined", + "properties": { + "text": { + "type": "string" + }, + "Foo": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "Foo" + ] +} \ No newline at end of file diff --git a/pkg/schema/testdata/keynamed.json b/pkg/schema/testdata/keynamed.json new file mode 100644 index 0000000..0116762 --- /dev/null +++ b/pkg/schema/testdata/keynamed.json @@ -0,0 +1,52 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/key-named", + "$ref": "#/$defs/KeyNamed", + "$defs": { + "KeyNamed": { + "properties": { + "ThisWasLeftAsIs": { + "type": "string" + }, + "coming_from_json_tag": { + "type": "boolean" + }, + "nested_not_renamed": { + "$ref": "#/$defs/KeyNamedNested" + }, + "✨unicode✨ s̸̥͝h̷̳͒e̴̜̽n̸̡̿a̷̘̔n̷̘͐i̶̫̐ǵ̶̯a̵̘͒n̷̮̾s̸̟̓": { + "type": "string" + }, + "20.01": { + "type": "integer", + "description": "Description was preserved" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "ThisWasLeftAsIs", + "coming_from_json_tag", + "nested_not_renamed", + "✨unicode✨ s̸̥͝h̷̳͒e̴̜̽n̸̡̿a̷̘̔n̷̘͐i̶̫̐ǵ̶̯a̵̘͒n̷̮̾s̸̟̓", + "20.01" + ] + }, + "KeyNamedNested": { + "properties": { + "nested-renamed-property": { + "type": "string" + }, + "NotRenamed": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "nested-renamed-property", + "NotRenamed" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/lookup.json b/pkg/schema/testdata/lookup.json new file mode 100644 index 0000000..1d52012 --- /dev/null +++ b/pkg/schema/testdata/lookup.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/schemas/lookup-user", + "$ref": "#/$defs/LookupUser", + "$defs": { + "LookupUser": { + "properties": { + "name": { + "$ref": "https://example.com/schemas/lookup-name" + }, + "alias": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/lookup_expanded.json b/pkg/schema/testdata/lookup_expanded.json new file mode 100644 index 0000000..a9013da --- /dev/null +++ b/pkg/schema/testdata/lookup_expanded.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/schemas/lookup-user", + "$anchor": "LookupUser", + "properties": { + "name": { + "$ref": "https://example.com/schemas/lookup-name" + }, + "alias": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name" + ] +} \ No newline at end of file diff --git a/pkg/schema/testdata/map_type.json b/pkg/schema/testdata/map_type.json new file mode 100644 index 0000000..67c6e1f --- /dev/null +++ b/pkg/schema/testdata/map_type.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/map-type", + "$ref": "#/$defs/MapType", + "$defs": { + "MapType": { + "type": "object" + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/no_reference.json b/pkg/schema/testdata/no_reference.json new file mode 100644 index 0000000..0664046 --- /dev/null +++ b/pkg/schema/testdata/no_reference.json @@ -0,0 +1,217 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-user", + "properties": { + "id": { + "type": "integer" + }, + "some_base_property": { + "type": "integer" + }, + "grand": { + "properties": { + "family_name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "family_name" + ] + }, + "SomeUntaggedBaseProperty": { + "type": "boolean" + }, + "PublicNonExported": { + "type": "integer" + }, + "MapType": { + "type": "object" + }, + "name": { + "type": "string", + "maxLength": 20, + "minLength": 1, + "pattern": ".*", + "title": "the name", + "description": "this is a property", + "default": "alex", + "readOnly": true, + "examples": [ + "joe", + "lucy" + ] + }, + "password": { + "type": "string", + "writeOnly": true + }, + "friends": { + "items": { + "type": "integer" + }, + "type": "array", + "description": "list of IDs, omitted when empty" + }, + "tags": { + "additionalProperties": { + "type": "string" + }, + "type": "object" + }, + "options": { + "type": "object" + }, + "TestFlag": { + "type": "boolean" + }, + "TestFlagFalse": { + "type": "boolean", + "default": false + }, + "TestFlagTrue": { + "type": "boolean", + "default": true + }, + "birth_date": { + "type": "string", + "format": "date-time" + }, + "website": { + "type": "string", + "format": "uri" + }, + "network_address": { + "type": "string", + "format": "ipv4" + }, + "photo": { + "type": "string", + "contentEncoding": "base64" + }, + "photo2": { + "type": "string", + "contentEncoding": "base64" + }, + "feeling": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "age": { + "type": "integer", + "maximum": 120, + "exclusiveMaximum": 121, + "minimum": 18, + "exclusiveMinimum": 17 + }, + "email": { + "type": "string", + "format": "email" + }, + "uuid": { + "type": "string", + "format": "uuid" + }, + "Baz": { + "type": "string", + "foo": [ + "bar", + "bar1" + ], + "hello": "world" + }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, + "color": { + "type": "string", + "enum": [ + "red", + "green", + "blue" + ] + }, + "rank": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ] + }, + "mult": { + "type": "number", + "enum": [ + 1.0, + 1.5, + 2.0 + ] + }, + "roles": { + "items": { + "type": "string", + "enum": [ + "admin", + "moderator", + "user" + ] + }, + "type": "array" + }, + "priorities": { + "items": { + "type": "integer", + "enum": [ + -1, + 0, + 1 + ] + }, + "type": "array" + }, + "offsets": { + "items": { + "type": "number", + "enum": [ + 1.570796, + 3.141592, + 6.283185 + ] + }, + "type": "array" + }, + "anything": true, + "raw": true + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "some_base_property", + "grand", + "SomeUntaggedBaseProperty", + "PublicNonExported", + "MapType", + "name", + "password", + "TestFlag", + "photo", + "photo2", + "age", + "email", + "uuid", + "Baz", + "color", + "roles", + "raw" + ] +} \ No newline at end of file diff --git a/pkg/schema/testdata/no_reference_anchor.json b/pkg/schema/testdata/no_reference_anchor.json new file mode 100644 index 0000000..47ac173 --- /dev/null +++ b/pkg/schema/testdata/no_reference_anchor.json @@ -0,0 +1,219 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-user", + "$anchor": "TestUser", + "properties": { + "id": { + "type": "integer" + }, + "some_base_property": { + "type": "integer" + }, + "grand": { + "$anchor": "GrandfatherType", + "properties": { + "family_name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "family_name" + ] + }, + "SomeUntaggedBaseProperty": { + "type": "boolean" + }, + "PublicNonExported": { + "type": "integer" + }, + "MapType": { + "type": "object" + }, + "name": { + "type": "string", + "maxLength": 20, + "minLength": 1, + "pattern": ".*", + "title": "the name", + "description": "this is a property", + "default": "alex", + "readOnly": true, + "examples": [ + "joe", + "lucy" + ] + }, + "password": { + "type": "string", + "writeOnly": true + }, + "friends": { + "items": { + "type": "integer" + }, + "type": "array", + "description": "list of IDs, omitted when empty" + }, + "tags": { + "additionalProperties": { + "type": "string" + }, + "type": "object" + }, + "options": { + "type": "object" + }, + "TestFlag": { + "type": "boolean" + }, + "TestFlagFalse": { + "type": "boolean", + "default": false + }, + "TestFlagTrue": { + "type": "boolean", + "default": true + }, + "birth_date": { + "type": "string", + "format": "date-time" + }, + "website": { + "type": "string", + "format": "uri" + }, + "network_address": { + "type": "string", + "format": "ipv4" + }, + "photo": { + "type": "string", + "contentEncoding": "base64" + }, + "photo2": { + "type": "string", + "contentEncoding": "base64" + }, + "feeling": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "age": { + "type": "integer", + "maximum": 120, + "exclusiveMaximum": 121, + "minimum": 18, + "exclusiveMinimum": 17 + }, + "email": { + "type": "string", + "format": "email" + }, + "uuid": { + "type": "string", + "format": "uuid" + }, + "Baz": { + "type": "string", + "foo": [ + "bar", + "bar1" + ], + "hello": "world" + }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, + "color": { + "type": "string", + "enum": [ + "red", + "green", + "blue" + ] + }, + "rank": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ] + }, + "mult": { + "type": "number", + "enum": [ + 1.0, + 1.5, + 2.0 + ] + }, + "roles": { + "items": { + "type": "string", + "enum": [ + "admin", + "moderator", + "user" + ] + }, + "type": "array" + }, + "priorities": { + "items": { + "type": "integer", + "enum": [ + -1, + 0, + 1 + ] + }, + "type": "array" + }, + "offsets": { + "items": { + "type": "number", + "enum": [ + 1.570796, + 3.141592, + 6.283185 + ] + }, + "type": "array" + }, + "anything": true, + "raw": true + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "some_base_property", + "grand", + "SomeUntaggedBaseProperty", + "PublicNonExported", + "MapType", + "name", + "password", + "TestFlag", + "photo", + "photo2", + "age", + "email", + "uuid", + "Baz", + "color", + "roles", + "raw" + ] +} \ No newline at end of file diff --git a/pkg/schema/testdata/nullable.json b/pkg/schema/testdata/nullable.json new file mode 100644 index 0000000..3950bc2 --- /dev/null +++ b/pkg/schema/testdata/nullable.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-nullable", + "$ref": "#/$defs/TestNullable", + "$defs": { + "TestNullable": { + "properties": { + "child1": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "child1" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/number_handling.json b/pkg/schema/testdata/number_handling.json new file mode 100644 index 0000000..02e272f --- /dev/null +++ b/pkg/schema/testdata/number_handling.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/number-handler", + "$ref": "#/$defs/NumberHandler", + "$defs": { + "NumberHandler": { + "properties": { + "int64": { + "type": "integer", + "default": 12 + }, + "float32": { + "type": "number", + "default": 12.5 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "int64", + "float32" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/oneof.json b/pkg/schema/testdata/oneof.json new file mode 100644 index 0000000..0558b33 --- /dev/null +++ b/pkg/schema/testdata/oneof.json @@ -0,0 +1,104 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/root-one-of", + "$ref": "#/$defs/RootOneOf", + "$defs": { + "ChildOneOf": { + "oneOf": [ + { + "required": [ + "child1", + "child4" + ], + "title": "group1" + }, + { + "required": [ + "child2", + "child3" + ], + "title": "group2" + } + ], + "properties": { + "child1": { + "type": "string" + }, + "child2": { + "type": "string" + }, + "child3": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array" + } + ] + }, + "child4": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "RootOneOf": { + "oneOf": [ + { + "required": [ + "field1", + "field4" + ], + "title": "group1" + }, + { + "required": [ + "field2" + ], + "title": "group2" + } + ], + "properties": { + "field1": { + "type": "string" + }, + "field2": { + "type": "string" + }, + "field3": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array" + } + ] + }, + "field4": { + "type": "string" + }, + "child": { + "$ref": "#/$defs/ChildOneOf" + }, + "field6": { + "oneOf": [ + { + "$ref": "Outer" + }, + { + "$ref": "OuterNamed" + }, + { + "$ref": "OuterPtr" + } + ] + } + }, + "additionalProperties": false, + "type": "object" + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/oneof_ref.json b/pkg/schema/testdata/oneof_ref.json new file mode 100644 index 0000000..1638ecf --- /dev/null +++ b/pkg/schema/testdata/oneof_ref.json @@ -0,0 +1,59 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/server", + "$ref": "#/$defs/Server", + "$defs": { + "Server": { + "properties": { + "ip_address": { + "oneOf": [ + { + "$ref": "#/$defs/ipv4" + }, + { + "$ref": "#/$defs/ipv6" + } + ] + }, + "ip_addresses": { + "items": { + "oneOf": [ + { + "$ref": "#/$defs/ipv4" + }, + { + "$ref": "#/$defs/ipv6" + } + ] + }, + "type": "array" + }, + "ip_address_any": { + "anyOf": [ + { + "$ref": "#/$defs/ipv4" + }, + { + "$ref": "#/$defs/ipv6" + } + ] + }, + "ip_addresses_any": { + "items": { + "anyOf": [ + { + "$ref": "#/$defs/ipv4" + }, + { + "$ref": "#/$defs/ipv6" + } + ] + }, + "type": "array" + } + }, + "additionalProperties": false, + "type": "object" + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/recursive.json b/pkg/schema/testdata/recursive.json new file mode 100644 index 0000000..ce3dfb1 --- /dev/null +++ b/pkg/schema/testdata/recursive.json @@ -0,0 +1,25 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/recursive-example", + "$ref": "#/$defs/RecursiveExample", + "$defs": { + "RecursiveExample": { + "properties": { + "text": { + "type": "string" + }, + "children": { + "items": { + "$ref": "#/$defs/RecursiveExample" + }, + "type": "array" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "text" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/required_from_jsontags.json b/pkg/schema/testdata/required_from_jsontags.json new file mode 100644 index 0000000..9f3cbcf --- /dev/null +++ b/pkg/schema/testdata/required_from_jsontags.json @@ -0,0 +1,218 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-user", + "$ref": "#/$defs/TestUser", + "$defs": { + "Bytes": { + "type": "string", + "contentEncoding": "base64" + }, + "GrandfatherType": { + "properties": { + "family_name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "family_name" + ] + }, + "MapType": { + "type": "object" + }, + "TestUser": { + "properties": { + "id": { + "type": "integer" + }, + "some_base_property": { + "type": "integer" + }, + "grand": { + "$ref": "#/$defs/GrandfatherType" + }, + "SomeUntaggedBaseProperty": { + "type": "boolean" + }, + "PublicNonExported": { + "type": "integer" + }, + "MapType": { + "$ref": "#/$defs/MapType" + }, + "name": { + "type": "string", + "maxLength": 20, + "minLength": 1, + "pattern": ".*", + "title": "the name", + "description": "this is a property", + "default": "alex", + "readOnly": true, + "examples": [ + "joe", + "lucy" + ] + }, + "password": { + "type": "string", + "writeOnly": true + }, + "friends": { + "items": { + "type": "integer" + }, + "type": "array", + "description": "list of IDs, omitted when empty" + }, + "tags": { + "additionalProperties": { + "type": "string" + }, + "type": "object" + }, + "options": { + "type": "object" + }, + "TestFlag": { + "type": "boolean" + }, + "TestFlagFalse": { + "type": "boolean", + "default": false + }, + "TestFlagTrue": { + "type": "boolean", + "default": true + }, + "birth_date": { + "type": "string", + "format": "date-time" + }, + "website": { + "type": "string", + "format": "uri" + }, + "network_address": { + "type": "string", + "format": "ipv4" + }, + "photo": { + "type": "string", + "contentEncoding": "base64" + }, + "photo2": { + "$ref": "#/$defs/Bytes" + }, + "feeling": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "age": { + "type": "integer", + "maximum": 120, + "exclusiveMaximum": 121, + "minimum": 18, + "exclusiveMinimum": 17 + }, + "email": { + "type": "string", + "format": "email" + }, + "uuid": { + "type": "string", + "format": "uuid" + }, + "Baz": { + "type": "string", + "foo": [ + "bar", + "bar1" + ], + "hello": "world" + }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, + "color": { + "type": "string", + "enum": [ + "red", + "green", + "blue" + ] + }, + "rank": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ] + }, + "mult": { + "type": "number", + "enum": [ + 1.0, + 1.5, + 2.0 + ] + }, + "roles": { + "items": { + "type": "string", + "enum": [ + "admin", + "moderator", + "user" + ] + }, + "type": "array" + }, + "priorities": { + "items": { + "type": "integer", + "enum": [ + -1, + 0, + 1 + ] + }, + "type": "array" + }, + "offsets": { + "items": { + "type": "number", + "enum": [ + 1.570796, + 3.141592, + 6.283185 + ] + }, + "type": "array" + }, + "anything": true, + "raw": true + }, + "additionalProperties": false, + "type": "object", + "required": [ + "SomeUntaggedBaseProperty", + "id", + "name", + "photo", + "photo2" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/run.py b/pkg/schema/testdata/run.py new file mode 100644 index 0000000..6fa0e0f --- /dev/null +++ b/pkg/schema/testdata/run.py @@ -0,0 +1,13 @@ +import os + +line = "conneroisu/groq-go" +replace = "conneroisu/groq-go/pkg/schema" +# for each json file in the directory +for file in os.listdir(): + if file.endswith(".json"): + with open(file, "r") as f: + data = f.read() + data = data.replace(line, replace) + with open(file, "w") as f: + _ = f.write(data) + diff --git a/pkg/schema/testdata/schema_alias.json b/pkg/schema/testdata/schema_alias.json new file mode 100644 index 0000000..ef28585 --- /dev/null +++ b/pkg/schema/testdata/schema_alias.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/alias-object-b", + "$ref": "#/$defs/AliasObjectA", + "$defs": { + "AliasObjectA": { + "properties": { + "prop_a": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "prop_a" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/schema_alias_2.json b/pkg/schema/testdata/schema_alias_2.json new file mode 100644 index 0000000..0a2586b --- /dev/null +++ b/pkg/schema/testdata/schema_alias_2.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/alias-object-c", + "$ref": "#/$defs/AliasObjectC", + "$defs": { + "AliasObjectA": { + "properties": { + "prop_a": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "prop_a" + ] + }, + "AliasObjectC": { + "properties": { + "obj_b": { + "$ref": "#/$defs/AliasObjectA" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "obj_b" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/schema_property_alias.json b/pkg/schema/testdata/schema_property_alias.json new file mode 100644 index 0000000..73e6eb9 --- /dev/null +++ b/pkg/schema/testdata/schema_property_alias.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/alias-property-object-base", + "$ref": "#/$defs/AliasPropertyObjectBase", + "$defs": { + "AliasObjectA": { + "properties": { + "prop_a": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "prop_a" + ] + }, + "AliasPropertyObjectBase": { + "properties": { + "object": { + "$ref": "#/$defs/AliasObjectA" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "object" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/schema_with_expression.json b/pkg/schema/testdata/schema_with_expression.json new file mode 100644 index 0000000..847d130 --- /dev/null +++ b/pkg/schema/testdata/schema_with_expression.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/expression", + "$ref": "#/$defs/Expression", + "$defs": { + "Expression": { + "properties": { + "value": { + "type": "integer", + "foo": "bar=='baz'" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "value" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/schema_with_minimum.json b/pkg/schema/testdata/schema_with_minimum.json new file mode 100644 index 0000000..0e922f3 --- /dev/null +++ b/pkg/schema/testdata/schema_with_minimum.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/min-value", + "$ref": "#/$defs/MinValue", + "$defs": { + "MinValue": { + "properties": { + "value4": { + "type": "integer", + "minimum": 0 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "value4" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/test_config.json b/pkg/schema/testdata/test_config.json new file mode 100644 index 0000000..f476588 --- /dev/null +++ b/pkg/schema/testdata/test_config.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/config", + "$ref": "#/$defs/Config", + "$defs": { + "Config": { + "properties": { + "name": { + "type": "string" + }, + "count": { + "type": "integer" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "count" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/test_description_override.json b/pkg/schema/testdata/test_description_override.json new file mode 100644 index 0000000..22be63d --- /dev/null +++ b/pkg/schema/testdata/test_description_override.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-description-override", + "$ref": "#/$defs/TestDescriptionOverride", + "$defs": { + "TestDescriptionOverride": { + "properties": { + "FirstName": { + "type": "string", + "description": "test2" + }, + "LastName": { + "type": "string", + "description": "test3" + }, + "age": { + "type": "integer", + "description": "test4" + }, + "middle_name": { + "type": "string", + "description": "test5" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "FirstName", + "LastName", + "age" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/test_user.json b/pkg/schema/testdata/test_user.json new file mode 100644 index 0000000..8c11152 --- /dev/null +++ b/pkg/schema/testdata/test_user.json @@ -0,0 +1,231 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-user", + "$ref": "#/$defs/TestUser", + "$defs": { + "Bytes": { + "type": "string", + "contentEncoding": "base64" + }, + "GrandfatherType": { + "properties": { + "family_name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "family_name" + ] + }, + "MapType": { + "type": "object" + }, + "TestUser": { + "properties": { + "id": { + "type": "integer" + }, + "some_base_property": { + "type": "integer" + }, + "grand": { + "$ref": "#/$defs/GrandfatherType" + }, + "SomeUntaggedBaseProperty": { + "type": "boolean" + }, + "PublicNonExported": { + "type": "integer" + }, + "MapType": { + "$ref": "#/$defs/MapType" + }, + "name": { + "type": "string", + "maxLength": 20, + "minLength": 1, + "pattern": ".*", + "title": "the name", + "description": "this is a property", + "default": "alex", + "readOnly": true, + "examples": [ + "joe", + "lucy" + ] + }, + "password": { + "type": "string", + "writeOnly": true + }, + "friends": { + "items": { + "type": "integer" + }, + "type": "array", + "description": "list of IDs, omitted when empty" + }, + "tags": { + "additionalProperties": { + "type": "string" + }, + "type": "object" + }, + "options": { + "type": "object" + }, + "TestFlag": { + "type": "boolean" + }, + "TestFlagFalse": { + "type": "boolean", + "default": false + }, + "TestFlagTrue": { + "type": "boolean", + "default": true + }, + "birth_date": { + "type": "string", + "format": "date-time" + }, + "website": { + "type": "string", + "format": "uri" + }, + "network_address": { + "type": "string", + "format": "ipv4" + }, + "photo": { + "type": "string", + "contentEncoding": "base64" + }, + "photo2": { + "$ref": "#/$defs/Bytes" + }, + "feeling": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "age": { + "type": "integer", + "maximum": 120, + "exclusiveMaximum": 121, + "minimum": 18, + "exclusiveMinimum": 17 + }, + "email": { + "type": "string", + "format": "email" + }, + "uuid": { + "type": "string", + "format": "uuid" + }, + "Baz": { + "type": "string", + "foo": [ + "bar", + "bar1" + ], + "hello": "world" + }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, + "color": { + "type": "string", + "enum": [ + "red", + "green", + "blue" + ] + }, + "rank": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ] + }, + "mult": { + "type": "number", + "enum": [ + 1.0, + 1.5, + 2.0 + ] + }, + "roles": { + "items": { + "type": "string", + "enum": [ + "admin", + "moderator", + "user" + ] + }, + "type": "array" + }, + "priorities": { + "items": { + "type": "integer", + "enum": [ + -1, + 0, + 1 + ] + }, + "type": "array" + }, + "offsets": { + "items": { + "type": "number", + "enum": [ + 1.570796, + 3.141592, + 6.283185 + ] + }, + "type": "array" + }, + "anything": true, + "raw": true + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "some_base_property", + "grand", + "SomeUntaggedBaseProperty", + "PublicNonExported", + "MapType", + "name", + "password", + "TestFlag", + "photo", + "photo2", + "age", + "email", + "uuid", + "Baz", + "color", + "roles", + "raw" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/test_user_assign_anchor.json b/pkg/schema/testdata/test_user_assign_anchor.json new file mode 100644 index 0000000..cf13e86 --- /dev/null +++ b/pkg/schema/testdata/test_user_assign_anchor.json @@ -0,0 +1,233 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-user", + "$ref": "#/$defs/TestUser", + "$defs": { + "Bytes": { + "type": "string", + "contentEncoding": "base64" + }, + "GrandfatherType": { + "$anchor": "GrandfatherType", + "properties": { + "family_name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "family_name" + ] + }, + "MapType": { + "type": "object" + }, + "TestUser": { + "$anchor": "TestUser", + "properties": { + "id": { + "type": "integer" + }, + "some_base_property": { + "type": "integer" + }, + "grand": { + "$ref": "#/$defs/GrandfatherType" + }, + "SomeUntaggedBaseProperty": { + "type": "boolean" + }, + "PublicNonExported": { + "type": "integer" + }, + "MapType": { + "$ref": "#/$defs/MapType" + }, + "name": { + "type": "string", + "maxLength": 20, + "minLength": 1, + "pattern": ".*", + "title": "the name", + "description": "this is a property", + "default": "alex", + "readOnly": true, + "examples": [ + "joe", + "lucy" + ] + }, + "password": { + "type": "string", + "writeOnly": true + }, + "friends": { + "items": { + "type": "integer" + }, + "type": "array", + "description": "list of IDs, omitted when empty" + }, + "tags": { + "additionalProperties": { + "type": "string" + }, + "type": "object" + }, + "options": { + "type": "object" + }, + "TestFlag": { + "type": "boolean" + }, + "TestFlagFalse": { + "type": "boolean", + "default": false + }, + "TestFlagTrue": { + "type": "boolean", + "default": true + }, + "birth_date": { + "type": "string", + "format": "date-time" + }, + "website": { + "type": "string", + "format": "uri" + }, + "network_address": { + "type": "string", + "format": "ipv4" + }, + "photo": { + "type": "string", + "contentEncoding": "base64" + }, + "photo2": { + "$ref": "#/$defs/Bytes" + }, + "feeling": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ] + }, + "age": { + "type": "integer", + "maximum": 120, + "exclusiveMaximum": 121, + "minimum": 18, + "exclusiveMinimum": 17 + }, + "email": { + "type": "string", + "format": "email" + }, + "uuid": { + "type": "string", + "format": "uuid" + }, + "Baz": { + "type": "string", + "foo": [ + "bar", + "bar1" + ], + "hello": "world" + }, + "bool_extra": { + "type": "string", + "isFalse": false, + "isTrue": true + }, + "color": { + "type": "string", + "enum": [ + "red", + "green", + "blue" + ] + }, + "rank": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ] + }, + "mult": { + "type": "number", + "enum": [ + 1.0, + 1.5, + 2.0 + ] + }, + "roles": { + "items": { + "type": "string", + "enum": [ + "admin", + "moderator", + "user" + ] + }, + "type": "array" + }, + "priorities": { + "items": { + "type": "integer", + "enum": [ + -1, + 0, + 1 + ] + }, + "type": "array" + }, + "offsets": { + "items": { + "type": "number", + "enum": [ + 1.570796, + 3.141592, + 6.283185 + ] + }, + "type": "array" + }, + "anything": true, + "raw": true + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "some_base_property", + "grand", + "SomeUntaggedBaseProperty", + "PublicNonExported", + "MapType", + "name", + "password", + "TestFlag", + "photo", + "photo2", + "age", + "email", + "uuid", + "Baz", + "color", + "roles", + "raw" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/test_yaml_and_json_prefer_yaml.json b/pkg/schema/testdata/test_yaml_and_json_prefer_yaml.json new file mode 100644 index 0000000..e0d59b3 --- /dev/null +++ b/pkg/schema/testdata/test_yaml_and_json_prefer_yaml.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/test-yaml-and-json", + "$ref": "#/$defs/TestYamlAndJson", + "$defs": { + "TestYamlAndJson": { + "properties": { + "first_name": { + "type": "string" + }, + "LastName": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "middle_name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "first_name", + "LastName", + "age" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/unsigned_int_handling.json b/pkg/schema/testdata/unsigned_int_handling.json new file mode 100644 index 0000000..3451855 --- /dev/null +++ b/pkg/schema/testdata/unsigned_int_handling.json @@ -0,0 +1,47 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/unsigned-int-handler", + "$ref": "#/$defs/UnsignedIntHandler", + "$defs": { + "UnsignedIntHandler": { + "properties": { + "min_len": { + "items": { + "type": "string", + "minLength": 0 + }, + "type": "array" + }, + "max_len": { + "items": { + "type": "string", + "maxLength": 0 + }, + "type": "array" + }, + "min_items": { + "items": { + "type": "string" + }, + "type": "array", + "minItems": 0 + }, + "max_items": { + "items": { + "type": "string" + }, + "type": "array", + "maxItems": 0 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "min_len", + "max_len", + "min_items", + "max_items" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/user_with_anchor.json b/pkg/schema/testdata/user_with_anchor.json new file mode 100644 index 0000000..7c1cf58 --- /dev/null +++ b/pkg/schema/testdata/user_with_anchor.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/user-with-anchor", + "$ref": "#/$defs/UserWithAnchor", + "$defs": { + "UserWithAnchor": { + "properties": { + "name": { + "$anchor": "Name", + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/with_custom_format.json b/pkg/schema/testdata/with_custom_format.json new file mode 100644 index 0000000..20aed0c --- /dev/null +++ b/pkg/schema/testdata/with_custom_format.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/conneroisu/groq-go/pkg/schema/with-custom-format", + "$ref": "#/$defs/WithCustomFormat", + "$defs": { + "WithCustomFormat": { + "properties": { + "dates": { + "items": { + "type": "string", + "format": "date" + }, + "type": "array" + }, + "odds": { + "items": { + "type": "string", + "format": "odd" + }, + "type": "array" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "dates", + "odds" + ] + } + } +} \ No newline at end of file diff --git a/pkg/schema/testdata/yaml_inline.json b/pkg/schema/testdata/yaml_inline.json new file mode 100644 index 0000000..7b396a9 --- /dev/null +++ b/pkg/schema/testdata/yaml_inline.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json-schema.org/draft/2020-12/schema", + "$ref": "#/$defs/TestYamlInline", + "definitions": { + "Inner": { + "required": ["foo"], + "properties": { + "foo": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + }, + "TestYamlInline": { + "required": [ + "Inlined" + ], + "properties": { + "Inlined": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Inner" + } + }, + "additionalProperties": false, + "type": "object" + } + } +}