Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit f84c363

Browse files
authored
Removes get_item_ (#159)
* Removes get_item_ * Samples and docs updated * Fixes python tests
1 parent c3ba84e commit f84c363

145 files changed

Lines changed: 26 additions & 2626 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-json-schema-generator/src/main/resources/python/README.hbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ This means that one can use normal dict methods on instances of these classes.
141141
- optional properties which were not set will not exist in the instance
142142
- None is only allowed in as a value if type: "null" was included or nullable: true was set
143143
- type hints are written for accessing values by key literals like instance["hi-there"]
144-
- and there is a method instance.get_item_["hi-there"] which returns an schemas.Unset value if the key was not set
145144
- required properties with valid python names are accessible with instance.SomeRequiredProp
146145
which uses the exact key from the openapi document
147146
- preserving the original key names is required to properly validate a payload to multiple json schemas

modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getitems.hbs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -53,59 +53,4 @@ def __getitem__(self, name: str) -> {{#if refInfo.refClass}}'{{> components/sche
5353
return super().__getitem__(name)
5454
{{/unless}}
5555
{{/with}}
56-
{{/or}}
57-
{{#if requiredProperties}}
58-
{{#each requiredProperties}}
59-
{{#with this}}
60-
61-
@typing.overload
62-
{{#if refInfo.refClass}}
63-
def get_item_(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> '{{> components/schemas/_helper_refclass_with_module }}': ...
64-
{{else}}
65-
{{#if jsonPathPiece}}
66-
{{#if schemaIsFromAdditionalProperties}}
67-
def get_item_(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> Schema_.{{jsonPathPiece.camelCase}}: ...
68-
{{else}}
69-
def get_item_(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> Schema_.Properties.{{jsonPathPiece.camelCase}}: ...
70-
{{/if}}
71-
{{else}}
72-
def get_item_(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> schemas.AnyTypeSchema: ...
73-
{{/if}}
74-
{{/if}}
75-
{{/with}}
76-
{{/each}}
77-
{{/if}}
78-
{{#if optionalProperties}}
79-
{{#each optionalProperties}}
80-
81-
@typing.overload
82-
{{#if refInfo.refClass}}
83-
def get_item_(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> typing.Union['{{> components/schemas/_helper_refclass_with_module }}', schemas.Unset]: ...
84-
{{else}}
85-
def get_item_(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> typing.Union[Schema_.Properties.{{jsonPathPiece.camelCase}}, schemas.Unset]: ...
86-
{{/if}}
87-
{{/each}}
88-
{{/if}}
89-
{{#or properties requiredProperties}}
90-
{{#with additionalProperties}}
91-
{{#unless isBooleanSchemaFalse}}
92-
93-
@typing.overload
94-
def get_item_(self, name: str) -> typing.Union[{{#if refInfo.refClass}}'{{> components/schemas/_helper_refclass_with_module }}'{{else}}Schema_.{{jsonPathPiece.camelCase}}{{/if}}, schemas.Unset]: ...
95-
{{/unless}}
96-
{{else}}
97-
98-
@typing.overload
99-
def get_item_(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
100-
{{/with}}
101-
102-
{{> components/schemas/_helper_getitem methodName="get_item_" }}
103-
{{else}}
104-
{{#with additionalProperties}}
105-
{{#unless isBooleanSchemaFalse}}
106-
107-
def get_item_(self, name: str) -> {{#if refInfo.refClass}}'{{> components/schemas/_helper_refclass_with_module }}'{{else}}Schema_.{{jsonPathPiece.camelCase}}{{/if}}:
108-
return super().get_item_(name)
109-
{{/unless}}
110-
{{/with}}
11156
{{/or}}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Migration v2.0.0 to v3.0.0
2+
3+
- get_item_ methods have been removed to reduce amount of generated code
4+
- instead use instance.get('someProp', schemas.unset)
5+
- urllib3 has been downgraded from 2.0.a3 -> urllib3>=1.21.1,<1.27 required by requests == 2.28.2
6+
- this change was required because oauth2 support was added and it uses the requests library

modules/openapi-json-schema-generator/src/main/resources/python/migration_other_python_generators.hbs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ When switching from other python client generators you will need to make some ch
3535
- Only required keys with valid python names are properties like .someProp and have type hints
3636
- All optional keys may not exist, so properties are not defined for them
3737
- One can access optional values with dict_instance['optionalProp'] and KeyError will be raised if it does not exist
38-
- Use get_item_ if you need a way to always get a value whether or not the key exists
39-
- If the key does not exist, schemas.unset is returned from calling dict_instance.get_item_('optionalProp')
40-
- All required and optional keys have type hints for this method, and @typing.overload is used
41-
- A type hint is also generated for additionalProperties accessed using this method
38+
- if you need a way to always get a value whether or not the key exists use:
39+
- dict_instance.get('optionalProp', schemas.unset)
4240
- So you will need to update you code to use some_instance['optionalProp'] to access optional property
4341
and additionalProperty values
4442
8. The location of the api classes has changed

modules/openapi-json-schema-generator/src/main/resources/python/schemas.hbs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,15 +2020,6 @@ class DictBase:
20202020
except KeyError as ex:
20212021
raise AttributeError(str(ex))
20222022

2023-
def get_item_(self, name: str) -> typing.Union['AnyTypeSchema', Unset]:
2024-
# dict_instance[name] accessor
2025-
if not isinstance(self, frozendict.frozendict):
2026-
raise NotImplementedError()
2027-
try:
2028-
return super().__getitem__(name)
2029-
except KeyError:
2030-
return unset
2031-
20322023

20332024
def cast_to_allowed_types(
20342025
arg: typing.Union[
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0
1+
3.0.0

samples/openapi3/client/3_0_3_unit_test/python/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ This means that one can use normal dict methods on instances of these classes.
133133
- optional properties which were not set will not exist in the instance
134134
- None is only allowed in as a value if type: "null" was included or nullable: true was set
135135
- type hints are written for accessing values by key literals like instance["hi-there"]
136-
- and there is a method instance.get_item_["hi-there"] which returns an schemas.Unset value if the key was not set
137136
- required properties with valid python names are accessible with instance.SomeRequiredProp
138137
which uses the exact key from the openapi document
139138
- preserving the original key names is required to properly validate a payload to multiple json schemas

samples/openapi3/client/3_0_3_unit_test/python/migration_other_python_generators.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ When switching from other python client generators you will need to make some ch
3535
- Only required keys with valid python names are properties like .someProp and have type hints
3636
- All optional keys may not exist, so properties are not defined for them
3737
- One can access optional values with dict_instance['optionalProp'] and KeyError will be raised if it does not exist
38-
- Use get_item_ if you need a way to always get a value whether or not the key exists
39-
- If the key does not exist, schemas.unset is returned from calling dict_instance.get_item_('optionalProp')
40-
- All required and optional keys have type hints for this method, and @typing.overload is used
41-
- A type hint is also generated for additionalProperties accessed using this method
38+
- if you need a way to always get a value whether or not the key exists use:
39+
- dict_instance.get('optionalProp', schemas.unset)
4240
- So you will need to update you code to use some_instance['optionalProp'] to access optional property
4341
and additionalProperty values
4442
8. The location of the api classes has changed

samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_allows_a_schema_which_should_validate.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,6 @@ def __getitem__(
6464
):
6565
# dict_instance[name] accessor
6666
return super().__getitem__(name)
67-
68-
@typing.overload
69-
def get_item_(self, name: typing_extensions.Literal["foo"]) -> typing.Union[Schema_.Properties.Foo, schemas.Unset]: ...
70-
71-
@typing.overload
72-
def get_item_(self, name: typing_extensions.Literal["bar"]) -> typing.Union[Schema_.Properties.Bar, schemas.Unset]: ...
73-
74-
@typing.overload
75-
def get_item_(self, name: str) -> typing.Union[Schema_.AdditionalProperties, schemas.Unset]: ...
76-
77-
def get_item_(
78-
self,
79-
name: typing.Union[
80-
typing_extensions.Literal["foo"],
81-
typing_extensions.Literal["bar"],
82-
str
83-
]
84-
):
85-
return super().get_item_(name)
8667

8768
def __new__(
8869
cls,

samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_are_allowed_by_default.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,6 @@ def __getitem__(
6464
):
6565
# dict_instance[name] accessor
6666
return super().__getitem__(name)
67-
68-
@typing.overload
69-
def get_item_(self, name: typing_extensions.Literal["foo"]) -> typing.Union[Schema_.Properties.Foo, schemas.Unset]: ...
70-
71-
@typing.overload
72-
def get_item_(self, name: typing_extensions.Literal["bar"]) -> typing.Union[Schema_.Properties.Bar, schemas.Unset]: ...
73-
74-
@typing.overload
75-
def get_item_(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
76-
77-
def get_item_(
78-
self,
79-
name: typing.Union[
80-
typing_extensions.Literal["foo"],
81-
typing_extensions.Literal["bar"],
82-
str
83-
]
84-
):
85-
return super().get_item_(name)
8667

8768
def __new__(
8869
cls,

0 commit comments

Comments
 (0)