forked from loafle/openapi-generator-original
[python] Fix array of array of model's to_dict, from_dict (#16032)
* fix array of array of model's to_dict, from_dict * update samples
This commit is contained in:
parent
83a12779fa
commit
08c3f8973e
@ -138,6 +138,20 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
|
|||||||
{{#allVars}}
|
{{#allVars}}
|
||||||
{{#isContainer}}
|
{{#isContainer}}
|
||||||
{{#isArray}}
|
{{#isArray}}
|
||||||
|
{{#items.isArray}}
|
||||||
|
{{^items.items.isPrimitiveType}}
|
||||||
|
# override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list of list)
|
||||||
|
_items = []
|
||||||
|
if self.{{{name}}}:
|
||||||
|
for _item in self.{{{name}}}:
|
||||||
|
if _item:
|
||||||
|
_items.append(
|
||||||
|
[_inner_item.to_dict() for _inner_item in _item if _inner_item is not None]
|
||||||
|
)
|
||||||
|
_dict['{{{baseName}}}'] = _items
|
||||||
|
{{/items.items.isPrimitiveType}}
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{^items.isArray}}
|
||||||
{{^items.isPrimitiveType}}
|
{{^items.isPrimitiveType}}
|
||||||
{{^items.isEnumOrRef}}
|
{{^items.isEnumOrRef}}
|
||||||
# override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list)
|
# override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list)
|
||||||
@ -149,6 +163,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
|
|||||||
_dict['{{{baseName}}}'] = _items
|
_dict['{{{baseName}}}'] = _items
|
||||||
{{/items.isEnumOrRef}}
|
{{/items.isEnumOrRef}}
|
||||||
{{/items.isPrimitiveType}}
|
{{/items.isPrimitiveType}}
|
||||||
|
{{/items.isArray}}
|
||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
{{#isMap}}
|
{{#isMap}}
|
||||||
{{#items.isArray}}
|
{{#items.isArray}}
|
||||||
@ -241,6 +256,18 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
|
|||||||
{{#allVars}}
|
{{#allVars}}
|
||||||
{{#isContainer}}
|
{{#isContainer}}
|
||||||
{{#isArray}}
|
{{#isArray}}
|
||||||
|
{{#items.isArray}}
|
||||||
|
{{#items.items.isPrimitiveType}}
|
||||||
|
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
||||||
|
{{/items.items.isPrimitiveType}}
|
||||||
|
{{^items.items.isPrimitiveType}}
|
||||||
|
"{{{name}}}": [
|
||||||
|
[{{{items.items.dataType}}}.from_dict(_inner_item) for _inner_item in _item]
|
||||||
|
for _item in obj.get("{{{baseName}}}")
|
||||||
|
] if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
|
||||||
|
{{/items.items.isPrimitiveType}}
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{^items.isArray}}
|
||||||
{{^items.isPrimitiveType}}
|
{{^items.isPrimitiveType}}
|
||||||
{{#items.isEnumOrRef}}
|
{{#items.isEnumOrRef}}
|
||||||
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
||||||
@ -252,6 +279,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
|
|||||||
{{#items.isPrimitiveType}}
|
{{#items.isPrimitiveType}}
|
||||||
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
|
||||||
{{/items.isPrimitiveType}}
|
{{/items.isPrimitiveType}}
|
||||||
|
{{/items.isArray}}
|
||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
{{#isMap}}
|
{{#isMap}}
|
||||||
{{^items.isPrimitiveType}}
|
{{^items.isPrimitiveType}}
|
||||||
|
@ -2220,4 +2220,13 @@ components:
|
|||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "#/components/schemas/Tag"
|
$ref: "#/components/schemas/Tag"
|
||||||
|
ArrayOfArrayOfModel:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
another_property:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/Tag"
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ docs/AnotherFakeApi.md
|
|||||||
docs/AnyOfColor.md
|
docs/AnyOfColor.md
|
||||||
docs/AnyOfPig.md
|
docs/AnyOfPig.md
|
||||||
docs/ApiResponse.md
|
docs/ApiResponse.md
|
||||||
|
docs/ArrayOfArrayOfModel.md
|
||||||
docs/ArrayOfArrayOfNumberOnly.md
|
docs/ArrayOfArrayOfNumberOnly.md
|
||||||
docs/ArrayOfNumberOnly.md
|
docs/ArrayOfNumberOnly.md
|
||||||
docs/ArrayTest.md
|
docs/ArrayTest.md
|
||||||
@ -100,6 +101,7 @@ petstore_api/models/animal.py
|
|||||||
petstore_api/models/any_of_color.py
|
petstore_api/models/any_of_color.py
|
||||||
petstore_api/models/any_of_pig.py
|
petstore_api/models/any_of_pig.py
|
||||||
petstore_api/models/api_response.py
|
petstore_api/models/api_response.py
|
||||||
|
petstore_api/models/array_of_array_of_model.py
|
||||||
petstore_api/models/array_of_array_of_number_only.py
|
petstore_api/models/array_of_array_of_number_only.py
|
||||||
petstore_api/models/array_of_number_only.py
|
petstore_api/models/array_of_number_only.py
|
||||||
petstore_api/models/array_test.py
|
petstore_api/models/array_test.py
|
||||||
|
@ -138,6 +138,7 @@ Class | Method | HTTP request | Description
|
|||||||
- [AnyOfColor](docs/AnyOfColor.md)
|
- [AnyOfColor](docs/AnyOfColor.md)
|
||||||
- [AnyOfPig](docs/AnyOfPig.md)
|
- [AnyOfPig](docs/AnyOfPig.md)
|
||||||
- [ApiResponse](docs/ApiResponse.md)
|
- [ApiResponse](docs/ApiResponse.md)
|
||||||
|
- [ArrayOfArrayOfModel](docs/ArrayOfArrayOfModel.md)
|
||||||
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
|
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
|
||||||
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
|
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
|
||||||
- [ArrayTest](docs/ArrayTest.md)
|
- [ArrayTest](docs/ArrayTest.md)
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
# ArrayOfArrayOfModel
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**another_property** | **List[List[Tag]]** | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of ArrayOfArrayOfModel from a JSON string
|
||||||
|
array_of_array_of_model_instance = ArrayOfArrayOfModel.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print ArrayOfArrayOfModel.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
array_of_array_of_model_dict = array_of_array_of_model_instance.to_dict()
|
||||||
|
# create an instance of ArrayOfArrayOfModel from a dict
|
||||||
|
array_of_array_of_model_form_dict = array_of_array_of_model.from_dict(array_of_array_of_model_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
@ -44,6 +44,7 @@ from petstore_api.models.animal import Animal
|
|||||||
from petstore_api.models.any_of_color import AnyOfColor
|
from petstore_api.models.any_of_color import AnyOfColor
|
||||||
from petstore_api.models.any_of_pig import AnyOfPig
|
from petstore_api.models.any_of_pig import AnyOfPig
|
||||||
from petstore_api.models.api_response import ApiResponse
|
from petstore_api.models.api_response import ApiResponse
|
||||||
|
from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel
|
||||||
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
|
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
|
||||||
from petstore_api.models.array_of_number_only import ArrayOfNumberOnly
|
from petstore_api.models.array_of_number_only import ArrayOfNumberOnly
|
||||||
from petstore_api.models.array_test import ArrayTest
|
from petstore_api.models.array_test import ArrayTest
|
||||||
|
@ -20,6 +20,7 @@ from petstore_api.models.animal import Animal
|
|||||||
from petstore_api.models.any_of_color import AnyOfColor
|
from petstore_api.models.any_of_color import AnyOfColor
|
||||||
from petstore_api.models.any_of_pig import AnyOfPig
|
from petstore_api.models.any_of_pig import AnyOfPig
|
||||||
from petstore_api.models.api_response import ApiResponse
|
from petstore_api.models.api_response import ApiResponse
|
||||||
|
from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel
|
||||||
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
|
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
|
||||||
from petstore_api.models.array_of_number_only import ArrayOfNumberOnly
|
from petstore_api.models.array_of_number_only import ArrayOfNumberOnly
|
||||||
from petstore_api.models.array_test import ArrayTest
|
from petstore_api.models.array_test import ArrayTest
|
||||||
|
@ -0,0 +1,83 @@
|
|||||||
|
# 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 OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import List, Optional
|
||||||
|
from pydantic import BaseModel, conlist
|
||||||
|
from petstore_api.models.tag import Tag
|
||||||
|
|
||||||
|
class ArrayOfArrayOfModel(BaseModel):
|
||||||
|
"""
|
||||||
|
ArrayOfArrayOfModel
|
||||||
|
"""
|
||||||
|
another_property: Optional[conlist(conlist(Tag))] = None
|
||||||
|
__properties = ["another_property"]
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> ArrayOfArrayOfModel:
|
||||||
|
"""Create an instance of ArrayOfArrayOfModel from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
# override the default output from pydantic by calling `to_dict()` of each item in another_property (list of list)
|
||||||
|
_items = []
|
||||||
|
if self.another_property:
|
||||||
|
for _item in self.another_property:
|
||||||
|
if _item:
|
||||||
|
_items.append(
|
||||||
|
[_inner_item.to_dict() for _inner_item in _item if _inner_item is not None]
|
||||||
|
)
|
||||||
|
_dict['another_property'] = _items
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> ArrayOfArrayOfModel:
|
||||||
|
"""Create an instance of ArrayOfArrayOfModel from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return ArrayOfArrayOfModel.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = ArrayOfArrayOfModel.parse_obj({
|
||||||
|
"another_property": [
|
||||||
|
[Tag.from_dict(_inner_item) for _inner_item in _item]
|
||||||
|
for _item in obj.get("another_property")
|
||||||
|
] if obj.get("another_property") is not None else None
|
||||||
|
})
|
||||||
|
return _obj
|
||||||
|
|
@ -55,12 +55,14 @@ class ArrayTest(BaseModel):
|
|||||||
exclude={
|
exclude={
|
||||||
},
|
},
|
||||||
exclude_none=True)
|
exclude_none=True)
|
||||||
# override the default output from pydantic by calling `to_dict()` of each item in array_array_of_model (list)
|
# override the default output from pydantic by calling `to_dict()` of each item in array_array_of_model (list of list)
|
||||||
_items = []
|
_items = []
|
||||||
if self.array_array_of_model:
|
if self.array_array_of_model:
|
||||||
for _item in self.array_array_of_model:
|
for _item in self.array_array_of_model:
|
||||||
if _item:
|
if _item:
|
||||||
_items.append(_item.to_dict())
|
_items.append(
|
||||||
|
[_inner_item.to_dict() for _inner_item in _item if _inner_item is not None]
|
||||||
|
)
|
||||||
_dict['array_array_of_model'] = _items
|
_dict['array_array_of_model'] = _items
|
||||||
return _dict
|
return _dict
|
||||||
|
|
||||||
@ -76,7 +78,10 @@ class ArrayTest(BaseModel):
|
|||||||
_obj = ArrayTest.parse_obj({
|
_obj = ArrayTest.parse_obj({
|
||||||
"array_of_string": obj.get("array_of_string"),
|
"array_of_string": obj.get("array_of_string"),
|
||||||
"array_array_of_integer": obj.get("array_array_of_integer"),
|
"array_array_of_integer": obj.get("array_array_of_integer"),
|
||||||
"array_array_of_model": [List[ReadOnlyFirst].from_dict(_item) for _item in obj.get("array_array_of_model")] if obj.get("array_array_of_model") is not None else None
|
"array_array_of_model": [
|
||||||
|
[ReadOnlyFirst.from_dict(_inner_item) for _inner_item in _item]
|
||||||
|
for _item in obj.get("array_array_of_model")
|
||||||
|
] if obj.get("array_array_of_model") is not None else None
|
||||||
})
|
})
|
||||||
return _obj
|
return _obj
|
||||||
|
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
# 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 OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
import petstore_api
|
||||||
|
from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel # noqa: E501
|
||||||
|
from petstore_api.rest import ApiException
|
||||||
|
|
||||||
|
class TestArrayOfArrayOfModel(unittest.TestCase):
|
||||||
|
"""ArrayOfArrayOfModel unit test stubs"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def make_instance(self, include_optional):
|
||||||
|
"""Test ArrayOfArrayOfModel
|
||||||
|
include_option is a boolean, when False only required
|
||||||
|
params are included, when True both required and
|
||||||
|
optional params are included """
|
||||||
|
# uncomment below to create an instance of `ArrayOfArrayOfModel`
|
||||||
|
"""
|
||||||
|
model = petstore_api.models.array_of_array_of_model.ArrayOfArrayOfModel() # noqa: E501
|
||||||
|
if include_optional :
|
||||||
|
return ArrayOfArrayOfModel(
|
||||||
|
another_property = [
|
||||||
|
[
|
||||||
|
petstore_api.models.tag.Tag(
|
||||||
|
id = 56,
|
||||||
|
name = '', )
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
else :
|
||||||
|
return ArrayOfArrayOfModel(
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def testArrayOfArrayOfModel(self):
|
||||||
|
"""Test ArrayOfArrayOfModel"""
|
||||||
|
# inst_req_only = self.make_instance(include_optional=False)
|
||||||
|
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
@ -10,6 +10,7 @@ docs/AnotherFakeApi.md
|
|||||||
docs/AnyOfColor.md
|
docs/AnyOfColor.md
|
||||||
docs/AnyOfPig.md
|
docs/AnyOfPig.md
|
||||||
docs/ApiResponse.md
|
docs/ApiResponse.md
|
||||||
|
docs/ArrayOfArrayOfModel.md
|
||||||
docs/ArrayOfArrayOfNumberOnly.md
|
docs/ArrayOfArrayOfNumberOnly.md
|
||||||
docs/ArrayOfNumberOnly.md
|
docs/ArrayOfNumberOnly.md
|
||||||
docs/ArrayTest.md
|
docs/ArrayTest.md
|
||||||
@ -100,6 +101,7 @@ petstore_api/models/animal.py
|
|||||||
petstore_api/models/any_of_color.py
|
petstore_api/models/any_of_color.py
|
||||||
petstore_api/models/any_of_pig.py
|
petstore_api/models/any_of_pig.py
|
||||||
petstore_api/models/api_response.py
|
petstore_api/models/api_response.py
|
||||||
|
petstore_api/models/array_of_array_of_model.py
|
||||||
petstore_api/models/array_of_array_of_number_only.py
|
petstore_api/models/array_of_array_of_number_only.py
|
||||||
petstore_api/models/array_of_number_only.py
|
petstore_api/models/array_of_number_only.py
|
||||||
petstore_api/models/array_test.py
|
petstore_api/models/array_test.py
|
||||||
|
@ -138,6 +138,7 @@ Class | Method | HTTP request | Description
|
|||||||
- [AnyOfColor](docs/AnyOfColor.md)
|
- [AnyOfColor](docs/AnyOfColor.md)
|
||||||
- [AnyOfPig](docs/AnyOfPig.md)
|
- [AnyOfPig](docs/AnyOfPig.md)
|
||||||
- [ApiResponse](docs/ApiResponse.md)
|
- [ApiResponse](docs/ApiResponse.md)
|
||||||
|
- [ArrayOfArrayOfModel](docs/ArrayOfArrayOfModel.md)
|
||||||
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
|
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
|
||||||
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
|
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
|
||||||
- [ArrayTest](docs/ArrayTest.md)
|
- [ArrayTest](docs/ArrayTest.md)
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
# ArrayOfArrayOfModel
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**another_property** | **List[List[Tag]]** | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of ArrayOfArrayOfModel from a JSON string
|
||||||
|
array_of_array_of_model_instance = ArrayOfArrayOfModel.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print ArrayOfArrayOfModel.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
array_of_array_of_model_dict = array_of_array_of_model_instance.to_dict()
|
||||||
|
# create an instance of ArrayOfArrayOfModel from a dict
|
||||||
|
array_of_array_of_model_form_dict = array_of_array_of_model.from_dict(array_of_array_of_model_dict)
|
||||||
|
```
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
@ -44,6 +44,7 @@ from petstore_api.models.animal import Animal
|
|||||||
from petstore_api.models.any_of_color import AnyOfColor
|
from petstore_api.models.any_of_color import AnyOfColor
|
||||||
from petstore_api.models.any_of_pig import AnyOfPig
|
from petstore_api.models.any_of_pig import AnyOfPig
|
||||||
from petstore_api.models.api_response import ApiResponse
|
from petstore_api.models.api_response import ApiResponse
|
||||||
|
from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel
|
||||||
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
|
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
|
||||||
from petstore_api.models.array_of_number_only import ArrayOfNumberOnly
|
from petstore_api.models.array_of_number_only import ArrayOfNumberOnly
|
||||||
from petstore_api.models.array_test import ArrayTest
|
from petstore_api.models.array_test import ArrayTest
|
||||||
|
@ -20,6 +20,7 @@ from petstore_api.models.animal import Animal
|
|||||||
from petstore_api.models.any_of_color import AnyOfColor
|
from petstore_api.models.any_of_color import AnyOfColor
|
||||||
from petstore_api.models.any_of_pig import AnyOfPig
|
from petstore_api.models.any_of_pig import AnyOfPig
|
||||||
from petstore_api.models.api_response import ApiResponse
|
from petstore_api.models.api_response import ApiResponse
|
||||||
|
from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel
|
||||||
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
|
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
|
||||||
from petstore_api.models.array_of_number_only import ArrayOfNumberOnly
|
from petstore_api.models.array_of_number_only import ArrayOfNumberOnly
|
||||||
from petstore_api.models.array_test import ArrayTest
|
from petstore_api.models.array_test import ArrayTest
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
# 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 OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import List, Optional
|
||||||
|
from pydantic import BaseModel, conlist
|
||||||
|
from petstore_api.models.tag import Tag
|
||||||
|
|
||||||
|
class ArrayOfArrayOfModel(BaseModel):
|
||||||
|
"""
|
||||||
|
ArrayOfArrayOfModel
|
||||||
|
"""
|
||||||
|
another_property: Optional[conlist(conlist(Tag))] = None
|
||||||
|
additional_properties: Dict[str, Any] = {}
|
||||||
|
__properties = ["another_property"]
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Pydantic configuration"""
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
validate_assignment = True
|
||||||
|
|
||||||
|
def to_str(self) -> str:
|
||||||
|
"""Returns the string representation of the model using alias"""
|
||||||
|
return pprint.pformat(self.dict(by_alias=True))
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
"""Returns the JSON representation of the model using alias"""
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(cls, json_str: str) -> ArrayOfArrayOfModel:
|
||||||
|
"""Create an instance of ArrayOfArrayOfModel from a JSON string"""
|
||||||
|
return cls.from_dict(json.loads(json_str))
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""Returns the dictionary representation of the model using alias"""
|
||||||
|
_dict = self.dict(by_alias=True,
|
||||||
|
exclude={
|
||||||
|
"additional_properties"
|
||||||
|
},
|
||||||
|
exclude_none=True)
|
||||||
|
# override the default output from pydantic by calling `to_dict()` of each item in another_property (list of list)
|
||||||
|
_items = []
|
||||||
|
if self.another_property:
|
||||||
|
for _item in self.another_property:
|
||||||
|
if _item:
|
||||||
|
_items.append(
|
||||||
|
[_inner_item.to_dict() for _inner_item in _item if _inner_item is not None]
|
||||||
|
)
|
||||||
|
_dict['another_property'] = _items
|
||||||
|
# puts key-value pairs in additional_properties in the top level
|
||||||
|
if self.additional_properties is not None:
|
||||||
|
for _key, _value in self.additional_properties.items():
|
||||||
|
_dict[_key] = _value
|
||||||
|
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> ArrayOfArrayOfModel:
|
||||||
|
"""Create an instance of ArrayOfArrayOfModel from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
return ArrayOfArrayOfModel.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = ArrayOfArrayOfModel.parse_obj({
|
||||||
|
"another_property": [
|
||||||
|
[Tag.from_dict(_inner_item) for _inner_item in _item]
|
||||||
|
for _item in obj.get("another_property")
|
||||||
|
] if obj.get("another_property") is not None else None
|
||||||
|
})
|
||||||
|
# store additional fields in additional_properties
|
||||||
|
for _key in obj.keys():
|
||||||
|
if _key not in cls.__properties:
|
||||||
|
_obj.additional_properties[_key] = obj.get(_key)
|
||||||
|
|
||||||
|
return _obj
|
||||||
|
|
@ -57,12 +57,14 @@ class ArrayTest(BaseModel):
|
|||||||
"additional_properties"
|
"additional_properties"
|
||||||
},
|
},
|
||||||
exclude_none=True)
|
exclude_none=True)
|
||||||
# override the default output from pydantic by calling `to_dict()` of each item in array_array_of_model (list)
|
# override the default output from pydantic by calling `to_dict()` of each item in array_array_of_model (list of list)
|
||||||
_items = []
|
_items = []
|
||||||
if self.array_array_of_model:
|
if self.array_array_of_model:
|
||||||
for _item in self.array_array_of_model:
|
for _item in self.array_array_of_model:
|
||||||
if _item:
|
if _item:
|
||||||
_items.append(_item.to_dict())
|
_items.append(
|
||||||
|
[_inner_item.to_dict() for _inner_item in _item if _inner_item is not None]
|
||||||
|
)
|
||||||
_dict['array_array_of_model'] = _items
|
_dict['array_array_of_model'] = _items
|
||||||
# puts key-value pairs in additional_properties in the top level
|
# puts key-value pairs in additional_properties in the top level
|
||||||
if self.additional_properties is not None:
|
if self.additional_properties is not None:
|
||||||
@ -83,7 +85,10 @@ class ArrayTest(BaseModel):
|
|||||||
_obj = ArrayTest.parse_obj({
|
_obj = ArrayTest.parse_obj({
|
||||||
"array_of_string": obj.get("array_of_string"),
|
"array_of_string": obj.get("array_of_string"),
|
||||||
"array_array_of_integer": obj.get("array_array_of_integer"),
|
"array_array_of_integer": obj.get("array_array_of_integer"),
|
||||||
"array_array_of_model": [List[ReadOnlyFirst].from_dict(_item) for _item in obj.get("array_array_of_model")] if obj.get("array_array_of_model") is not None else None
|
"array_array_of_model": [
|
||||||
|
[ReadOnlyFirst.from_dict(_inner_item) for _inner_item in _item]
|
||||||
|
for _item in obj.get("array_array_of_model")
|
||||||
|
] if obj.get("array_array_of_model") is not None else None
|
||||||
})
|
})
|
||||||
# store additional fields in additional_properties
|
# store additional fields in additional_properties
|
||||||
for _key in obj.keys():
|
for _key in obj.keys():
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
# 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 OpenAPI Generator (https://openapi-generator.tech)
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
import petstore_api
|
||||||
|
from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel # noqa: E501
|
||||||
|
from petstore_api.rest import ApiException
|
||||||
|
|
||||||
|
class TestArrayOfArrayOfModel(unittest.TestCase):
|
||||||
|
"""ArrayOfArrayOfModel unit test stubs"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def make_instance(self, include_optional):
|
||||||
|
"""Test ArrayOfArrayOfModel
|
||||||
|
include_option is a boolean, when False only required
|
||||||
|
params are included, when True both required and
|
||||||
|
optional params are included """
|
||||||
|
# uncomment below to create an instance of `ArrayOfArrayOfModel`
|
||||||
|
"""
|
||||||
|
model = petstore_api.models.array_of_array_of_model.ArrayOfArrayOfModel() # noqa: E501
|
||||||
|
if include_optional :
|
||||||
|
return ArrayOfArrayOfModel(
|
||||||
|
shop_id_to_org_online_lip_map = [
|
||||||
|
[
|
||||||
|
petstore_api.models.tag.Tag(
|
||||||
|
id = 56,
|
||||||
|
name = '', )
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
else :
|
||||||
|
return ArrayOfArrayOfModel(
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def testArrayOfArrayOfModel(self):
|
||||||
|
"""Test ArrayOfArrayOfModel"""
|
||||||
|
# inst_req_only = self.make_instance(include_optional=False)
|
||||||
|
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
@ -492,3 +492,12 @@ class ModelTests(unittest.TestCase):
|
|||||||
self.assertEqual(a.to_json(), '{"shopIdToOrgOnlineLipMap": {"somekey": [{"id": 123, "name": "tag name"}]}}')
|
self.assertEqual(a.to_json(), '{"shopIdToOrgOnlineLipMap": {"somekey": [{"id": 123, "name": "tag name"}]}}')
|
||||||
a2 = petstore_api.MapOfArrayOfModel.from_dict(a.to_dict())
|
a2 = petstore_api.MapOfArrayOfModel.from_dict(a.to_dict())
|
||||||
self.assertEqual(a.to_dict(), a2.to_dict())
|
self.assertEqual(a.to_dict(), a2.to_dict())
|
||||||
|
|
||||||
|
def test_array_of_array_of_model(self):
|
||||||
|
a = petstore_api.ArrayOfArrayOfModel()
|
||||||
|
t = petstore_api.Tag(id=123, name="tag name")
|
||||||
|
a.another_property = [[t]]
|
||||||
|
self.assertEqual(a.to_dict(), {'another_property': [[ {'id': 123, 'name': 'tag name'} ]]})
|
||||||
|
self.assertEqual(a.to_json(), '{"another_property": [[{"id": 123, "name": "tag name"}]]}')
|
||||||
|
a2 = petstore_api.ArrayOfArrayOfModel.from_dict(a.to_dict())
|
||||||
|
self.assertEqual(a.to_dict(), a2.to_dict())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user