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

Commit 5e71b63

Browse files
authored
Adds fix for refed properties with invalid names (#26)
* Adds fix for refed properties with invalid names * Adds Object with refed from property * Adds !reference property * Adds test_instantiation_success + test_omitting_required_properties_fails
1 parent 27cbe43 commit 5e71b63

File tree

15 files changed

+561
-3
lines changed

15 files changed

+561
-3
lines changed

modules/openapi-json-schema-generator/src/main/resources/python/model_templates/composed_schemas.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def any_of(cls):
9999
{{#if complexType}}
100100

101101
@staticmethod
102-
def {{baseName}}() -> typing.Type['{{complexType}}']:
102+
def {{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}() -> typing.Type['{{complexType}}']:
103103
return {{complexType}}
104104
{{else}}
105105
{{> model_templates/schema }}

modules/openapi-json-schema-generator/src/main/resources/python/model_templates/dict_partial.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class properties:
3030
{{#if complexType}}
3131

3232
@staticmethod
33-
def {{baseName}}() -> typing.Type['{{complexType}}']:
33+
def {{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}() -> typing.Type['{{complexType}}']:
3434
return {{complexType}}
3535
{{else}}
3636
{{> model_templates/schema }}

modules/openapi-json-schema-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2941,4 +2941,21 @@ components:
29412941
double:
29422942
format: double
29432943
float:
2944-
format: float
2944+
format: float
2945+
FromSchema:
2946+
type: object
2947+
properties:
2948+
data:
2949+
type: string
2950+
id:
2951+
type: integer
2952+
ObjectWithInvalidNamedRefedProperties:
2953+
type: object
2954+
properties:
2955+
from:
2956+
$ref: "#/components/schemas/FromSchema"
2957+
"!reference":
2958+
$ref: "#/components/schemas/ArrayWithValidationsInItems"
2959+
required:
2960+
- from
2961+
- "!reference"

samples/openapi3/client/petstore/python/.openapi-generator/FILES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ docs/models/File.md
6363
docs/models/FileSchemaTestClass.md
6464
docs/models/Foo.md
6565
docs/models/FormatTest.md
66+
docs/models/FromSchema.md
6667
docs/models/Fruit.md
6768
docs/models/FruitReq.md
6869
docs/models/GmFruit.md
@@ -99,6 +100,7 @@ docs/models/ObjectModelWithRefProps.md
99100
docs/models/ObjectWithDecimalProperties.md
100101
docs/models/ObjectWithDifficultlyNamedProps.md
101102
docs/models/ObjectWithInlineCompositionProperty.md
103+
docs/models/ObjectWithInvalidNamedRefedProperties.md
102104
docs/models/ObjectWithValidations.md
103105
docs/models/Order.md
104106
docs/models/ParentPet.md
@@ -248,6 +250,8 @@ petstore_api/model/foo.py
248250
petstore_api/model/foo.pyi
249251
petstore_api/model/format_test.py
250252
petstore_api/model/format_test.pyi
253+
petstore_api/model/from_schema.py
254+
petstore_api/model/from_schema.pyi
251255
petstore_api/model/fruit.py
252256
petstore_api/model/fruit.pyi
253257
petstore_api/model/fruit_req.py
@@ -320,6 +324,8 @@ petstore_api/model/object_with_difficultly_named_props.py
320324
petstore_api/model/object_with_difficultly_named_props.pyi
321325
petstore_api/model/object_with_inline_composition_property.py
322326
petstore_api/model/object_with_inline_composition_property.pyi
327+
petstore_api/model/object_with_invalid_named_refed_properties.py
328+
petstore_api/model/object_with_invalid_named_refed_properties.pyi
323329
petstore_api/model/object_with_validations.py
324330
petstore_api/model/object_with_validations.pyi
325331
petstore_api/model/order.py

samples/openapi3/client/petstore/python/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ Class | Method | HTTP request | Description
284284
- [FileSchemaTestClass](docs/models/FileSchemaTestClass.md)
285285
- [Foo](docs/models/Foo.md)
286286
- [FormatTest](docs/models/FormatTest.md)
287+
- [FromSchema](docs/models/FromSchema.md)
287288
- [Fruit](docs/models/Fruit.md)
288289
- [FruitReq](docs/models/FruitReq.md)
289290
- [GmFruit](docs/models/GmFruit.md)
@@ -320,6 +321,7 @@ Class | Method | HTTP request | Description
320321
- [ObjectWithDecimalProperties](docs/models/ObjectWithDecimalProperties.md)
321322
- [ObjectWithDifficultlyNamedProps](docs/models/ObjectWithDifficultlyNamedProps.md)
322323
- [ObjectWithInlineCompositionProperty](docs/models/ObjectWithInlineCompositionProperty.md)
324+
- [ObjectWithInvalidNamedRefedProperties](docs/models/ObjectWithInvalidNamedRefedProperties.md)
323325
- [ObjectWithValidations](docs/models/ObjectWithValidations.md)
324326
- [Order](docs/models/Order.md)
325327
- [ParentPet](docs/models/ParentPet.md)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# petstore_api.model.from_schema.FromSchema
2+
3+
## Model Type Info
4+
Input Type | Accessed Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
dict, frozendict.frozendict, | frozendict.frozendict, | |
7+
8+
### Dictionary Keys
9+
Key | Input Type | Accessed Type | Description | Notes
10+
------------ | ------------- | ------------- | ------------- | -------------
11+
**data** | str, | str, | | [optional]
12+
**id** | decimal.Decimal, int, | decimal.Decimal, | | [optional]
13+
**any_string_name** | dict, frozendict.frozendict, str, date, datetime, int, float, bool, decimal.Decimal, None, list, tuple, bytes, io.FileIO, io.BufferedReader | frozendict.frozendict, str, BoolClass, decimal.Decimal, NoneClass, tuple, bytes, FileIO | any string name can be used but the value must be the correct type | [optional]
14+
15+
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
16+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# petstore_api.model.object_with_invalid_named_refed_properties.ObjectWithInvalidNamedRefedProperties
2+
3+
## Model Type Info
4+
Input Type | Accessed Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
dict, frozendict.frozendict, | frozendict.frozendict, | |
7+
8+
### Dictionary Keys
9+
Key | Input Type | Accessed Type | Description | Notes
10+
------------ | ------------- | ------------- | ------------- | -------------
11+
**!reference** | [**ArrayWithValidationsInItems**](ArrayWithValidationsInItems.md) | [**ArrayWithValidationsInItems**](ArrayWithValidationsInItems.md) | |
12+
**from** | [**FromSchema**](FromSchema.md) | [**FromSchema**](FromSchema.md) | |
13+
**any_string_name** | dict, frozendict.frozendict, str, date, datetime, int, float, bool, decimal.Decimal, None, list, tuple, bytes, io.FileIO, io.BufferedReader | frozendict.frozendict, str, BoolClass, decimal.Decimal, NoneClass, tuple, bytes, FileIO | any string name can be used but the value must be the correct type | [optional]
14+
15+
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
16+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# coding: utf-8
2+
3+
"""
4+
OpenAPI Petstore
5+
6+
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
7+
8+
The version of the OpenAPI document: 1.0.0
9+
Generated by: https://openapi-generator.tech
10+
"""
11+
12+
from datetime import date, datetime # noqa: F401
13+
import decimal # noqa: F401
14+
import functools # noqa: F401
15+
import io # noqa: F401
16+
import re # noqa: F401
17+
import typing # noqa: F401
18+
import typing_extensions # noqa: F401
19+
import uuid # noqa: F401
20+
21+
import frozendict # noqa: F401
22+
23+
from petstore_api import schemas # noqa: F401
24+
25+
26+
class FromSchema(
27+
schemas.DictSchema
28+
):
29+
"""NOTE: This class is auto generated by OpenAPI Generator.
30+
Ref: https://openapi-generator.tech
31+
32+
Do not edit the class manually.
33+
"""
34+
35+
36+
class MetaOapg:
37+
38+
class properties:
39+
data = schemas.StrSchema
40+
id = schemas.IntSchema
41+
__annotations__ = {
42+
"data": data,
43+
"id": id,
44+
}
45+
46+
@typing.overload
47+
def __getitem__(self, name: typing_extensions.Literal["data"]) -> MetaOapg.properties.data: ...
48+
49+
@typing.overload
50+
def __getitem__(self, name: typing_extensions.Literal["id"]) -> MetaOapg.properties.id: ...
51+
52+
@typing.overload
53+
def __getitem__(self, name: str) -> schemas.UnsetAnyTypeSchema: ...
54+
55+
def __getitem__(self, name: typing.Union[typing_extensions.Literal["data", "id", ], str]):
56+
# dict_instance[name] accessor
57+
return super().__getitem__(name)
58+
59+
60+
@typing.overload
61+
def get_item_oapg(self, name: typing_extensions.Literal["data"]) -> typing.Union[MetaOapg.properties.data, schemas.Unset]: ...
62+
63+
@typing.overload
64+
def get_item_oapg(self, name: typing_extensions.Literal["id"]) -> typing.Union[MetaOapg.properties.id, schemas.Unset]: ...
65+
66+
@typing.overload
67+
def get_item_oapg(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
68+
69+
def get_item_oapg(self, name: typing.Union[typing_extensions.Literal["data", "id", ], str]):
70+
return super().get_item_oapg(name)
71+
72+
73+
def __new__(
74+
cls,
75+
*args: typing.Union[dict, frozendict.frozendict, ],
76+
data: typing.Union[MetaOapg.properties.data, str, schemas.Unset] = schemas.unset,
77+
id: typing.Union[MetaOapg.properties.id, decimal.Decimal, int, schemas.Unset] = schemas.unset,
78+
_configuration: typing.Optional[schemas.Configuration] = None,
79+
**kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes],
80+
) -> 'FromSchema':
81+
return super().__new__(
82+
cls,
83+
*args,
84+
data=data,
85+
id=id,
86+
_configuration=_configuration,
87+
**kwargs,
88+
)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# coding: utf-8
2+
3+
"""
4+
OpenAPI Petstore
5+
6+
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
7+
8+
The version of the OpenAPI document: 1.0.0
9+
Generated by: https://openapi-generator.tech
10+
"""
11+
12+
from datetime import date, datetime # noqa: F401
13+
import decimal # noqa: F401
14+
import functools # noqa: F401
15+
import io # noqa: F401
16+
import re # noqa: F401
17+
import typing # noqa: F401
18+
import typing_extensions # noqa: F401
19+
import uuid # noqa: F401
20+
21+
import frozendict # noqa: F401
22+
23+
from petstore_api import schemas # noqa: F401
24+
25+
26+
class FromSchema(
27+
schemas.DictSchema
28+
):
29+
"""NOTE: This class is auto generated by OpenAPI Generator.
30+
Ref: https://openapi-generator.tech
31+
32+
Do not edit the class manually.
33+
"""
34+
35+
36+
class MetaOapg:
37+
38+
class properties:
39+
data = schemas.StrSchema
40+
id = schemas.IntSchema
41+
__annotations__ = {
42+
"data": data,
43+
"id": id,
44+
}
45+
46+
@typing.overload
47+
def __getitem__(self, name: typing_extensions.Literal["data"]) -> MetaOapg.properties.data: ...
48+
49+
@typing.overload
50+
def __getitem__(self, name: typing_extensions.Literal["id"]) -> MetaOapg.properties.id: ...
51+
52+
@typing.overload
53+
def __getitem__(self, name: str) -> schemas.UnsetAnyTypeSchema: ...
54+
55+
def __getitem__(self, name: typing.Union[typing_extensions.Literal["data", "id", ], str]):
56+
# dict_instance[name] accessor
57+
return super().__getitem__(name)
58+
59+
60+
@typing.overload
61+
def get_item_oapg(self, name: typing_extensions.Literal["data"]) -> typing.Union[MetaOapg.properties.data, schemas.Unset]: ...
62+
63+
@typing.overload
64+
def get_item_oapg(self, name: typing_extensions.Literal["id"]) -> typing.Union[MetaOapg.properties.id, schemas.Unset]: ...
65+
66+
@typing.overload
67+
def get_item_oapg(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
68+
69+
def get_item_oapg(self, name: typing.Union[typing_extensions.Literal["data", "id", ], str]):
70+
return super().get_item_oapg(name)
71+
72+
73+
def __new__(
74+
cls,
75+
*args: typing.Union[dict, frozendict.frozendict, ],
76+
data: typing.Union[MetaOapg.properties.data, str, schemas.Unset] = schemas.unset,
77+
id: typing.Union[MetaOapg.properties.id, decimal.Decimal, int, schemas.Unset] = schemas.unset,
78+
_configuration: typing.Optional[schemas.Configuration] = None,
79+
**kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes],
80+
) -> 'FromSchema':
81+
return super().__new__(
82+
cls,
83+
*args,
84+
data=data,
85+
id=id,
86+
_configuration=_configuration,
87+
**kwargs,
88+
)

0 commit comments

Comments
 (0)