Skip to content

Commit

Permalink
Fixes Python schema class order, Issue 276 (#277)
Browse files Browse the repository at this point in the history
* Adds new components, adds possible java fix

* Fixes schema writing order

* Fixes python test

* Samples regen
  • Loading branch information
spacether committed Nov 7, 2023
1 parent 06c63dd commit 9a73df4
Show file tree
Hide file tree
Showing 50 changed files with 753 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
from unit_test_api.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary]


from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference
AllOf = typing.Tuple[
typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference],
]


@dataclasses.dataclass(frozen=True)
class RefInAllof(
Expand All @@ -24,8 +29,3 @@ class RefInAllof(
# any type
all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore


from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference
AllOf = typing.Tuple[
typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference],
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
from unit_test_api.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary]


from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference
AnyOf = typing.Tuple[
typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference],
]


@dataclasses.dataclass(frozen=True)
class RefInAnyof(
Expand All @@ -24,8 +29,3 @@ class RefInAnyof(
# any type
any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore


from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference
AnyOf = typing.Tuple[
typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference],
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
from unit_test_api.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary]


from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference
OneOf = typing.Tuple[
typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference],
]


@dataclasses.dataclass(frozen=True)
class RefInOneof(
Expand All @@ -24,8 +29,3 @@ class RefInOneof(
# any type
one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore


from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference
OneOf = typing.Tuple[
typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference],
]
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,9 @@ def validate_any_of(
) -> PathToSchemasType:
anyof_classes = []
path_to_schemas: PathToSchemasType = collections.defaultdict(dict)
module_namespace = vars(sys.modules[cls.__module__])
for schema in classes:
schema = _get_class(schema)
schema = _get_class(schema, module_namespace)
if schema is cls:
"""
optimistically assume that cls schema will pass validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,9 @@ def validate_any_of(
) -> PathToSchemasType:
anyof_classes = []
path_to_schemas: PathToSchemasType = collections.defaultdict(dict)
module_namespace = vars(sys.modules[cls.__module__])
for schema in classes:
schema = _get_class(schema)
schema = _get_class(schema, module_namespace)
if schema is cls:
"""
optimistically assume that cls schema will pass validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
from this_package.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary]


from this_package.components.schema import addition_operator
from this_package.components.schema import subtraction_operator
OneOf = typing.Tuple[
typing.Type[addition_operator.AdditionOperator],
typing.Type[subtraction_operator.SubtractionOperator],
]


@dataclasses.dataclass(frozen=True)
class Operator(
Expand All @@ -34,10 +41,3 @@ class Operator(
)
one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore


from this_package.components.schema import addition_operator
from this_package.components.schema import subtraction_operator
OneOf = typing.Tuple[
typing.Type[addition_operator.AdditionOperator],
typing.Type[subtraction_operator.SubtractionOperator],
]
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,9 @@ def validate_any_of(
) -> PathToSchemasType:
anyof_classes = []
path_to_schemas: PathToSchemasType = collections.defaultdict(dict)
module_namespace = vars(sys.modules[cls.__module__])
for schema in classes:
schema = _get_class(schema)
schema = _get_class(schema, module_namespace)
if schema is cls:
"""
optimistically assume that cls schema will pass validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,9 @@ def validate_any_of(
) -> PathToSchemasType:
anyof_classes = []
path_to_schemas: PathToSchemasType = collections.defaultdict(dict)
module_namespace = vars(sys.modules[cls.__module__])
for schema in classes:
schema = _get_class(schema)
schema = _get_class(schema, module_namespace)
if schema is cls:
"""
optimistically assume that cls schema will pass validation
Expand Down
8 changes: 8 additions & 0 deletions samples/client/petstore/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ Class | Description



[MyObjectDto](docs/MyObjectDto.md) |



[Name](docs/Name.md) | Model for testing model name same as property name


Expand Down Expand Up @@ -906,6 +910,10 @@ Class | Description



[PaginatedResultMyObjectDto](docs/PaginatedResultMyObjectDto.md) |



[ParentPet](docs/ParentPet.md) |


Expand Down
4 changes: 4 additions & 0 deletions samples/client/petstore/python/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ docs/components/schema/mammal.md
docs/components/schema/map_test.md
docs/components/schema/mixed_properties_and_additional_properties_class.md
docs/components/schema/money.md
docs/components/schema/my_object_dto.md
docs/components/schema/name.md
docs/components/schema/no_additional_properties.md
docs/components/schema/nullable_class.md
Expand All @@ -152,6 +153,7 @@ docs/components/schema/object_with_only_optional_props.md
docs/components/schema/object_with_optional_test_prop.md
docs/components/schema/object_with_validations.md
docs/components/schema/order.md
docs/components/schema/paginated_result_my_object_dto.md
docs/components/schema/parent_pet.md
docs/components/schema/pet.md
docs/components/schema/pig.md
Expand Down Expand Up @@ -636,6 +638,7 @@ src/petstore_api/components/schema/mammal.py
src/petstore_api/components/schema/map_test.py
src/petstore_api/components/schema/mixed_properties_and_additional_properties_class.py
src/petstore_api/components/schema/money.py
src/petstore_api/components/schema/my_object_dto.py
src/petstore_api/components/schema/name.py
src/petstore_api/components/schema/no_additional_properties.py
src/petstore_api/components/schema/nullable_class.py
Expand All @@ -660,6 +663,7 @@ src/petstore_api/components/schema/object_with_only_optional_props.py
src/petstore_api/components/schema/object_with_optional_test_prop.py
src/petstore_api/components/schema/object_with_validations.py
src/petstore_api/components/schema/order.py
src/petstore_api/components/schema/paginated_result_my_object_dto.py
src/petstore_api/components/schema/parent_pet.py
src/petstore_api/components/schema/pet.py
src/petstore_api/components/schema/pig.py
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ Class | Description
[MapTest](docs/components/schema/map_test.md) |
[MixedPropertiesAndAdditionalPropertiesClass](docs/components/schema/mixed_properties_and_additional_properties_class.md) |
[Money](docs/components/schema/money.md) |
[MyObjectDto](docs/components/schema/my_object_dto.md) |
[Name](docs/components/schema/name.md) | Model for testing model name same as property name
[NoAdditionalProperties](docs/components/schema/no_additional_properties.md) |
[NullableClass](docs/components/schema/nullable_class.md) |
Expand All @@ -335,6 +336,7 @@ Class | Description
[ObjectWithOptionalTestProp](docs/components/schema/object_with_optional_test_prop.md) |
[ObjectWithValidations](docs/components/schema/object_with_validations.md) |
[Order](docs/components/schema/order.md) |
[PaginatedResultMyObjectDto](docs/components/schema/paginated_result_my_object_dto.md) |
[ParentPet](docs/components/schema/parent_pet.md) |
[Pet](docs/components/schema/pet.md) | Pet object that needs to be added to the store
[Pig](docs/components/schema/pig.md) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# MyObjectDto
petstore_api.components.schema.my_object_dto
```
type: schemas.Schema
```

## validate method
Input Type | Return Type | Notes
------------ | ------------- | -------------
[MyObjectDtoDictInput](#myobjectdtodictinput), [MyObjectDtoDict](#myobjectdtodict) | [MyObjectDtoDict](#myobjectdtodict) |

## MyObjectDtoDictInput
```
type: typing.TypedDict
```
Key | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | str, uuid.UUID | | [optional] value must be a uuid

## MyObjectDtoDict
```
base class: schemas.immutabledict[str, str]
```
### __new__ method
Keyword Argument | Type | Description | Notes
---------------- | ---- | ----------- | -----
**id** | str, uuid.UUID, schemas.Unset | | [optional] value must be a uuid

### properties
Property | Type | Description | Notes
-------- | ---- | ----------- | -----
**id** | str, schemas.Unset | | [optional] value must be a uuid

### methods
Method | Input Type | Return Type | Notes
------ | ---------- | ----------- | ------
from_dict_ | [MyObjectDtoDictInput](#myobjectdtodictinput), [MyObjectDtoDict](#myobjectdtodict) | [MyObjectDtoDict](#myobjectdtodict) | a constructor

[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# PaginatedResultMyObjectDto
petstore_api.components.schema.paginated_result_my_object_dto
```
type: schemas.Schema
```

## validate method
Input Type | Return Type | Notes
------------ | ------------- | -------------
[PaginatedResultMyObjectDtoDictInput](#paginatedresultmyobjectdtodictinput), [PaginatedResultMyObjectDtoDict](#paginatedresultmyobjectdtodict) | [PaginatedResultMyObjectDtoDict](#paginatedresultmyobjectdtodict) |

## PaginatedResultMyObjectDtoDictInput
```
type: typing.TypedDict
```
Key | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**count** | int | |
**results** | [ResultsTupleInput](#resultstupleinput), [ResultsTuple](#resultstuple) | |

## PaginatedResultMyObjectDtoDict
```
base class: schemas.immutabledict[str, typing.Union[
typing.Tuple[schemas.OUTPUT_BASE_TYPES],
int,
]]
```
### __new__ method
Keyword Argument | Type | Description | Notes
---------------- | ---- | ----------- | -----
**count** | int | |
**results** | [ResultsTupleInput](#resultstupleinput), [ResultsTuple](#resultstuple) | |

### properties
Property | Type | Description | Notes
-------- | ---- | ----------- | -----
**count** | int | |
**results** | [ResultsTuple](#resultstuple) | |

### methods
Method | Input Type | Return Type | Notes
------ | ---------- | ----------- | ------
from_dict_ | [PaginatedResultMyObjectDtoDictInput](#paginatedresultmyobjectdtodictinput), [PaginatedResultMyObjectDtoDict](#paginatedresultmyobjectdtodict) | [PaginatedResultMyObjectDtoDict](#paginatedresultmyobjectdtodict) | a constructor

# Results
```
type: schemas.Schema
```

## validate method
Input Type | Return Type | Notes
------------ | ------------- | -------------
[ResultsTupleInput](#resultstupleinput), [ResultsTuple](#resultstuple) | [ResultsTuple](#resultstuple) |

## ResultsTupleInput
```
type: typing.Union[
typing.List[
typing.Union[
my_object_dto.MyObjectDtoDictInput,
my_object_dto.MyObjectDtoDict,
],
],
typing.Tuple[
typing.Union[
my_object_dto.MyObjectDtoDictInput,
my_object_dto.MyObjectDtoDict,
],
...
]
]
```
List/Tuple Item Type | Description | Notes
-------------------- | ------------- | -------------
[my_object_dto.MyObjectDtoDictInput](../../components/schema/my_object_dto.md#myobjectdtodictinput), [my_object_dto.MyObjectDtoDict](../../components/schema/my_object_dto.md#myobjectdtodict) | |

## ResultsTuple
```
base class: typing.Tuple[
my_object_dto.MyObjectDtoDict,
...
]
```
### __new__ method
Argument | Type
-------- | ------
arg | [ResultsTupleInput](#resultstupleinput), [ResultsTuple](#resultstuple)
configuration | typing.Optional[schema_configuration.SchemaConfiguration] = None

### methods
Method | Input Type | Return Type | Notes
------ | ---------- | ----------- | ------
__getitem__ | int | [my_object_dto.MyObjectDtoDict](../../components/schema/my_object_dto.md#myobjectdtodict) | This method is used under the hood when instance[0] is called

[[Back to top]](#top) [[Back to Component Schemas]](../../../README.md#Component-Schemas) [[Back to README]](../../../README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BAS
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)
return self.get(name, schemas.unset)
AbstractStepMessageDictInput = typing.Mapping[str, schemas.INPUT_TYPES_ALL]
AnyOf = typing.Tuple[
typing.Type['AbstractStepMessage'],
]


@dataclasses.dataclass(frozen=True)
Expand Down Expand Up @@ -133,6 +136,3 @@ def validate(
configuration=configuration,
)

AnyOf = typing.Tuple[
typing.Type[AbstractStepMessage],
]
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ def validate(
)


from petstore_api.components.schema import animal
AllOf = typing.Tuple[
typing.Type[animal.Animal],
typing.Type[_1],
]


@dataclasses.dataclass(frozen=True)
class Cat(
Expand All @@ -117,9 +123,3 @@ class Cat(
# any type
all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore


from petstore_api.components.schema import animal
AllOf = typing.Tuple[
typing.Type[animal.Animal],
typing.Type[_1],
]
Loading

0 comments on commit 9a73df4

Please sign in to comment.