From b3ef84bd8d988af30980d9dac46f981fe9036747 Mon Sep 17 00:00:00 2001 From: Dan Fellin Date: Thu, 7 Mar 2024 10:20:06 -0800 Subject: [PATCH 1/6] add custom_get_name_method --- .gitignore | 1 + jsonschema_gentypes/api.py | 28 ++++++++-- jsonschema_gentypes/api_draft_04.py | 12 ++--- jsonschema_gentypes/configuration.py | 20 ++++++- tests/custom_get_name.json | 25 +++++++++ tests/custom_get_name.py | 22 ++++++++ tests/test_custom_get_name.py | 78 ++++++++++++++++++++++++++++ 7 files changed, 175 insertions(+), 11 deletions(-) create mode 100644 tests/custom_get_name.json create mode 100644 tests/custom_get_name.py create mode 100644 tests/test_custom_get_name.py diff --git a/.gitignore b/.gitignore index c66b14ea..7e48cb67 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__ /dist /.github/changelog-generator-cache /tests/recursion.py +/.vscode diff --git a/jsonschema_gentypes/api.py b/jsonschema_gentypes/api.py index 04cebb2f..84c062b6 100644 --- a/jsonschema_gentypes/api.py +++ b/jsonschema_gentypes/api.py @@ -53,12 +53,14 @@ def __init__( self, resolver: RefResolver, additional_properties: configuration.AdditionalProperties = configuration.ADDITIONALPROPERTIES_ONLY_EXPLICIT, + custom_get_name: Optional[configuration.GetNameFunction] = None, ) -> None: """ Initialize with a resolver. """ self.resolver = resolver self.additional_properties = additional_properties + self.custom_get_name: Optional[configuration.GetNameFunction] = custom_get_name # types by reference self.ref_type: dict[str, Type] = {} self.root: Optional[TypeProxy] = None @@ -170,13 +172,15 @@ def get_type( if description: if not isinstance(the_type, NamedType): if auto_alias: - the_type = TypeAlias(get_name(schema_meta_data, proposed_name), the_type, description) + the_type = TypeAlias( + self.get_name(schema_meta_data, proposed_name), the_type, description + ) the_type.set_comments(description) if "default" in schema_meta_data: the_type.add_depends_on( Constant( - f"{get_name(schema_meta_data, proposed_name, True)}_DEFAULT", + f"{self.get_name(schema_meta_data, proposed_name, True)}_DEFAULT", schema_meta_data["default"], [f"Default value of the field path '{proposed_name}'"], ) @@ -191,6 +195,22 @@ def get_type( return the_type + def get_name( + self, + schema: Optional[ + Union[ + jsonschema_draft_04.JSONSchemaD4, + jsonschema_draft_2019_09_meta_data.JSONSchemaItemD2019, + ] + ], + proposed_name: Optional[str] = None, + upper: bool = False, + ) -> str: + if self.custom_get_name: + return self.custom_get_name(schema, proposed_name, upper) + else: + return get_name(schema, proposed_name, upper) + def resolve_ref( self, schema: Union[ @@ -342,7 +362,7 @@ def build_type( "anyof", ) if not isinstance(type_, NamedType): - type_ = TypeAlias(get_name(schema_meta_data, proposed_name), type_) + type_ = TypeAlias(self.get_name(schema_meta_data, proposed_name), type_) elif type_.comments(): type_.comments().append("") type_.comments().append("Aggregation type: anyOf") @@ -394,7 +414,7 @@ def build_type( if len(schema_type) == 0: return BuiltinType("None") inner_types = [] - name = get_name(schema_meta_data, proposed_name) + name = self.get_name(schema_meta_data, proposed_name) has_title = "title" in schema_meta_data proposed_name = schema_meta_data.get("title", proposed_name) diff --git a/jsonschema_gentypes/api_draft_04.py b/jsonschema_gentypes/api_draft_04.py index 576a86d9..25662627 100644 --- a/jsonschema_gentypes/api_draft_04.py +++ b/jsonschema_gentypes/api_draft_04.py @@ -55,7 +55,7 @@ def enum( ) return TypeEnum( - get_name(schema_meta_data, proposed_name), + self.get_name(schema_meta_data, proposed_name), cast(list[Union[int, float, bool, str, None]], schema["enum"]), get_description(schema_meta_data), ) @@ -99,7 +99,7 @@ def object( ) std_dict = None - name = get_name(schema_meta_data, proposed_name) + name = self.get_name(schema_meta_data, proposed_name) schema.setdefault("used", set()).add("additionalProperties") # type: ignore[typeddict-item] additional_properties = cast( Union[jsonschema_draft_04.JSONSchemaD4, jsonschema_draft_2020_12_applicator.JSONSchemaD2020], @@ -294,7 +294,7 @@ def any_of( ) if not isinstance(type_, NamedType): type_ = TypeAlias( - get_name(combined_schema_meta_data, proposed_name + " " + sub_name), type_, [] + self.get_name(combined_schema_meta_data, proposed_name + " " + sub_name), type_, [] ) additional_types.append(type_) @@ -326,7 +326,7 @@ def any_of( ) if not isinstance(type_, NamedType): type_ = TypeAlias( - get_name(combined_schema_meta_data, proposed_name + " " + sub_name), type_, [] + self.get_name(combined_schema_meta_data, proposed_name + " " + sub_name), type_, [] ) additional_types.append(type_) inner_types.append(type_) @@ -495,7 +495,7 @@ def all_of( ) if not isinstance(type_, NamedType): type_ = TypeAlias( - get_name(combined_schema_meta_data, f"{proposed_name} {sub_name}{index}"), + self.get_name(combined_schema_meta_data, f"{proposed_name} {sub_name}{index}"), type_, [], ) @@ -522,7 +522,7 @@ def all_of( ) if not isinstance(type_, NamedType): type_ = TypeAlias( - get_name(combined_schema_meta_data, f"{proposed_name} {sub_name}{index}"), + self.get_name(combined_schema_meta_data, f"{proposed_name} {sub_name}{index}"), type_, [], ) diff --git a/jsonschema_gentypes/configuration.py b/jsonschema_gentypes/configuration.py index 161a9c73..ae6e179c 100644 --- a/jsonschema_gentypes/configuration.py +++ b/jsonschema_gentypes/configuration.py @@ -2,10 +2,12 @@ Automatically generated file from a JSON schema. """ -from typing import Any, Literal, TypedDict, Union +from typing import Any, Callable, Literal, Optional, TypedDict, Union from typing_extensions import Required +from jsonschema_gentypes import jsonschema_draft_04, jsonschema_draft_2019_09_meta_data + AdditionalProperties = Union[Literal["Always"], Literal["Only explicit"]] """ Additional properties. @@ -18,6 +20,21 @@ """The values for the 'Additional properties' enum""" +GetNameFunction = Callable[ + [ + Optional[ + Union[ + jsonschema_draft_04.JSONSchemaD4, + jsonschema_draft_2019_09_meta_data.JSONSchemaItemD2019, + ] + ], + Optional[str], + bool, + ], + str, +] + + class ApiArguments(TypedDict, total=False): """ API arguments. @@ -26,6 +43,7 @@ class ApiArguments(TypedDict, total=False): """ additional_properties: "AdditionalProperties" + custom_get_name: GetNameFunction """ Additional properties. diff --git a/tests/custom_get_name.json b/tests/custom_get_name.json new file mode 100644 index 00000000..9a2c3842 --- /dev/null +++ b/tests/custom_get_name.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "SubresourceUris": { + "type": "object", + "properties": { + "feedback": { + "type": "string" + } + }, + "required": ["feedback"], + "title": "SubresourceUris" + } + }, + "type": "object", + "properties": { + "subresource_uris": { + "$ref": "#/definitions/SubresourceUris" + } + }, + "required": [ + "subresource_uris" + ], + "title": "ResponseType" +} \ No newline at end of file diff --git a/tests/custom_get_name.py b/tests/custom_get_name.py new file mode 100644 index 00000000..12979de2 --- /dev/null +++ b/tests/custom_get_name.py @@ -0,0 +1,22 @@ +from typing import TypedDict +from typing_extensions import Required + + +class ResponseType(TypedDict, total=False): + """ ResponseType. """ + + subresource_uris: Required["SubresourceUris"] + """ + SubresourceUris. + + Required property + """ + + + +class SubresourceUris(TypedDict, total=False): + """ SubresourceUris. """ + + feedback: Required[str] + """ Required property """ + diff --git a/tests/test_custom_get_name.py b/tests/test_custom_get_name.py new file mode 100644 index 00000000..8dd8c4fa --- /dev/null +++ b/tests/test_custom_get_name.py @@ -0,0 +1,78 @@ +from typing import Callable, Optional, Union +from jsonschema_gentypes import jsonschema_draft_04, jsonschema_draft_2019_09_meta_data, normalize +from jsonschema_gentypes.cli import process_config +from jsonschema_gentypes.configuration import Configuration + + +GetNameFunction = Callable[ + [ + Optional[ + Union[ + jsonschema_draft_04.JSONSchemaD4, + jsonschema_draft_2019_09_meta_data.JSONSchemaItemD2019, + ] + ], + Optional[str], + bool, + ], + str, +] + + +def custom_get_name( + schema: Optional[ + Union[ + jsonschema_draft_04.JSONSchemaD4, + jsonschema_draft_2019_09_meta_data.JSONSchemaItemD2019, + ] + ], + proposed_name: Optional[str] = None, + upper: bool = False, +) -> str: + """ + Custom get the name for an element. + + Just capitalize first Letter, don't do `.title` + + Parameter: + schema: the concerned schema + proposed_name: a name that we will use it the schema hasn't any title + upper: should we use an upper case (For constants) + """ + # Get the base name + has_title = isinstance(schema, dict) and "title" in schema + name = schema["title"] if has_title else proposed_name # type: ignore + assert name is not None + name = normalize(name) + + prefix = "" if has_title else "_" + if upper: + # Upper case + name = name.upper() + # Remove spaces + return prefix + "".join(["_" if char.isspace() else char for char in name]) + else: + # Title case + name = name[0].upper() + name[1:] + # Remove spaces + return prefix + "".join([char for char in name if not char.isspace()]) + + +def test_empty_array() -> None: + config: Configuration = Configuration( + generate=[ + { + "source": "tests/custom_get_name.json", + "destination": "tests/custom_get_name.py", + "api_arguments": {"custom_get_name": custom_get_name}, + } + ], + ) + process_config( + config, + ["tests/custom_get_name.json"], + ) + + with open("tests/custom_get_name.py", "r") as f: + content = f.read() + assert "class SubresourceUris" in content \ No newline at end of file From 73f25b4823aad3011b2a8221dc4bc4d414bb9cd4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Mar 2024 20:43:40 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- jsonschema_gentypes/api_draft_04.py | 8 ++++++-- tests/custom_get_name.json | 6 ++---- tests/custom_get_name.py | 7 +++---- tests/test_custom_get_name.py | 6 +++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/jsonschema_gentypes/api_draft_04.py b/jsonschema_gentypes/api_draft_04.py index 25662627..fa1355d9 100644 --- a/jsonschema_gentypes/api_draft_04.py +++ b/jsonschema_gentypes/api_draft_04.py @@ -294,7 +294,9 @@ def any_of( ) if not isinstance(type_, NamedType): type_ = TypeAlias( - self.get_name(combined_schema_meta_data, proposed_name + " " + sub_name), type_, [] + self.get_name(combined_schema_meta_data, proposed_name + " " + sub_name), + type_, + [], ) additional_types.append(type_) @@ -326,7 +328,9 @@ def any_of( ) if not isinstance(type_, NamedType): type_ = TypeAlias( - self.get_name(combined_schema_meta_data, proposed_name + " " + sub_name), type_, [] + self.get_name(combined_schema_meta_data, proposed_name + " " + sub_name), + type_, + [], ) additional_types.append(type_) inner_types.append(type_) diff --git a/tests/custom_get_name.json b/tests/custom_get_name.json index 9a2c3842..cc9df7bf 100644 --- a/tests/custom_get_name.json +++ b/tests/custom_get_name.json @@ -18,8 +18,6 @@ "$ref": "#/definitions/SubresourceUris" } }, - "required": [ - "subresource_uris" - ], + "required": ["subresource_uris"], "title": "ResponseType" -} \ No newline at end of file +} diff --git a/tests/custom_get_name.py b/tests/custom_get_name.py index 12979de2..c8ba70d9 100644 --- a/tests/custom_get_name.py +++ b/tests/custom_get_name.py @@ -1,9 +1,10 @@ from typing import TypedDict + from typing_extensions import Required class ResponseType(TypedDict, total=False): - """ ResponseType. """ + """ResponseType.""" subresource_uris: Required["SubresourceUris"] """ @@ -13,10 +14,8 @@ class ResponseType(TypedDict, total=False): """ - class SubresourceUris(TypedDict, total=False): - """ SubresourceUris. """ + """SubresourceUris.""" feedback: Required[str] """ Required property """ - diff --git a/tests/test_custom_get_name.py b/tests/test_custom_get_name.py index 8dd8c4fa..9a897b82 100644 --- a/tests/test_custom_get_name.py +++ b/tests/test_custom_get_name.py @@ -1,9 +1,9 @@ from typing import Callable, Optional, Union + from jsonschema_gentypes import jsonschema_draft_04, jsonschema_draft_2019_09_meta_data, normalize from jsonschema_gentypes.cli import process_config from jsonschema_gentypes.configuration import Configuration - GetNameFunction = Callable[ [ Optional[ @@ -73,6 +73,6 @@ def test_empty_array() -> None: ["tests/custom_get_name.json"], ) - with open("tests/custom_get_name.py", "r") as f: + with open("tests/custom_get_name.py") as f: content = f.read() - assert "class SubresourceUris" in content \ No newline at end of file + assert "class SubresourceUris" in content From 373674913678587dfd835c933f35c33b7d92527a Mon Sep 17 00:00:00 2001 From: Dan Fellin Date: Fri, 8 Mar 2024 07:22:49 -0800 Subject: [PATCH 3/6] fixes from PR comments --- .gitignore | 1 - tests/test_custom_get_name.py | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/.gitignore b/.gitignore index 7e48cb67..c66b14ea 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,3 @@ __pycache__ /dist /.github/changelog-generator-cache /tests/recursion.py -/.vscode diff --git a/tests/test_custom_get_name.py b/tests/test_custom_get_name.py index 9a897b82..43db1e82 100644 --- a/tests/test_custom_get_name.py +++ b/tests/test_custom_get_name.py @@ -4,20 +4,6 @@ from jsonschema_gentypes.cli import process_config from jsonschema_gentypes.configuration import Configuration -GetNameFunction = Callable[ - [ - Optional[ - Union[ - jsonschema_draft_04.JSONSchemaD4, - jsonschema_draft_2019_09_meta_data.JSONSchemaItemD2019, - ] - ], - Optional[str], - bool, - ], - str, -] - def custom_get_name( schema: Optional[ From 7c7fe0d6f5539c13334580762bfacef292c6edba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:23:40 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_custom_get_name.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_custom_get_name.py b/tests/test_custom_get_name.py index 43db1e82..45216453 100644 --- a/tests/test_custom_get_name.py +++ b/tests/test_custom_get_name.py @@ -1,4 +1,4 @@ -from typing import Callable, Optional, Union +from typing import Optional, Union from jsonschema_gentypes import jsonschema_draft_04, jsonschema_draft_2019_09_meta_data, normalize from jsonschema_gentypes.cli import process_config From 46376146a7c21a988b23574c30ba2bb01cb9f817 Mon Sep 17 00:00:00 2001 From: Dan Fellin Date: Mon, 20 May 2024 08:31:55 -0700 Subject: [PATCH 5/6] onward --- jsonschema_gentypes/__init__.py | 6 ++ jsonschema_gentypes/api.py | 9 +-- jsonschema_gentypes/configuration.py | 39 +++++------ jsonschema_gentypes/schema.json | 6 ++ ...get_name.json => get_name_properties.json} | 0 ...tom_get_name.py => get_name_properties.py} | 0 tests/test_custom_get_name.py | 64 ------------------- tests/test_get_name_properties.py | 22 +++++++ 8 files changed, 57 insertions(+), 89 deletions(-) rename tests/{custom_get_name.json => get_name_properties.json} (100%) rename tests/{custom_get_name.py => get_name_properties.py} (100%) delete mode 100644 tests/test_custom_get_name.py create mode 100644 tests/test_get_name_properties.py diff --git a/jsonschema_gentypes/__init__.py b/jsonschema_gentypes/__init__.py index 7a007adc..2dd26b78 100644 --- a/jsonschema_gentypes/__init__.py +++ b/jsonschema_gentypes/__init__.py @@ -673,6 +673,7 @@ def get_name( ], proposed_name: Optional[str] = None, upper: bool = False, + get_name_properties: Optional[str] = None, ) -> str: """ Get the name for an element. @@ -694,6 +695,11 @@ def get_name( name = name.upper() # Remove spaces return prefix + "".join(["_" if char.isspace() else char for char in name]) + elif get_name_properties == "UpperFirst": + # Change just the first letter to upper case + name = name[0].upper() + name[1:] + # Remove spaces + return prefix + "".join([char for char in name if not char.isspace()]) else: # Title case name = name.title() diff --git a/jsonschema_gentypes/api.py b/jsonschema_gentypes/api.py index 84c062b6..2ab6080c 100644 --- a/jsonschema_gentypes/api.py +++ b/jsonschema_gentypes/api.py @@ -53,14 +53,14 @@ def __init__( self, resolver: RefResolver, additional_properties: configuration.AdditionalProperties = configuration.ADDITIONALPROPERTIES_ONLY_EXPLICIT, - custom_get_name: Optional[configuration.GetNameFunction] = None, + get_name_properties: configuration.GetNameProperties = configuration.GETNAMEPROPERTIES_TITLE, ) -> None: """ Initialize with a resolver. """ self.resolver = resolver self.additional_properties = additional_properties - self.custom_get_name: Optional[configuration.GetNameFunction] = custom_get_name + self.get_name_properties = get_name_properties # types by reference self.ref_type: dict[str, Type] = {} self.root: Optional[TypeProxy] = None @@ -206,10 +206,7 @@ def get_name( proposed_name: Optional[str] = None, upper: bool = False, ) -> str: - if self.custom_get_name: - return self.custom_get_name(schema, proposed_name, upper) - else: - return get_name(schema, proposed_name, upper) + return get_name(schema, proposed_name, upper, self.get_name_properties) def resolve_ref( self, diff --git a/jsonschema_gentypes/configuration.py b/jsonschema_gentypes/configuration.py index ae6e179c..cce086e6 100644 --- a/jsonschema_gentypes/configuration.py +++ b/jsonschema_gentypes/configuration.py @@ -2,12 +2,10 @@ Automatically generated file from a JSON schema. """ -from typing import Any, Callable, Literal, Optional, TypedDict, Union +from typing import Any, Literal, TypedDict, Union from typing_extensions import Required -from jsonschema_gentypes import jsonschema_draft_04, jsonschema_draft_2019_09_meta_data - AdditionalProperties = Union[Literal["Always"], Literal["Only explicit"]] """ Additional properties. @@ -20,21 +18,6 @@ """The values for the 'Additional properties' enum""" -GetNameFunction = Callable[ - [ - Optional[ - Union[ - jsonschema_draft_04.JSONSchemaD4, - jsonschema_draft_2019_09_meta_data.JSONSchemaItemD2019, - ] - ], - Optional[str], - bool, - ], - str, -] - - class ApiArguments(TypedDict, total=False): """ API arguments. @@ -43,13 +26,19 @@ class ApiArguments(TypedDict, total=False): """ additional_properties: "AdditionalProperties" - custom_get_name: GetNameFunction """ Additional properties. Describe how to deal with additional properties """ + get_name_properties: "GetNameProperties" + """ + Get name properties. + + Describe the rules to use to get the name of a field + """ + class Configuration(TypedDict, total=False): """ @@ -119,6 +108,18 @@ class GenerateItem(TypedDict, total=False): """ +GetNameProperties = Union[Literal["Title"], Literal["UpperFirst"]] +""" +Get name properties. + +Describe the rules to use to get the name of a field +""" +GETNAMEPROPERTIES_TITLE: Literal["Title"] = "Title" +"""The values for the 'Get name properties' enum""" +GETNAMEPROPERTIES_UPPERFIRST: Literal["UpperFirst"] = "UpperFirst" +"""The values for the 'Get name properties' enum""" + + PRE_COMMIT_ARGUMENTS_DEFAULT: list[Any] = [] """ Default value of the field path 'Pre-commit configuration arguments' """ diff --git a/jsonschema_gentypes/schema.json b/jsonschema_gentypes/schema.json index fe89d105..b85a967e 100644 --- a/jsonschema_gentypes/schema.json +++ b/jsonschema_gentypes/schema.json @@ -60,6 +60,12 @@ "title": "Additional properties", "description": "Describe how to deal with additional properties", "enum": ["Always", "Only explicit"] + }, + "get_name_properties": { + "type": "string", + "title": "Get name properties", + "description": "Describe the rules to use to get the name of a field", + "enum": ["Title", "UpperFirst"] } } }, diff --git a/tests/custom_get_name.json b/tests/get_name_properties.json similarity index 100% rename from tests/custom_get_name.json rename to tests/get_name_properties.json diff --git a/tests/custom_get_name.py b/tests/get_name_properties.py similarity index 100% rename from tests/custom_get_name.py rename to tests/get_name_properties.py diff --git a/tests/test_custom_get_name.py b/tests/test_custom_get_name.py deleted file mode 100644 index 45216453..00000000 --- a/tests/test_custom_get_name.py +++ /dev/null @@ -1,64 +0,0 @@ -from typing import Optional, Union - -from jsonschema_gentypes import jsonschema_draft_04, jsonschema_draft_2019_09_meta_data, normalize -from jsonschema_gentypes.cli import process_config -from jsonschema_gentypes.configuration import Configuration - - -def custom_get_name( - schema: Optional[ - Union[ - jsonschema_draft_04.JSONSchemaD4, - jsonschema_draft_2019_09_meta_data.JSONSchemaItemD2019, - ] - ], - proposed_name: Optional[str] = None, - upper: bool = False, -) -> str: - """ - Custom get the name for an element. - - Just capitalize first Letter, don't do `.title` - - Parameter: - schema: the concerned schema - proposed_name: a name that we will use it the schema hasn't any title - upper: should we use an upper case (For constants) - """ - # Get the base name - has_title = isinstance(schema, dict) and "title" in schema - name = schema["title"] if has_title else proposed_name # type: ignore - assert name is not None - name = normalize(name) - - prefix = "" if has_title else "_" - if upper: - # Upper case - name = name.upper() - # Remove spaces - return prefix + "".join(["_" if char.isspace() else char for char in name]) - else: - # Title case - name = name[0].upper() + name[1:] - # Remove spaces - return prefix + "".join([char for char in name if not char.isspace()]) - - -def test_empty_array() -> None: - config: Configuration = Configuration( - generate=[ - { - "source": "tests/custom_get_name.json", - "destination": "tests/custom_get_name.py", - "api_arguments": {"custom_get_name": custom_get_name}, - } - ], - ) - process_config( - config, - ["tests/custom_get_name.json"], - ) - - with open("tests/custom_get_name.py") as f: - content = f.read() - assert "class SubresourceUris" in content diff --git a/tests/test_get_name_properties.py b/tests/test_get_name_properties.py new file mode 100644 index 00000000..88841839 --- /dev/null +++ b/tests/test_get_name_properties.py @@ -0,0 +1,22 @@ +from jsonschema_gentypes.cli import process_config +from jsonschema_gentypes.configuration import Configuration + + +def test_empty_array() -> None: + config: Configuration = Configuration( + generate=[ + { + "source": "tests/get_name_properties.json", + "destination": "tests/get_name_properties.py", + "api_arguments": {"get_name_properties": "UpperFirst"}, + } + ], + ) + process_config( + config, + ["tests/get_name_properties.json"], + ) + + with open("tests/get_name_properties.py") as f: + content = f.read() + assert "class SubresourceUris" in content From f6d844f3caeb0000eb25922cff444a8a65fa36d4 Mon Sep 17 00:00:00 2001 From: Dan Fellin Date: Mon, 20 May 2024 08:35:38 -0700 Subject: [PATCH 6/6] better description --- jsonschema_gentypes/configuration.py | 4 ++-- jsonschema_gentypes/schema.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jsonschema_gentypes/configuration.py b/jsonschema_gentypes/configuration.py index cce086e6..e202b2c3 100644 --- a/jsonschema_gentypes/configuration.py +++ b/jsonschema_gentypes/configuration.py @@ -36,7 +36,7 @@ class ApiArguments(TypedDict, total=False): """ Get name properties. - Describe the rules to use to get the name of a field + Describe the rules to use to get the name of an element """ @@ -112,7 +112,7 @@ class GenerateItem(TypedDict, total=False): """ Get name properties. -Describe the rules to use to get the name of a field +Describe the rules to use to get the name of an element """ GETNAMEPROPERTIES_TITLE: Literal["Title"] = "Title" """The values for the 'Get name properties' enum""" diff --git a/jsonschema_gentypes/schema.json b/jsonschema_gentypes/schema.json index b85a967e..c64067b0 100644 --- a/jsonschema_gentypes/schema.json +++ b/jsonschema_gentypes/schema.json @@ -64,7 +64,7 @@ "get_name_properties": { "type": "string", "title": "Get name properties", - "description": "Describe the rules to use to get the name of a field", + "description": "Describe the rules to use to get the name of an element", "enum": ["Title", "UpperFirst"] } }