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

File tree

145 files changed

+26
-2626
lines changed

Some content is hidden

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

145 files changed

+26
-2626
lines changed

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

-1
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

-55
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}}
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

+2-4
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

-9
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[
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

-1
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

+2-4
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

-19
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

-19
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,

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

-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ class Schema_:
4040
def __getitem__(self, name: str) -> Schema_.AdditionalProperties:
4141
# dict_instance[name] accessor
4242
return super().__getitem__(name)
43-
44-
def get_item_(self, name: str) -> Schema_.AdditionalProperties:
45-
return super().get_item_(name)
4643

4744
def __new__(
4845
cls,

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

-18
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,6 @@ def __getitem__(
7070
):
7171
# dict_instance[name] accessor
7272
return super().__getitem__(name)
73-
74-
@typing.overload
75-
def get_item_(self, name: typing_extensions.Literal["foo"]) -> typing.Union[Schema_.Properties.Foo, schemas.Unset]: ...
76-
77-
@typing.overload
78-
def get_item_(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
79-
80-
def get_item_(
81-
self,
82-
name: typing.Union[
83-
typing_extensions.Literal["foo"],
84-
str
85-
]
86-
):
87-
return super().get_item_(name)
8873

8974
def __new__(
9075
cls,
@@ -108,9 +93,6 @@ def __new__(
10893
def __getitem__(self, name: str) -> Schema_.AdditionalProperties:
10994
# dict_instance[name] accessor
11095
return super().__getitem__(name)
111-
112-
def get_item_(self, name: str) -> Schema_.AdditionalProperties:
113-
return super().get_item_(name)
11496

11597
def __new__(
11698
cls,

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

-30
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,6 @@ def __getitem__(
7474
):
7575
# dict_instance[name] accessor
7676
return super().__getitem__(name)
77-
78-
@typing.overload
79-
def get_item_(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar: ...
80-
81-
@typing.overload
82-
def get_item_(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
83-
84-
def get_item_(
85-
self,
86-
name: typing.Union[
87-
typing_extensions.Literal["bar"],
88-
str
89-
]
90-
):
91-
return super().get_item_(name)
9277

9378
def __new__(
9479
cls,
@@ -139,21 +124,6 @@ def __getitem__(
139124
):
140125
# dict_instance[name] accessor
141126
return super().__getitem__(name)
142-
143-
@typing.overload
144-
def get_item_(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo: ...
145-
146-
@typing.overload
147-
def get_item_(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
148-
149-
def get_item_(
150-
self,
151-
name: typing.Union[
152-
typing_extensions.Literal["foo"],
153-
str
154-
]
155-
):
156-
return super().get_item_(name)
157127

158128
def __new__(
159129
cls,

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

-45
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,6 @@ def __getitem__(
8383
):
8484
# dict_instance[name] accessor
8585
return super().__getitem__(name)
86-
87-
@typing.overload
88-
def get_item_(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo: ...
89-
90-
@typing.overload
91-
def get_item_(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
92-
93-
def get_item_(
94-
self,
95-
name: typing.Union[
96-
typing_extensions.Literal["foo"],
97-
str
98-
]
99-
):
100-
return super().get_item_(name)
10186

10287
def __new__(
10388
cls,
@@ -148,21 +133,6 @@ def __getitem__(
148133
):
149134
# dict_instance[name] accessor
150135
return super().__getitem__(name)
151-
152-
@typing.overload
153-
def get_item_(self, name: typing_extensions.Literal["baz"]) -> Schema_.Properties.Baz: ...
154-
155-
@typing.overload
156-
def get_item_(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
157-
158-
def get_item_(
159-
self,
160-
name: typing.Union[
161-
typing_extensions.Literal["baz"],
162-
str
163-
]
164-
):
165-
return super().get_item_(name)
166136

167137
def __new__(
168138
cls,
@@ -199,21 +169,6 @@ def __getitem__(
199169
):
200170
# dict_instance[name] accessor
201171
return super().__getitem__(name)
202-
203-
@typing.overload
204-
def get_item_(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar: ...
205-
206-
@typing.overload
207-
def get_item_(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
208-
209-
def get_item_(
210-
self,
211-
name: typing.Union[
212-
typing_extensions.Literal["bar"],
213-
str
214-
]
215-
):
216-
return super().get_item_(name)
217172

218173
def __new__(
219174
cls,

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

-30
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,6 @@ def __getitem__(
7474
):
7575
# dict_instance[name] accessor
7676
return super().__getitem__(name)
77-
78-
@typing.overload
79-
def get_item_(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar: ...
80-
81-
@typing.overload
82-
def get_item_(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
83-
84-
def get_item_(
85-
self,
86-
name: typing.Union[
87-
typing_extensions.Literal["bar"],
88-
str
89-
]
90-
):
91-
return super().get_item_(name)
9277

9378
def __new__(
9479
cls,
@@ -139,21 +124,6 @@ def __getitem__(
139124
):
140125
# dict_instance[name] accessor
141126
return super().__getitem__(name)
142-
143-
@typing.overload
144-
def get_item_(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo: ...
145-
146-
@typing.overload
147-
def get_item_(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
148-
149-
def get_item_(
150-
self,
151-
name: typing.Union[
152-
typing_extensions.Literal["foo"],
153-
str
154-
]
155-
):
156-
return super().get_item_(name)
157127

158128
def __new__(
159129
cls,

0 commit comments

Comments
 (0)