Skip to content

Commit

Permalink
Change dict to list
Browse files Browse the repository at this point in the history
  • Loading branch information
sidpan1 committed May 23, 2024
1 parent 92288b7 commit 1ea2f4b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,4 @@ setup.cfg
setup.py
test-requirements.txt
test/__init__.py
test/test_resource_catalog_service_api.py
test/test_service_catalog_service_api.py
tox.ini
2 changes: 1 addition & 1 deletion docs/ServiceCatalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Name | Type | Description | Notes
**product_code** | **str** | |
**display_name** | **str** | |
**description** | **str** | |
**resource_types** | [**Dict[str, ResourceTypes]**](ResourceTypes.md) | |
**resource_types** | [**List[ResourceTypes]**](ResourceTypes.md) | |
**features** | [**Features**](Features.md) | |

## Example
Expand Down
10 changes: 9 additions & 1 deletion onelens_backend_client/models/service_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ServiceCatalog(BaseModel):
product_code: StrictStr
display_name: StrictStr
description: StrictStr
resource_types: Dict[str, ResourceTypes]
resource_types: List[ResourceTypes]
features: Features
__properties: ClassVar[List[str]] = ["id", "name", "product_code", "display_name", "description", "resource_types", "features"]

Expand Down Expand Up @@ -76,6 +76,13 @@ def to_dict(self) -> Dict[str, Any]:
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of each item in resource_types (list)
_items = []
if self.resource_types:
for _item in self.resource_types:
if _item:
_items.append(_item.to_dict())
_dict['resource_types'] = _items
# override the default output from pydantic by calling `to_dict()` of features
if self.features:
_dict['features'] = self.features.to_dict()
Expand All @@ -96,6 +103,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"product_code": obj.get("product_code"),
"display_name": obj.get("display_name"),
"description": obj.get("description"),
"resource_types": [ResourceTypes.from_dict(_item) for _item in obj["resource_types"]] if obj.get("resource_types") is not None else None,
"features": Features.from_dict(obj["features"]) if obj.get("features") is not None else None
})
return _obj
Expand Down

0 comments on commit 1ea2f4b

Please sign in to comment.