Skip to content

Commit

Permalink
Merge d0a2e6e into 422e993
Browse files Browse the repository at this point in the history
  • Loading branch information
p1-ra committed Feb 21, 2021
2 parents 422e993 + d0a2e6e commit 2e28978
Show file tree
Hide file tree
Showing 6 changed files with 910 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Additions

- Add support of properties indirect reference ($ref) resolution; Add support of inner properties direct and indirect reference resolution to its owner model/enum (#329). Thanks @p1-ra!
- New `--meta` command line option for specifying what type of metadata should be generated:
- `poetry` is the default value, same behavior you're used to in previous versions
- `setup` will generate a pyproject.toml with no Poetry information, and instead create a `setup.py` with the
Expand Down
39 changes: 39 additions & 0 deletions end_to_end_tests/golden-record-custom/custom_e2e/models/a_model.py
Expand Up @@ -27,6 +27,9 @@ class AModel:
a_nullable_date: Optional[datetime.date]
required_nullable: Optional[str]
nullable_model: Optional[AModelNullableModel]
an_enum_indirect_ref: Union[Unset, AnEnum] = UNSET
direct_ref_to_itself: Union["AModel", Unset] = UNSET
indirect_ref_to_itself: Union["AModel", Unset] = UNSET
nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET
a_not_required_date: Union[Unset, datetime.date] = UNSET
attr_1_leading_digit: Union[Unset, str] = UNSET
Expand All @@ -48,6 +51,18 @@ def to_dict(self) -> Dict[str, Any]:
required_not_nullable = self.required_not_nullable
model = self.model.to_dict()

an_enum_indirect_ref: Union[Unset, AnEnum] = UNSET
if not isinstance(self.an_enum_indirect_ref, Unset):
an_enum_indirect_ref = self.an_enum_indirect_ref

direct_ref_to_itself: Union[Unset, Dict[str, Any]] = UNSET
if not isinstance(self.direct_ref_to_itself, Unset):
direct_ref_to_itself = self.direct_ref_to_itself.to_dict()

indirect_ref_to_itself: Union[Unset, Dict[str, Any]] = UNSET
if not isinstance(self.indirect_ref_to_itself, Unset):
indirect_ref_to_itself = self.indirect_ref_to_itself.to_dict()

nested_list_of_enums: Union[Unset, List[Any]] = UNSET
if not isinstance(self.nested_list_of_enums, Unset):
nested_list_of_enums = []
Expand Down Expand Up @@ -94,6 +109,12 @@ def to_dict(self) -> Dict[str, Any]:
"nullable_model": nullable_model,
}
)
if an_enum_indirect_ref is not UNSET:
field_dict["an_enum_indirect_ref"] = an_enum_indirect_ref
if direct_ref_to_itself is not UNSET:
field_dict["direct_ref_to_itself"] = direct_ref_to_itself
if indirect_ref_to_itself is not UNSET:
field_dict["indirect_ref_to_itself"] = indirect_ref_to_itself
if nested_list_of_enums is not UNSET:
field_dict["nested_list_of_enums"] = nested_list_of_enums
if a_not_required_date is not UNSET:
Expand Down Expand Up @@ -137,6 +158,21 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat

model = AModelModel.from_dict(d.pop("model"))

an_enum_indirect_ref: Union[Unset, AnEnum] = UNSET
_an_enum_indirect_ref = d.pop("an_enum_indirect_ref", UNSET)
if not isinstance(_an_enum_indirect_ref, Unset):
an_enum_indirect_ref = AnEnum(_an_enum_indirect_ref)

direct_ref_to_itself: Union[AModel, Unset] = UNSET
_direct_ref_to_itself = d.pop("direct_ref_to_itself", UNSET)
if not isinstance(_direct_ref_to_itself, Unset):
direct_ref_to_itself = AModel.from_dict(_direct_ref_to_itself)

indirect_ref_to_itself: Union[AModel, Unset] = UNSET
_indirect_ref_to_itself = d.pop("indirect_ref_to_itself", UNSET)
if not isinstance(_indirect_ref_to_itself, Unset):
indirect_ref_to_itself = AModel.from_dict(_indirect_ref_to_itself)

nested_list_of_enums = []
_nested_list_of_enums = d.pop("nested_list_of_enums", UNSET)
for nested_list_of_enums_item_data in _nested_list_of_enums or []:
Expand Down Expand Up @@ -188,6 +224,9 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat
a_date=a_date,
required_not_nullable=required_not_nullable,
model=model,
an_enum_indirect_ref=an_enum_indirect_ref,
direct_ref_to_itself=direct_ref_to_itself,
indirect_ref_to_itself=indirect_ref_to_itself,
nested_list_of_enums=nested_list_of_enums,
a_nullable_date=a_nullable_date,
a_not_required_date=a_not_required_date,
Expand Down
Expand Up @@ -27,6 +27,9 @@ class AModel:
a_nullable_date: Optional[datetime.date]
required_nullable: Optional[str]
nullable_model: Optional[AModelNullableModel]
an_enum_indirect_ref: Union[Unset, AnEnum] = UNSET
direct_ref_to_itself: Union["AModel", Unset] = UNSET
indirect_ref_to_itself: Union["AModel", Unset] = UNSET
nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET
a_not_required_date: Union[Unset, datetime.date] = UNSET
attr_1_leading_digit: Union[Unset, str] = UNSET
Expand All @@ -48,6 +51,18 @@ def to_dict(self) -> Dict[str, Any]:
required_not_nullable = self.required_not_nullable
model = self.model.to_dict()

an_enum_indirect_ref: Union[Unset, AnEnum] = UNSET
if not isinstance(self.an_enum_indirect_ref, Unset):
an_enum_indirect_ref = self.an_enum_indirect_ref

direct_ref_to_itself: Union[Unset, Dict[str, Any]] = UNSET
if not isinstance(self.direct_ref_to_itself, Unset):
direct_ref_to_itself = self.direct_ref_to_itself.to_dict()

indirect_ref_to_itself: Union[Unset, Dict[str, Any]] = UNSET
if not isinstance(self.indirect_ref_to_itself, Unset):
indirect_ref_to_itself = self.indirect_ref_to_itself.to_dict()

nested_list_of_enums: Union[Unset, List[Any]] = UNSET
if not isinstance(self.nested_list_of_enums, Unset):
nested_list_of_enums = []
Expand Down Expand Up @@ -94,6 +109,12 @@ def to_dict(self) -> Dict[str, Any]:
"nullable_model": nullable_model,
}
)
if an_enum_indirect_ref is not UNSET:
field_dict["an_enum_indirect_ref"] = an_enum_indirect_ref
if direct_ref_to_itself is not UNSET:
field_dict["direct_ref_to_itself"] = direct_ref_to_itself
if indirect_ref_to_itself is not UNSET:
field_dict["indirect_ref_to_itself"] = indirect_ref_to_itself
if nested_list_of_enums is not UNSET:
field_dict["nested_list_of_enums"] = nested_list_of_enums
if a_not_required_date is not UNSET:
Expand Down Expand Up @@ -137,6 +158,21 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat

model = AModelModel.from_dict(d.pop("model"))

an_enum_indirect_ref: Union[Unset, AnEnum] = UNSET
_an_enum_indirect_ref = d.pop("an_enum_indirect_ref", UNSET)
if not isinstance(_an_enum_indirect_ref, Unset):
an_enum_indirect_ref = AnEnum(_an_enum_indirect_ref)

direct_ref_to_itself: Union[AModel, Unset] = UNSET
_direct_ref_to_itself = d.pop("direct_ref_to_itself", UNSET)
if not isinstance(_direct_ref_to_itself, Unset):
direct_ref_to_itself = AModel.from_dict(_direct_ref_to_itself)

indirect_ref_to_itself: Union[AModel, Unset] = UNSET
_indirect_ref_to_itself = d.pop("indirect_ref_to_itself", UNSET)
if not isinstance(_indirect_ref_to_itself, Unset):
indirect_ref_to_itself = AModel.from_dict(_indirect_ref_to_itself)

nested_list_of_enums = []
_nested_list_of_enums = d.pop("nested_list_of_enums", UNSET)
for nested_list_of_enums_item_data in _nested_list_of_enums or []:
Expand Down Expand Up @@ -188,6 +224,9 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat
a_date=a_date,
required_not_nullable=required_not_nullable,
model=model,
an_enum_indirect_ref=an_enum_indirect_ref,
direct_ref_to_itself=direct_ref_to_itself,
indirect_ref_to_itself=indirect_ref_to_itself,
nested_list_of_enums=nested_list_of_enums,
a_nullable_date=a_nullable_date,
a_not_required_date=a_not_required_date,
Expand Down
23 changes: 22 additions & 1 deletion end_to_end_tests/openapi.json
Expand Up @@ -675,6 +675,15 @@
"required": ["an_enum_value", "aCamelDateTime", "a_date", "a_nullable_date", "required_nullable", "required_not_nullable", "model", "nullable_model"],
"type": "object",
"properties": {
"an_enum_indirect_ref": {
"$ref": "#/components/schemas/AnEnumDeeperIndirectReference"
},
"direct_ref_to_itself": {
"$ref": "#/components/schemas/AModel"
},
"indirect_ref_to_itself": {
"$ref": "#/components/schemas/AModelDeeperIndirectReference"
},
"an_enum_value": {
"$ref": "#/components/schemas/AnEnum"
},
Expand Down Expand Up @@ -716,7 +725,7 @@
"a_not_required_date": {
"title": "A Nullable Date",
"type": "string",
"format": "date",
"format": "date"
},
"1_leading_digit": {
"title": "Leading Digit",
Expand Down Expand Up @@ -782,11 +791,23 @@
"description": "A Model for testing all the ways custom objects can be used ",
"additionalProperties": false
},
"AModelIndirectReference": {
"$ref": "#/components/schemas/AModel"
},
"AModelDeeperIndirectReference": {
"$ref": "#/components/schemas/AModelIndirectReference"
},
"AnEnumIndirectReference": {
"$ref": "#/components/schemas/AnEnum"
},
"AnEnum": {
"title": "AnEnum",
"enum": ["FIRST_VALUE", "SECOND_VALUE"],
"description": "For testing Enums in all the ways they can be used "
},
"AnEnumDeeperIndirectReference": {
"$ref": "#/components/schemas/AnEnumIndirectReference"
},
"AnIntEnum": {
"title": "AnIntEnum",
"enum": [-1, 1, 2],
Expand Down

0 comments on commit 2e28978

Please sign in to comment.