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

Fixes issue 43, fixes class type hint for required prop that is not in properties #44

Merged
merged 2 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ def __new__(
{{#if complexType}}
{{baseName}}: '{{complexType}}',
{{else}}
{{#if getSchemaIsFromAdditionalProperties}}
{{#if addPropsUnset}}
{{baseName}}: typing.Union[schemas.AnyTypeSchema, {{> model_templates/schema_python_types }}],
{{else}}
{{baseName}}: typing.Union[MetaOapg.additional_properties, {{> model_templates/schema_python_types }}],
{{/if}}
{{else}}
{{baseName}}: typing.Union[MetaOapg.properties.{{baseName}}, {{> model_templates/schema_python_types }}],
{{/if}}
{{/if}}
{{/unless}}
{{/with}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ class {{> model_templates/classname }}(
{{/if}}
{{> model_templates/property_type_hints }}

{{#if additionalProperties}}
{{> model_templates/new }}
{{else}}
{{> model_templates/new addPropsUnset=true }}
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -2978,4 +2978,17 @@ components:
$ref: "#/components/schemas/ArrayWithValidationsInItems"
required:
- from
- "!reference"
- "!reference"
ObjectWithOptionalTestProp:
type: object
properties:
test:
type: string
ObjectWithAllOfWithReqTestPropFromUnsetAddProp:
allOf:
- $ref: '#/components/schemas/ObjectWithOptionalTestProp'
- type: object
required: [ test ]
properties:
name:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ docs/models/NumberOnly.md
docs/models/NumberWithValidations.md
docs/models/ObjectInterface.md
docs/models/ObjectModelWithRefProps.md
docs/models/ObjectWithAllOfWithReqTestPropFromUnsetAddProp.md
docs/models/ObjectWithDecimalProperties.md
docs/models/ObjectWithDifficultlyNamedProps.md
docs/models/ObjectWithInlineCompositionProperty.md
docs/models/ObjectWithInvalidNamedRefedProperties.md
docs/models/ObjectWithOptionalTestProp.md
docs/models/ObjectWithValidations.md
docs/models/Order.md
docs/models/ParentPet.md
Expand Down Expand Up @@ -318,6 +320,8 @@ petstore_api/model/object_interface.py
petstore_api/model/object_interface.pyi
petstore_api/model/object_model_with_ref_props.py
petstore_api/model/object_model_with_ref_props.pyi
petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.py
petstore_api/model/object_with_all_of_with_req_test_prop_from_unset_add_prop.pyi
petstore_api/model/object_with_decimal_properties.py
petstore_api/model/object_with_decimal_properties.pyi
petstore_api/model/object_with_difficultly_named_props.py
Expand All @@ -326,6 +330,8 @@ petstore_api/model/object_with_inline_composition_property.py
petstore_api/model/object_with_inline_composition_property.pyi
petstore_api/model/object_with_invalid_named_refed_properties.py
petstore_api/model/object_with_invalid_named_refed_properties.pyi
petstore_api/model/object_with_optional_test_prop.py
petstore_api/model/object_with_optional_test_prop.pyi
petstore_api/model/object_with_validations.py
petstore_api/model/object_with_validations.pyi
petstore_api/model/order.py
Expand Down
2 changes: 2 additions & 0 deletions samples/openapi3/client/petstore/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,12 @@ Class | Method | HTTP request | Description
- [NumberWithValidations](docs/models/NumberWithValidations.md)
- [ObjectInterface](docs/models/ObjectInterface.md)
- [ObjectModelWithRefProps](docs/models/ObjectModelWithRefProps.md)
- [ObjectWithAllOfWithReqTestPropFromUnsetAddProp](docs/models/ObjectWithAllOfWithReqTestPropFromUnsetAddProp.md)
- [ObjectWithDecimalProperties](docs/models/ObjectWithDecimalProperties.md)
- [ObjectWithDifficultlyNamedProps](docs/models/ObjectWithDifficultlyNamedProps.md)
- [ObjectWithInlineCompositionProperty](docs/models/ObjectWithInlineCompositionProperty.md)
- [ObjectWithInvalidNamedRefedProperties](docs/models/ObjectWithInvalidNamedRefedProperties.md)
- [ObjectWithOptionalTestProp](docs/models/ObjectWithOptionalTestProp.md)
- [ObjectWithValidations](docs/models/ObjectWithValidations.md)
- [Order](docs/models/Order.md)
- [ParentPet](docs/models/ParentPet.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# petstore_api.model.object_with_all_of_with_req_test_prop_from_unset_add_prop.ObjectWithAllOfWithReqTestPropFromUnsetAddProp

## Model Type Info
Input Type | Accessed Type | Description | Notes
------------ | ------------- | ------------- | -------------
dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, FileIO | |

### Composed Schemas (allOf/anyOf/oneOf/not)
#### allOf
Class Name | Input Type | Accessed Type | Description | Notes
------------- | ------------- | ------------- | ------------- | -------------
[ObjectWithOptionalTestProp](ObjectWithOptionalTestProp.md) | [**ObjectWithOptionalTestProp**](ObjectWithOptionalTestProp.md) | [**ObjectWithOptionalTestProp**](ObjectWithOptionalTestProp.md) | |
[all_of_1](#all_of_1) | dict, frozendict.frozendict, | frozendict.frozendict, | |

# all_of_1

## Model Type Info
Input Type | Accessed Type | Description | Notes
------------ | ------------- | ------------- | -------------
dict, frozendict.frozendict, | frozendict.frozendict, | |

### Dictionary Keys
Key | Input Type | Accessed Type | Description | Notes
------------ | ------------- | ------------- | ------------- | -------------
**test** | dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, FileIO | |
**name** | str, | str, | | [optional]
**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]

[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# petstore_api.model.object_with_optional_test_prop.ObjectWithOptionalTestProp

## Model Type Info
Input Type | Accessed Type | Description | Notes
------------ | ------------- | ------------- | -------------
dict, frozendict.frozendict, | frozendict.frozendict, | |

### Dictionary Keys
Key | Input Type | Accessed Type | Description | Notes
------------ | ------------- | ------------- | ------------- | -------------
**test** | str, | str, | | [optional]
**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]

[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# coding: utf-8

"""
OpenAPI Petstore

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

The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""

from datetime import date, datetime # noqa: F401
import decimal # noqa: F401
import functools # noqa: F401
import io # noqa: F401
import re # noqa: F401
import typing # noqa: F401
import typing_extensions # noqa: F401
import uuid # noqa: F401

import frozendict # noqa: F401

from petstore_api import schemas # noqa: F401


class ObjectWithAllOfWithReqTestPropFromUnsetAddProp(
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

Do not edit the class manually.
"""


class MetaOapg:


class all_of_1(
schemas.DictSchema
):


class MetaOapg:
required = {
"test",
}

class properties:
name = schemas.StrSchema
__annotations__ = {
"name": name,
}

test: schemas.AnyTypeSchema

@typing.overload
def __getitem__(self, name: typing_extensions.Literal["name"]) -> MetaOapg.properties.name: ...

@typing.overload
def __getitem__(self, name: str) -> schemas.UnsetAnyTypeSchema: ...

def __getitem__(self, name: typing.Union[typing_extensions.Literal["name", ], str]):
# dict_instance[name] accessor
return super().__getitem__(name)


@typing.overload
def get_item_oapg(self, name: typing_extensions.Literal["name"]) -> typing.Union[MetaOapg.properties.name, schemas.Unset]: ...

@typing.overload
def get_item_oapg(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...

def get_item_oapg(self, name: typing.Union[typing_extensions.Literal["name", ], str]):
return super().get_item_oapg(name)


def __new__(
cls,
*args: typing.Union[dict, frozendict.frozendict, ],
test: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, ],
name: typing.Union[MetaOapg.properties.name, str, schemas.Unset] = schemas.unset,
_configuration: typing.Optional[schemas.Configuration] = None,
**kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes],
) -> 'all_of_1':
return super().__new__(
cls,
*args,
test=test,
name=name,
_configuration=_configuration,
**kwargs,
)

@classmethod
@functools.lru_cache()
def all_of(cls):
# we need this here to make our import statements work
# we must store _composed_schemas in here so the code is only run
# when we invoke this method. If we kept this at the class
# level we would get an error because the class level
# code would be run when this module is imported, and these composed
# classes don't exist yet because their module has not finished
# loading
return [
ObjectWithOptionalTestProp,
cls.all_of_1,
]


def __new__(
cls,
*args: typing.Union[dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, ],
_configuration: typing.Optional[schemas.Configuration] = None,
**kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes],
) -> 'ObjectWithAllOfWithReqTestPropFromUnsetAddProp':
return super().__new__(
cls,
*args,
_configuration=_configuration,
**kwargs,
)

from petstore_api.model.object_with_optional_test_prop import ObjectWithOptionalTestProp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# coding: utf-8

"""
OpenAPI Petstore

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

The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""

from datetime import date, datetime # noqa: F401
import decimal # noqa: F401
import functools # noqa: F401
import io # noqa: F401
import re # noqa: F401
import typing # noqa: F401
import typing_extensions # noqa: F401
import uuid # noqa: F401

import frozendict # noqa: F401

from petstore_api import schemas # noqa: F401


class ObjectWithAllOfWithReqTestPropFromUnsetAddProp(
schemas.ComposedSchema,
):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech

Do not edit the class manually.
"""


class MetaOapg:


class all_of_1(
schemas.DictSchema
):


class MetaOapg:
required = {
"test",
}

class properties:
name = schemas.StrSchema
__annotations__ = {
"name": name,
}

test: schemas.AnyTypeSchema

@typing.overload
def __getitem__(self, name: typing_extensions.Literal["name"]) -> MetaOapg.properties.name: ...

@typing.overload
def __getitem__(self, name: str) -> schemas.UnsetAnyTypeSchema: ...

def __getitem__(self, name: typing.Union[typing_extensions.Literal["name", ], str]):
# dict_instance[name] accessor
return super().__getitem__(name)


@typing.overload
def get_item_oapg(self, name: typing_extensions.Literal["name"]) -> typing.Union[MetaOapg.properties.name, schemas.Unset]: ...

@typing.overload
def get_item_oapg(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...

def get_item_oapg(self, name: typing.Union[typing_extensions.Literal["name", ], str]):
return super().get_item_oapg(name)


def __new__(
cls,
*args: typing.Union[dict, frozendict.frozendict, ],
test: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, ],
name: typing.Union[MetaOapg.properties.name, str, schemas.Unset] = schemas.unset,
_configuration: typing.Optional[schemas.Configuration] = None,
**kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes],
) -> 'all_of_1':
return super().__new__(
cls,
*args,
test=test,
name=name,
_configuration=_configuration,
**kwargs,
)

@classmethod
@functools.lru_cache()
def all_of(cls):
# we need this here to make our import statements work
# we must store _composed_schemas in here so the code is only run
# when we invoke this method. If we kept this at the class
# level we would get an error because the class level
# code would be run when this module is imported, and these composed
# classes don't exist yet because their module has not finished
# loading
return [
ObjectWithOptionalTestProp,
cls.all_of_1,
]


def __new__(
cls,
*args: typing.Union[dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, ],
_configuration: typing.Optional[schemas.Configuration] = None,
**kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes],
) -> 'ObjectWithAllOfWithReqTestPropFromUnsetAddProp':
return super().__new__(
cls,
*args,
_configuration=_configuration,
**kwargs,
)

from petstore_api.model.object_with_optional_test_prop import ObjectWithOptionalTestProp
Loading