From a0481f8d55d3b5db891c6d495d9df6a9d7d12762 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Wed, 28 Jun 2023 09:40:10 -0400 Subject: [PATCH 1/3] Remove ToSnakeCase for $id field Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- examples_test.go | 2 +- fixtures/allow_additional_props.json | 4 ++-- fixtures/anyof.json | 4 ++-- fixtures/array_type.json | 4 ++-- fixtures/base_schema_id.json | 4 ++-- fixtures/commas_in_pattern.json | 4 ++-- fixtures/compact_date.json | 4 ++-- fixtures/custom_additional.json | 4 ++-- fixtures/custom_map_type.json | 4 ++-- fixtures/custom_slice_type.json | 4 ++-- fixtures/custom_type.json | 4 ++-- fixtures/custom_type_extend.json | 4 ++-- fixtures/custom_type_with_interface.json | 4 ++-- fixtures/defaults_expanded_toplevel.json | 4 ++-- fixtures/go_comments.json | 4 ++-- fixtures/ignore_type.json | 4 ++-- fixtures/inlining_embedded.json | 4 ++-- fixtures/inlining_embedded_anchored.json | 4 ++-- fixtures/inlining_inheritance.json | 4 ++-- fixtures/inlining_ptr.json | 4 ++-- fixtures/keynamed.json | 4 ++-- fixtures/lookup.json | 6 +++--- fixtures/lookup_expanded.json | 6 +++--- fixtures/map_type.json | 4 ++-- fixtures/no_reference.json | 4 ++-- fixtures/no_reference_anchor.json | 4 ++-- fixtures/nullable.json | 4 ++-- fixtures/oneof.json | 4 ++-- fixtures/recursive.json | 4 ++-- fixtures/required_from_jsontags.json | 4 ++-- fixtures/schema_with_expression.json | 4 ++-- fixtures/schema_with_minimum.json | 4 ++-- fixtures/test_description_override.json | 4 ++-- fixtures/test_user.json | 4 ++-- fixtures/test_user_assign_anchor.json | 4 ++-- fixtures/test_yaml_and_json_prefer_yaml.json | 4 ++-- fixtures/user_with_anchor.json | 4 ++-- reflect.go | 2 +- reflect_test.go | 10 +++++----- 39 files changed, 81 insertions(+), 81 deletions(-) diff --git a/examples_test.go b/examples_test.go index 82cae05..c4bd62d 100644 --- a/examples_test.go +++ b/examples_test.go @@ -29,7 +29,7 @@ func ExampleReflect() { // Output: // { // "$schema": "https://json-schema.org/draft/2020-12/schema", - // "$id": "https://github.com/invopop/jsonschema_test/sample-user", + // "$id": "https://github.com/invopop/jsonschema_test/SampleUser", // "$ref": "#/$defs/SampleUser", // "$defs": { // "SampleUser": { diff --git a/fixtures/allow_additional_props.json b/fixtures/allow_additional_props.json index a2fe8d1..b23fe7a 100644 --- a/fixtures/allow_additional_props.json +++ b/fixtures/allow_additional_props.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-user", + "$id": "https://github.com/invopop/jsonschema/TestUser", "$ref": "#/$defs/TestUser", "$defs": { "Bytes": { @@ -226,4 +226,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/anyof.json b/fixtures/anyof.json index 8b3d4fe..2fbb1a3 100644 --- a/fixtures/anyof.json +++ b/fixtures/anyof.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/root-any-of", + "$id": "https://github.com/invopop/jsonschema/RootAnyOf", "$ref": "#/$defs/RootAnyOf", "$defs": { "ChildAnyOf": { @@ -88,4 +88,4 @@ "type": "object" } } -} \ No newline at end of file +} diff --git a/fixtures/array_type.json b/fixtures/array_type.json index a574591..f17eee1 100644 --- a/fixtures/array_type.json +++ b/fixtures/array_type.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/array-type", + "$id": "https://github.com/invopop/jsonschema/ArrayType", "$ref": "#/$defs/ArrayType", "$defs": { "ArrayType": { @@ -10,4 +10,4 @@ "type": "array" } } -} \ No newline at end of file +} diff --git a/fixtures/base_schema_id.json b/fixtures/base_schema_id.json index 7c52f31..f6c6786 100644 --- a/fixtures/base_schema_id.json +++ b/fixtures/base_schema_id.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schemas/lookup-user", + "$id": "https://example.com/schemas/LookupUser", "$ref": "#/$defs/LookupUser", "$defs": { "LookupName": { @@ -35,4 +35,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/commas_in_pattern.json b/fixtures/commas_in_pattern.json index a2f950c..8d54847 100644 --- a/fixtures/commas_in_pattern.json +++ b/fixtures/commas_in_pattern.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/pattern-test", + "$id": "https://github.com/invopop/jsonschema/PatternTest", "$ref": "#/$defs/PatternTest", "$defs": { "PatternTest": { @@ -19,4 +19,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/compact_date.json b/fixtures/compact_date.json index 927472e..4bcfd9f 100644 --- a/fixtures/compact_date.json +++ b/fixtures/compact_date.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/compact-date", + "$id": "https://github.com/invopop/jsonschema/CompactDate", "$ref": "#/$defs/CompactDate", "$defs": { "CompactDate": { @@ -10,4 +10,4 @@ "description": "Short date that only includes year and month" } } -} \ No newline at end of file +} diff --git a/fixtures/custom_additional.json b/fixtures/custom_additional.json index 4dc7992..b4daa5b 100644 --- a/fixtures/custom_additional.json +++ b/fixtures/custom_additional.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/grandfather-type", + "$id": "https://github.com/invopop/jsonschema/GrandfatherType", "$ref": "#/$defs/GrandfatherType", "$defs": { "GrandfatherType": { @@ -21,4 +21,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/custom_map_type.json b/fixtures/custom_map_type.json index 379efe2..e06db66 100644 --- a/fixtures/custom_map_type.json +++ b/fixtures/custom_map_type.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/custom-map-outer", + "$id": "https://github.com/invopop/jsonschema/CustomMapOuter", "$ref": "#/$defs/CustomMapOuter", "$defs": { "CustomMapOuter": { @@ -34,4 +34,4 @@ "type": "array" } } -} \ No newline at end of file +} diff --git a/fixtures/custom_slice_type.json b/fixtures/custom_slice_type.json index 6e5cb71..665f4f5 100644 --- a/fixtures/custom_slice_type.json +++ b/fixtures/custom_slice_type.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/custom-slice-outer", + "$id": "https://github.com/invopop/jsonschema/CustomSliceOuter", "$ref": "#/$defs/CustomSliceOuter", "$defs": { "CustomSliceOuter": { @@ -29,4 +29,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/custom_type.json b/fixtures/custom_type.json index 0cc5bab..da453f0 100644 --- a/fixtures/custom_type.json +++ b/fixtures/custom_type.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/custom-type-field", + "$id": "https://github.com/invopop/jsonschema/CustomTypeField", "$ref": "#/$defs/CustomTypeField", "$defs": { "CustomTypeField": { @@ -17,4 +17,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/custom_type_extend.json b/fixtures/custom_type_extend.json index a1dc9d4..fe4af42 100644 --- a/fixtures/custom_type_extend.json +++ b/fixtures/custom_type_extend.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/schema-extend-test", + "$id": "https://github.com/invopop/jsonschema/SchemaExtendTest", "$ref": "#/$defs/SchemaExtendTest", "$defs": { "SchemaExtendTest": { @@ -20,4 +20,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/custom_type_with_interface.json b/fixtures/custom_type_with_interface.json index 0e4c53d..d1a768b 100644 --- a/fixtures/custom_type_with_interface.json +++ b/fixtures/custom_type_with_interface.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/custom-type-field-with-interface", + "$id": "https://github.com/invopop/jsonschema/CustomTypeFieldWithInterface", "$ref": "#/$defs/CustomTypeFieldWithInterface", "$defs": { "CustomTimeWithInterface": { @@ -20,4 +20,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/defaults_expanded_toplevel.json b/fixtures/defaults_expanded_toplevel.json index c57ca8f..e56e41b 100644 --- a/fixtures/defaults_expanded_toplevel.json +++ b/fixtures/defaults_expanded_toplevel.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-user", + "$id": "https://github.com/invopop/jsonschema/TestUser", "$defs": { "Bytes": { "type": "string", @@ -225,4 +225,4 @@ "roles", "raw" ] -} \ No newline at end of file +} diff --git a/fixtures/go_comments.json b/fixtures/go_comments.json index 6b3fb29..d8ff631 100644 --- a/fixtures/go_comments.json +++ b/fixtures/go_comments.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/examples/user", + "$id": "https://github.com/invopop/jsonschema/examples/User", "$ref": "#/$defs/User", "$defs": { "NamedPets": { @@ -106,4 +106,4 @@ "description": "User is used as a base to provide tests for comments." } } -} \ No newline at end of file +} diff --git a/fixtures/ignore_type.json b/fixtures/ignore_type.json index 2a08af6..9bdd7df 100644 --- a/fixtures/ignore_type.json +++ b/fixtures/ignore_type.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-user", + "$id": "https://github.com/invopop/jsonschema/TestUser", "$ref": "#/$defs/TestUser", "$defs": { "Bytes": { @@ -221,4 +221,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/inlining_embedded.json b/fixtures/inlining_embedded.json index 630e5f9..e53e55e 100644 --- a/fixtures/inlining_embedded.json +++ b/fixtures/inlining_embedded.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/outer-named", + "$id": "https://github.com/invopop/jsonschema/OuterNamed", "$defs": { "Inner": { "properties": { @@ -28,4 +28,4 @@ "required": [ "inner" ] -} \ No newline at end of file +} diff --git a/fixtures/inlining_embedded_anchored.json b/fixtures/inlining_embedded_anchored.json index 7d0b42c..9e9e791 100644 --- a/fixtures/inlining_embedded_anchored.json +++ b/fixtures/inlining_embedded_anchored.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/outer-named", + "$id": "https://github.com/invopop/jsonschema/OuterNamed", "$anchor": "OuterNamed", "$defs": { "Inner": { @@ -30,4 +30,4 @@ "required": [ "inner" ] -} \ No newline at end of file +} diff --git a/fixtures/inlining_inheritance.json b/fixtures/inlining_inheritance.json index bd01a39..2602431 100644 --- a/fixtures/inlining_inheritance.json +++ b/fixtures/inlining_inheritance.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/outer", + "$id": "https://github.com/invopop/jsonschema/Outer", "properties": { "TextNamed": { "type": "string" @@ -18,4 +18,4 @@ "TextNamed", "Foo" ] -} \ No newline at end of file +} diff --git a/fixtures/inlining_ptr.json b/fixtures/inlining_ptr.json index 9ea4738..bfc5fb8 100644 --- a/fixtures/inlining_ptr.json +++ b/fixtures/inlining_ptr.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/outer-ptr", + "$id": "https://github.com/invopop/jsonschema/OuterPtr", "properties": { "Foo": { "type": "string" @@ -14,4 +14,4 @@ "required": [ "Foo" ] -} \ No newline at end of file +} diff --git a/fixtures/keynamed.json b/fixtures/keynamed.json index 60bd2a7..66bd26c 100644 --- a/fixtures/keynamed.json +++ b/fixtures/keynamed.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/key-named", + "$id": "https://github.com/invopop/jsonschema/KeyNamed", "$ref": "#/$defs/KeyNamed", "$defs": { "KeyNamed": { @@ -49,4 +49,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/lookup.json b/fixtures/lookup.json index 1d52012..469aa96 100644 --- a/fixtures/lookup.json +++ b/fixtures/lookup.json @@ -1,12 +1,12 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schemas/lookup-user", + "$id": "https://example.com/schemas/LookupUser", "$ref": "#/$defs/LookupUser", "$defs": { "LookupUser": { "properties": { "name": { - "$ref": "https://example.com/schemas/lookup-name" + "$ref": "https://example.com/schemas/LookupName" }, "alias": { "type": "string" @@ -19,4 +19,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/lookup_expanded.json b/fixtures/lookup_expanded.json index a9013da..72953b8 100644 --- a/fixtures/lookup_expanded.json +++ b/fixtures/lookup_expanded.json @@ -1,10 +1,10 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schemas/lookup-user", + "$id": "https://example.com/schemas/LookupUser", "$anchor": "LookupUser", "properties": { "name": { - "$ref": "https://example.com/schemas/lookup-name" + "$ref": "https://example.com/schemas/LookupName" }, "alias": { "type": "string" @@ -15,4 +15,4 @@ "required": [ "name" ] -} \ No newline at end of file +} diff --git a/fixtures/map_type.json b/fixtures/map_type.json index 9050c57..c3927b6 100644 --- a/fixtures/map_type.json +++ b/fixtures/map_type.json @@ -1,10 +1,10 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/map-type", + "$id": "https://github.com/invopop/jsonschema/MapType", "$ref": "#/$defs/MapType", "$defs": { "MapType": { "type": "object" } } -} \ No newline at end of file +} diff --git a/fixtures/no_reference.json b/fixtures/no_reference.json index abbe6ec..36aa16a 100644 --- a/fixtures/no_reference.json +++ b/fixtures/no_reference.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-user", + "$id": "https://github.com/invopop/jsonschema/TestUser", "properties": { "id": { "type": "integer" @@ -214,4 +214,4 @@ "roles", "raw" ] -} \ No newline at end of file +} diff --git a/fixtures/no_reference_anchor.json b/fixtures/no_reference_anchor.json index 154c5b2..009c55d 100644 --- a/fixtures/no_reference_anchor.json +++ b/fixtures/no_reference_anchor.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-user", + "$id": "https://github.com/invopop/jsonschema/TestUser", "$anchor": "TestUser", "properties": { "id": { @@ -216,4 +216,4 @@ "roles", "raw" ] -} \ No newline at end of file +} diff --git a/fixtures/nullable.json b/fixtures/nullable.json index 7bad7a9..5c47ab0 100644 --- a/fixtures/nullable.json +++ b/fixtures/nullable.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-nullable", + "$id": "https://github.com/invopop/jsonschema/TestNullable", "$ref": "#/$defs/TestNullable", "$defs": { "TestNullable": { @@ -23,4 +23,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/oneof.json b/fixtures/oneof.json index c1daf0f..3ba5262 100644 --- a/fixtures/oneof.json +++ b/fixtures/oneof.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/root-one-of", + "$id": "https://github.com/invopop/jsonschema/RootOneOf", "$ref": "#/$defs/RootOneOf", "$defs": { "ChildOneOf": { @@ -88,4 +88,4 @@ "type": "object" } } -} \ No newline at end of file +} diff --git a/fixtures/recursive.json b/fixtures/recursive.json index ef1daa2..291f87c 100644 --- a/fixtures/recursive.json +++ b/fixtures/recursive.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/recursive-example", + "$id": "https://github.com/invopop/jsonschema/RecursiveExample", "$ref": "#/$defs/RecursiveExample", "$defs": { "RecursiveExample": { @@ -22,4 +22,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/required_from_jsontags.json b/fixtures/required_from_jsontags.json index 3a41aaa..6b50d8c 100644 --- a/fixtures/required_from_jsontags.json +++ b/fixtures/required_from_jsontags.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-user", + "$id": "https://github.com/invopop/jsonschema/TestUser", "$ref": "#/$defs/TestUser", "$defs": { "Bytes": { @@ -217,4 +217,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/schema_with_expression.json b/fixtures/schema_with_expression.json index dcdb2e1..868f228 100644 --- a/fixtures/schema_with_expression.json +++ b/fixtures/schema_with_expression.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/expression", + "$id": "https://github.com/invopop/jsonschema/Expression", "$ref": "#/$defs/Expression", "$defs": { "Expression": { @@ -17,4 +17,4 @@ ] } } - } \ No newline at end of file + } diff --git a/fixtures/schema_with_minimum.json b/fixtures/schema_with_minimum.json index 50176c4..e75423e 100644 --- a/fixtures/schema_with_minimum.json +++ b/fixtures/schema_with_minimum.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/min-value", + "$id": "https://github.com/invopop/jsonschema/MinValue", "$ref": "#/$defs/MinValue", "$defs": { "MinValue": { @@ -17,4 +17,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/test_description_override.json b/fixtures/test_description_override.json index 21be044..d5db9fe 100644 --- a/fixtures/test_description_override.json +++ b/fixtures/test_description_override.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-description-override", + "$id": "https://github.com/invopop/jsonschema/TestDescriptionOverride", "$ref": "#/$defs/TestDescriptionOverride", "$defs": { "TestDescriptionOverride": { @@ -31,4 +31,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/test_user.json b/fixtures/test_user.json index 8ef1d01..48f1fe1 100644 --- a/fixtures/test_user.json +++ b/fixtures/test_user.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-user", + "$id": "https://github.com/invopop/jsonschema/TestUser", "$ref": "#/$defs/TestUser", "$defs": { "Bytes": { @@ -228,4 +228,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/test_user_assign_anchor.json b/fixtures/test_user_assign_anchor.json index c5e6198..b553353 100644 --- a/fixtures/test_user_assign_anchor.json +++ b/fixtures/test_user_assign_anchor.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-user", + "$id": "https://github.com/invopop/jsonschema/TestUser", "$ref": "#/$defs/TestUser", "$defs": { "Bytes": { @@ -230,4 +230,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/test_yaml_and_json_prefer_yaml.json b/fixtures/test_yaml_and_json_prefer_yaml.json index 77cefa9..13d210c 100644 --- a/fixtures/test_yaml_and_json_prefer_yaml.json +++ b/fixtures/test_yaml_and_json_prefer_yaml.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/test-yaml-and-json", + "$id": "https://github.com/invopop/jsonschema/TestYamlAndJson", "$ref": "#/$defs/TestYamlAndJson", "$defs": { "TestYamlAndJson": { @@ -27,4 +27,4 @@ ] } } -} \ No newline at end of file +} diff --git a/fixtures/user_with_anchor.json b/fixtures/user_with_anchor.json index 0d8994b..b519037 100644 --- a/fixtures/user_with_anchor.json +++ b/fixtures/user_with_anchor.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/user-with-anchor", + "$id": "https://github.com/invopop/jsonschema/UserWithAnchor", "$ref": "#/$defs/UserWithAnchor", "$defs": { "UserWithAnchor": { @@ -17,4 +17,4 @@ ] } } -} \ No newline at end of file +} diff --git a/reflect.go b/reflect.go index 6ebc6be..9867ea0 100644 --- a/reflect.go +++ b/reflect.go @@ -260,7 +260,7 @@ func (r *Reflector) ReflectFromType(t reflect.Type) *Schema { } } if baseSchemaID != EmptyID { - s.ID = baseSchemaID.Add(ToSnakeCase(name)) + s.ID = baseSchemaID.Add(name) } } diff --git a/reflect_test.go b/reflect_test.go index c0d2c9f..124416d 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -346,7 +346,7 @@ func TestReflectFromType(t *testing.T) { typ := reflect.TypeOf(tu) s := r.ReflectFromType(typ) - assert.EqualValues(t, "https://github.com/invopop/jsonschema/test-user", s.ID) + assert.EqualValues(t, "https://github.com/invopop/jsonschema/TestUser", s.ID) x := struct { Test string @@ -391,9 +391,9 @@ func TestSchemaGeneration(t *testing.T) { Lookup: func(i reflect.Type) ID { switch i { case reflect.TypeOf(LookupUser{}): - return ID("https://example.com/schemas/lookup-user") + return ID("https://example.com/schemas/LookupUser") case reflect.TypeOf(LookupName{}): - return ID("https://example.com/schemas/lookup-name") + return ID("https://example.com/schemas/LookupName") } return EmptyID }, @@ -405,9 +405,9 @@ func TestSchemaGeneration(t *testing.T) { Lookup: func(i reflect.Type) ID { switch i { case reflect.TypeOf(LookupUser{}): - return ID("https://example.com/schemas/lookup-user") + return ID("https://example.com/schemas/LookupUser") case reflect.TypeOf(LookupName{}): - return ID("https://example.com/schemas/lookup-name") + return ID("https://example.com/schemas/LookupName") } return EmptyID }, From 2a47f1f1a0ecf0cf306be23ce874a3e73adb12ed Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Wed, 6 Sep 2023 15:17:38 -0400 Subject: [PATCH 2/3] Revert changes Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- examples_test.go | 2 +- fixtures/allow_additional_props.json | 4 ++-- fixtures/anyof.json | 4 ++-- fixtures/array_type.json | 4 ++-- fixtures/base_schema_id.json | 4 ++-- fixtures/commas_in_pattern.json | 4 ++-- fixtures/compact_date.json | 4 ++-- fixtures/custom_additional.json | 4 ++-- fixtures/custom_map_type.json | 4 ++-- fixtures/custom_slice_type.json | 4 ++-- fixtures/custom_type.json | 4 ++-- fixtures/custom_type_extend.json | 4 ++-- fixtures/custom_type_with_interface.json | 4 ++-- fixtures/defaults_expanded_toplevel.json | 4 ++-- fixtures/go_comments.json | 4 ++-- fixtures/ignore_type.json | 4 ++-- fixtures/inlining_embedded.json | 4 ++-- fixtures/inlining_embedded_anchored.json | 4 ++-- fixtures/inlining_inheritance.json | 4 ++-- fixtures/inlining_ptr.json | 4 ++-- fixtures/keynamed.json | 4 ++-- fixtures/lookup.json | 6 +++--- fixtures/lookup_expanded.json | 6 +++--- fixtures/map_type.json | 4 ++-- fixtures/no_reference.json | 4 ++-- fixtures/no_reference_anchor.json | 4 ++-- fixtures/nullable.json | 4 ++-- fixtures/oneof.json | 4 ++-- fixtures/recursive.json | 4 ++-- fixtures/required_from_jsontags.json | 4 ++-- fixtures/schema_with_expression.json | 4 ++-- fixtures/schema_with_minimum.json | 4 ++-- fixtures/test_description_override.json | 4 ++-- fixtures/test_user.json | 4 ++-- fixtures/test_user_assign_anchor.json | 4 ++-- fixtures/test_yaml_and_json_prefer_yaml.json | 4 ++-- fixtures/user_with_anchor.json | 4 ++-- reflect.go | 10 +++++++++- reflect_test.go | 10 +++++----- 39 files changed, 89 insertions(+), 81 deletions(-) diff --git a/examples_test.go b/examples_test.go index c4bd62d..82cae05 100644 --- a/examples_test.go +++ b/examples_test.go @@ -29,7 +29,7 @@ func ExampleReflect() { // Output: // { // "$schema": "https://json-schema.org/draft/2020-12/schema", - // "$id": "https://github.com/invopop/jsonschema_test/SampleUser", + // "$id": "https://github.com/invopop/jsonschema_test/sample-user", // "$ref": "#/$defs/SampleUser", // "$defs": { // "SampleUser": { diff --git a/fixtures/allow_additional_props.json b/fixtures/allow_additional_props.json index b23fe7a..a2fe8d1 100644 --- a/fixtures/allow_additional_props.json +++ b/fixtures/allow_additional_props.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestUser", + "$id": "https://github.com/invopop/jsonschema/test-user", "$ref": "#/$defs/TestUser", "$defs": { "Bytes": { @@ -226,4 +226,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/anyof.json b/fixtures/anyof.json index 2fbb1a3..8b3d4fe 100644 --- a/fixtures/anyof.json +++ b/fixtures/anyof.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/RootAnyOf", + "$id": "https://github.com/invopop/jsonschema/root-any-of", "$ref": "#/$defs/RootAnyOf", "$defs": { "ChildAnyOf": { @@ -88,4 +88,4 @@ "type": "object" } } -} +} \ No newline at end of file diff --git a/fixtures/array_type.json b/fixtures/array_type.json index f17eee1..a574591 100644 --- a/fixtures/array_type.json +++ b/fixtures/array_type.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/ArrayType", + "$id": "https://github.com/invopop/jsonschema/array-type", "$ref": "#/$defs/ArrayType", "$defs": { "ArrayType": { @@ -10,4 +10,4 @@ "type": "array" } } -} +} \ No newline at end of file diff --git a/fixtures/base_schema_id.json b/fixtures/base_schema_id.json index f6c6786..7c52f31 100644 --- a/fixtures/base_schema_id.json +++ b/fixtures/base_schema_id.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schemas/LookupUser", + "$id": "https://example.com/schemas/lookup-user", "$ref": "#/$defs/LookupUser", "$defs": { "LookupName": { @@ -35,4 +35,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/commas_in_pattern.json b/fixtures/commas_in_pattern.json index 8d54847..a2f950c 100644 --- a/fixtures/commas_in_pattern.json +++ b/fixtures/commas_in_pattern.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/PatternTest", + "$id": "https://github.com/invopop/jsonschema/pattern-test", "$ref": "#/$defs/PatternTest", "$defs": { "PatternTest": { @@ -19,4 +19,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/compact_date.json b/fixtures/compact_date.json index 4bcfd9f..927472e 100644 --- a/fixtures/compact_date.json +++ b/fixtures/compact_date.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/CompactDate", + "$id": "https://github.com/invopop/jsonschema/compact-date", "$ref": "#/$defs/CompactDate", "$defs": { "CompactDate": { @@ -10,4 +10,4 @@ "description": "Short date that only includes year and month" } } -} +} \ No newline at end of file diff --git a/fixtures/custom_additional.json b/fixtures/custom_additional.json index b4daa5b..4dc7992 100644 --- a/fixtures/custom_additional.json +++ b/fixtures/custom_additional.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/GrandfatherType", + "$id": "https://github.com/invopop/jsonschema/grandfather-type", "$ref": "#/$defs/GrandfatherType", "$defs": { "GrandfatherType": { @@ -21,4 +21,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/custom_map_type.json b/fixtures/custom_map_type.json index e06db66..379efe2 100644 --- a/fixtures/custom_map_type.json +++ b/fixtures/custom_map_type.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/CustomMapOuter", + "$id": "https://github.com/invopop/jsonschema/custom-map-outer", "$ref": "#/$defs/CustomMapOuter", "$defs": { "CustomMapOuter": { @@ -34,4 +34,4 @@ "type": "array" } } -} +} \ No newline at end of file diff --git a/fixtures/custom_slice_type.json b/fixtures/custom_slice_type.json index 665f4f5..6e5cb71 100644 --- a/fixtures/custom_slice_type.json +++ b/fixtures/custom_slice_type.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/CustomSliceOuter", + "$id": "https://github.com/invopop/jsonschema/custom-slice-outer", "$ref": "#/$defs/CustomSliceOuter", "$defs": { "CustomSliceOuter": { @@ -29,4 +29,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/custom_type.json b/fixtures/custom_type.json index da453f0..0cc5bab 100644 --- a/fixtures/custom_type.json +++ b/fixtures/custom_type.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/CustomTypeField", + "$id": "https://github.com/invopop/jsonschema/custom-type-field", "$ref": "#/$defs/CustomTypeField", "$defs": { "CustomTypeField": { @@ -17,4 +17,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/custom_type_extend.json b/fixtures/custom_type_extend.json index fe4af42..a1dc9d4 100644 --- a/fixtures/custom_type_extend.json +++ b/fixtures/custom_type_extend.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/SchemaExtendTest", + "$id": "https://github.com/invopop/jsonschema/schema-extend-test", "$ref": "#/$defs/SchemaExtendTest", "$defs": { "SchemaExtendTest": { @@ -20,4 +20,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/custom_type_with_interface.json b/fixtures/custom_type_with_interface.json index d1a768b..0e4c53d 100644 --- a/fixtures/custom_type_with_interface.json +++ b/fixtures/custom_type_with_interface.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/CustomTypeFieldWithInterface", + "$id": "https://github.com/invopop/jsonschema/custom-type-field-with-interface", "$ref": "#/$defs/CustomTypeFieldWithInterface", "$defs": { "CustomTimeWithInterface": { @@ -20,4 +20,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/defaults_expanded_toplevel.json b/fixtures/defaults_expanded_toplevel.json index e56e41b..c57ca8f 100644 --- a/fixtures/defaults_expanded_toplevel.json +++ b/fixtures/defaults_expanded_toplevel.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestUser", + "$id": "https://github.com/invopop/jsonschema/test-user", "$defs": { "Bytes": { "type": "string", @@ -225,4 +225,4 @@ "roles", "raw" ] -} +} \ No newline at end of file diff --git a/fixtures/go_comments.json b/fixtures/go_comments.json index d8ff631..6b3fb29 100644 --- a/fixtures/go_comments.json +++ b/fixtures/go_comments.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/examples/User", + "$id": "https://github.com/invopop/jsonschema/examples/user", "$ref": "#/$defs/User", "$defs": { "NamedPets": { @@ -106,4 +106,4 @@ "description": "User is used as a base to provide tests for comments." } } -} +} \ No newline at end of file diff --git a/fixtures/ignore_type.json b/fixtures/ignore_type.json index 9bdd7df..2a08af6 100644 --- a/fixtures/ignore_type.json +++ b/fixtures/ignore_type.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestUser", + "$id": "https://github.com/invopop/jsonschema/test-user", "$ref": "#/$defs/TestUser", "$defs": { "Bytes": { @@ -221,4 +221,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/inlining_embedded.json b/fixtures/inlining_embedded.json index e53e55e..630e5f9 100644 --- a/fixtures/inlining_embedded.json +++ b/fixtures/inlining_embedded.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/OuterNamed", + "$id": "https://github.com/invopop/jsonschema/outer-named", "$defs": { "Inner": { "properties": { @@ -28,4 +28,4 @@ "required": [ "inner" ] -} +} \ No newline at end of file diff --git a/fixtures/inlining_embedded_anchored.json b/fixtures/inlining_embedded_anchored.json index 9e9e791..7d0b42c 100644 --- a/fixtures/inlining_embedded_anchored.json +++ b/fixtures/inlining_embedded_anchored.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/OuterNamed", + "$id": "https://github.com/invopop/jsonschema/outer-named", "$anchor": "OuterNamed", "$defs": { "Inner": { @@ -30,4 +30,4 @@ "required": [ "inner" ] -} +} \ No newline at end of file diff --git a/fixtures/inlining_inheritance.json b/fixtures/inlining_inheritance.json index 2602431..bd01a39 100644 --- a/fixtures/inlining_inheritance.json +++ b/fixtures/inlining_inheritance.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/Outer", + "$id": "https://github.com/invopop/jsonschema/outer", "properties": { "TextNamed": { "type": "string" @@ -18,4 +18,4 @@ "TextNamed", "Foo" ] -} +} \ No newline at end of file diff --git a/fixtures/inlining_ptr.json b/fixtures/inlining_ptr.json index bfc5fb8..9ea4738 100644 --- a/fixtures/inlining_ptr.json +++ b/fixtures/inlining_ptr.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/OuterPtr", + "$id": "https://github.com/invopop/jsonschema/outer-ptr", "properties": { "Foo": { "type": "string" @@ -14,4 +14,4 @@ "required": [ "Foo" ] -} +} \ No newline at end of file diff --git a/fixtures/keynamed.json b/fixtures/keynamed.json index 66bd26c..60bd2a7 100644 --- a/fixtures/keynamed.json +++ b/fixtures/keynamed.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/KeyNamed", + "$id": "https://github.com/invopop/jsonschema/key-named", "$ref": "#/$defs/KeyNamed", "$defs": { "KeyNamed": { @@ -49,4 +49,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/lookup.json b/fixtures/lookup.json index 469aa96..1d52012 100644 --- a/fixtures/lookup.json +++ b/fixtures/lookup.json @@ -1,12 +1,12 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schemas/LookupUser", + "$id": "https://example.com/schemas/lookup-user", "$ref": "#/$defs/LookupUser", "$defs": { "LookupUser": { "properties": { "name": { - "$ref": "https://example.com/schemas/LookupName" + "$ref": "https://example.com/schemas/lookup-name" }, "alias": { "type": "string" @@ -19,4 +19,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/lookup_expanded.json b/fixtures/lookup_expanded.json index 72953b8..a9013da 100644 --- a/fixtures/lookup_expanded.json +++ b/fixtures/lookup_expanded.json @@ -1,10 +1,10 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schemas/LookupUser", + "$id": "https://example.com/schemas/lookup-user", "$anchor": "LookupUser", "properties": { "name": { - "$ref": "https://example.com/schemas/LookupName" + "$ref": "https://example.com/schemas/lookup-name" }, "alias": { "type": "string" @@ -15,4 +15,4 @@ "required": [ "name" ] -} +} \ No newline at end of file diff --git a/fixtures/map_type.json b/fixtures/map_type.json index c3927b6..9050c57 100644 --- a/fixtures/map_type.json +++ b/fixtures/map_type.json @@ -1,10 +1,10 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/MapType", + "$id": "https://github.com/invopop/jsonschema/map-type", "$ref": "#/$defs/MapType", "$defs": { "MapType": { "type": "object" } } -} +} \ No newline at end of file diff --git a/fixtures/no_reference.json b/fixtures/no_reference.json index 36aa16a..abbe6ec 100644 --- a/fixtures/no_reference.json +++ b/fixtures/no_reference.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestUser", + "$id": "https://github.com/invopop/jsonschema/test-user", "properties": { "id": { "type": "integer" @@ -214,4 +214,4 @@ "roles", "raw" ] -} +} \ No newline at end of file diff --git a/fixtures/no_reference_anchor.json b/fixtures/no_reference_anchor.json index 009c55d..154c5b2 100644 --- a/fixtures/no_reference_anchor.json +++ b/fixtures/no_reference_anchor.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestUser", + "$id": "https://github.com/invopop/jsonschema/test-user", "$anchor": "TestUser", "properties": { "id": { @@ -216,4 +216,4 @@ "roles", "raw" ] -} +} \ No newline at end of file diff --git a/fixtures/nullable.json b/fixtures/nullable.json index 5c47ab0..7bad7a9 100644 --- a/fixtures/nullable.json +++ b/fixtures/nullable.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestNullable", + "$id": "https://github.com/invopop/jsonschema/test-nullable", "$ref": "#/$defs/TestNullable", "$defs": { "TestNullable": { @@ -23,4 +23,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/oneof.json b/fixtures/oneof.json index 3ba5262..c1daf0f 100644 --- a/fixtures/oneof.json +++ b/fixtures/oneof.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/RootOneOf", + "$id": "https://github.com/invopop/jsonschema/root-one-of", "$ref": "#/$defs/RootOneOf", "$defs": { "ChildOneOf": { @@ -88,4 +88,4 @@ "type": "object" } } -} +} \ No newline at end of file diff --git a/fixtures/recursive.json b/fixtures/recursive.json index 291f87c..ef1daa2 100644 --- a/fixtures/recursive.json +++ b/fixtures/recursive.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/RecursiveExample", + "$id": "https://github.com/invopop/jsonschema/recursive-example", "$ref": "#/$defs/RecursiveExample", "$defs": { "RecursiveExample": { @@ -22,4 +22,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/required_from_jsontags.json b/fixtures/required_from_jsontags.json index 6b50d8c..3a41aaa 100644 --- a/fixtures/required_from_jsontags.json +++ b/fixtures/required_from_jsontags.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestUser", + "$id": "https://github.com/invopop/jsonschema/test-user", "$ref": "#/$defs/TestUser", "$defs": { "Bytes": { @@ -217,4 +217,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/schema_with_expression.json b/fixtures/schema_with_expression.json index 868f228..dcdb2e1 100644 --- a/fixtures/schema_with_expression.json +++ b/fixtures/schema_with_expression.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/Expression", + "$id": "https://github.com/invopop/jsonschema/expression", "$ref": "#/$defs/Expression", "$defs": { "Expression": { @@ -17,4 +17,4 @@ ] } } - } + } \ No newline at end of file diff --git a/fixtures/schema_with_minimum.json b/fixtures/schema_with_minimum.json index e75423e..50176c4 100644 --- a/fixtures/schema_with_minimum.json +++ b/fixtures/schema_with_minimum.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/MinValue", + "$id": "https://github.com/invopop/jsonschema/min-value", "$ref": "#/$defs/MinValue", "$defs": { "MinValue": { @@ -17,4 +17,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/test_description_override.json b/fixtures/test_description_override.json index d5db9fe..21be044 100644 --- a/fixtures/test_description_override.json +++ b/fixtures/test_description_override.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestDescriptionOverride", + "$id": "https://github.com/invopop/jsonschema/test-description-override", "$ref": "#/$defs/TestDescriptionOverride", "$defs": { "TestDescriptionOverride": { @@ -31,4 +31,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/test_user.json b/fixtures/test_user.json index 48f1fe1..8ef1d01 100644 --- a/fixtures/test_user.json +++ b/fixtures/test_user.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestUser", + "$id": "https://github.com/invopop/jsonschema/test-user", "$ref": "#/$defs/TestUser", "$defs": { "Bytes": { @@ -228,4 +228,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/test_user_assign_anchor.json b/fixtures/test_user_assign_anchor.json index b553353..c5e6198 100644 --- a/fixtures/test_user_assign_anchor.json +++ b/fixtures/test_user_assign_anchor.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestUser", + "$id": "https://github.com/invopop/jsonschema/test-user", "$ref": "#/$defs/TestUser", "$defs": { "Bytes": { @@ -230,4 +230,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/test_yaml_and_json_prefer_yaml.json b/fixtures/test_yaml_and_json_prefer_yaml.json index 13d210c..77cefa9 100644 --- a/fixtures/test_yaml_and_json_prefer_yaml.json +++ b/fixtures/test_yaml_and_json_prefer_yaml.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/TestYamlAndJson", + "$id": "https://github.com/invopop/jsonschema/test-yaml-and-json", "$ref": "#/$defs/TestYamlAndJson", "$defs": { "TestYamlAndJson": { @@ -27,4 +27,4 @@ ] } } -} +} \ No newline at end of file diff --git a/fixtures/user_with_anchor.json b/fixtures/user_with_anchor.json index b519037..0d8994b 100644 --- a/fixtures/user_with_anchor.json +++ b/fixtures/user_with_anchor.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/invopop/jsonschema/UserWithAnchor", + "$id": "https://github.com/invopop/jsonschema/user-with-anchor", "$ref": "#/$defs/UserWithAnchor", "$defs": { "UserWithAnchor": { @@ -17,4 +17,4 @@ ] } } -} +} \ No newline at end of file diff --git a/reflect.go b/reflect.go index 9867ea0..f8ddfad 100644 --- a/reflect.go +++ b/reflect.go @@ -149,6 +149,10 @@ type Reflector struct { // include a schema ID. BaseSchemaID ID + // UseCamelCaseForIDs determines if missing IDs will use CamelCase (e.g. `TestUser`) + // or the default snake-case (e.g. `test-user`) when creating the BaseSchemaID. + UseCamelCaseForIDs bool + // Anonymous when true will hide the auto-generated Schema ID and provide what is // known as an "anonymous schema". As a rule, this is not recommended. Anonymous bool @@ -260,7 +264,11 @@ func (r *Reflector) ReflectFromType(t reflect.Type) *Schema { } } if baseSchemaID != EmptyID { - s.ID = baseSchemaID.Add(name) + if r.UseCamelCaseForIDs { + s.ID = baseSchemaID.Add(name) + } else { + s.ID = baseSchemaID.Add(ToSnakeCase(name)) + } } } diff --git a/reflect_test.go b/reflect_test.go index 124416d..c0d2c9f 100644 --- a/reflect_test.go +++ b/reflect_test.go @@ -346,7 +346,7 @@ func TestReflectFromType(t *testing.T) { typ := reflect.TypeOf(tu) s := r.ReflectFromType(typ) - assert.EqualValues(t, "https://github.com/invopop/jsonschema/TestUser", s.ID) + assert.EqualValues(t, "https://github.com/invopop/jsonschema/test-user", s.ID) x := struct { Test string @@ -391,9 +391,9 @@ func TestSchemaGeneration(t *testing.T) { Lookup: func(i reflect.Type) ID { switch i { case reflect.TypeOf(LookupUser{}): - return ID("https://example.com/schemas/LookupUser") + return ID("https://example.com/schemas/lookup-user") case reflect.TypeOf(LookupName{}): - return ID("https://example.com/schemas/LookupName") + return ID("https://example.com/schemas/lookup-name") } return EmptyID }, @@ -405,9 +405,9 @@ func TestSchemaGeneration(t *testing.T) { Lookup: func(i reflect.Type) ID { switch i { case reflect.TypeOf(LookupUser{}): - return ID("https://example.com/schemas/LookupUser") + return ID("https://example.com/schemas/lookup-user") case reflect.TypeOf(LookupName{}): - return ID("https://example.com/schemas/LookupName") + return ID("https://example.com/schemas/lookup-name") } return EmptyID }, From e390ead894939c9ba6ea0556f4cc231e5420e1be Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:00:48 -0400 Subject: [PATCH 3/3] Address review feedback Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- reflect.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/reflect.go b/reflect.go index f8ddfad..5644ed2 100644 --- a/reflect.go +++ b/reflect.go @@ -149,9 +149,11 @@ type Reflector struct { // include a schema ID. BaseSchemaID ID - // UseCamelCaseForIDs determines if missing IDs will use CamelCase (e.g. `TestUser`) - // or the default snake-case (e.g. `test-user`) when creating the BaseSchemaID. - UseCamelCaseForIDs bool + // SchemaIDNameFormatter optionally formats the names of missing IDs. + // If nil, ToSnakeCase will be used (e.g. `test-user`). + // Providing the identity function: func(id string) string { return id } + // will result in CamelCase (e.g. `TestUser`) IDs. + SchemaIDNameFormatter func(id string) string // Anonymous when true will hide the auto-generated Schema ID and provide what is // known as an "anonymous schema". As a rule, this is not recommended. @@ -264,8 +266,8 @@ func (r *Reflector) ReflectFromType(t reflect.Type) *Schema { } } if baseSchemaID != EmptyID { - if r.UseCamelCaseForIDs { - s.ID = baseSchemaID.Add(name) + if r.SchemaIDNameFormatter != nil { + s.ID = baseSchemaID.Add(r.SchemaIDNameFormatter(name)) } else { s.ID = baseSchemaID.Add(ToSnakeCase(name)) }