Skip to content

Commit

Permalink
[python] mypy test for multiple arrays of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
VelorumS committed Jul 23, 2024
1 parent 95b5597 commit 12ae860
Show file tree
Hide file tree
Showing 29 changed files with 801 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,18 @@ components:
enum:
- fish
- crab
MultiArrays:
type: object
properties:
tags:
type: array
items:
$ref: '#/components/schemas/Tag'
files:
type: array
description: Another array of objects in addition to tags (mypy check to not to reuse the same iterator)
items:
$ref: '#/components/schemas/File'
FreeFormObject:
type: object
description: A schema consisting only of additional properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ docs/Model200Response.md
docs/ModelApiResponse.md
docs/ModelField.md
docs/ModelReturn.md
docs/MultiArrays.md
docs/Name.md
docs/NullableClass.md
docs/NullableProperty.md
Expand Down Expand Up @@ -188,6 +189,7 @@ petstore_api/models/model200_response.py
petstore_api/models/model_api_response.py
petstore_api/models/model_field.py
petstore_api/models/model_return.py
petstore_api/models/multi_arrays.py
petstore_api/models/name.py
petstore_api/models/nullable_class.py
petstore_api/models/nullable_property.py
Expand Down
1 change: 1 addition & 0 deletions samples/openapi3/client/petstore/python-aiohttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ Class | Method | HTTP request | Description
- [ModelApiResponse](docs/ModelApiResponse.md)
- [ModelField](docs/ModelField.md)
- [ModelReturn](docs/ModelReturn.md)
- [MultiArrays](docs/MultiArrays.md)
- [Name](docs/Name.md)
- [NullableClass](docs/NullableClass.md)
- [NullableProperty](docs/NullableProperty.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# MultiArrays


## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**tags** | [**List[Tag]**](Tag.md) | | [optional]
**files** | [**List[File]**](File.md) | Another array of objects in addition to tags (mypy check to not to reuse the same iterator) | [optional]

## Example

```python
from petstore_api.models.multi_arrays import MultiArrays

# TODO update the JSON string below
json = "{}"
# create an instance of MultiArrays from a JSON string
multi_arrays_instance = MultiArrays.from_json(json)
# print the JSON string representation of the object
print(MultiArrays.to_json())

# convert the object into a dict
multi_arrays_dict = multi_arrays_instance.to_dict()
# create an instance of MultiArrays from a dict
multi_arrays_from_dict = MultiArrays.from_dict(multi_arrays_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)


Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
from petstore_api.models.model_api_response import ModelApiResponse
from petstore_api.models.model_field import ModelField
from petstore_api.models.model_return import ModelReturn
from petstore_api.models.multi_arrays import MultiArrays
from petstore_api.models.name import Name
from petstore_api.models.nullable_class import NullableClass
from petstore_api.models.nullable_property import NullableProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
from petstore_api.models.model_api_response import ModelApiResponse
from petstore_api.models.model_field import ModelField
from petstore_api.models.model_return import ModelReturn
from petstore_api.models.multi_arrays import MultiArrays
from petstore_api.models.name import Name
from petstore_api.models.nullable_class import NullableClass
from petstore_api.models.nullable_property import NullableProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# 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: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501


from __future__ import annotations
import pprint
import re # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field
from typing import Any, ClassVar, Dict, List, Optional
from petstore_api.models.file import File
from petstore_api.models.tag import Tag
from typing import Optional, Set
from typing_extensions import Self

class MultiArrays(BaseModel):
"""
MultiArrays
""" # noqa: E501
tags: Optional[List[Tag]] = None
files: Optional[List[File]] = Field(default=None, description="Another array of objects in addition to tags (mypy check to not to reuse the same iterator)")
__properties: ClassVar[List[str]] = ["tags", "files"]

model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)


def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))

def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of MultiArrays from a JSON string"""
return cls.from_dict(json.loads(json_str))

def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([
])

_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of each item in tags (list)
_items = []
if self.tags:
for _item_tags in self.tags:
if _item_tags:
_items.append(_item_tags.to_dict())
_dict['tags'] = _items
# override the default output from pydantic by calling `to_dict()` of each item in files (list)
_items = []
if self.files:
for _item_files in self.files:
if _item_files:
_items.append(_item_files.to_dict())
_dict['files'] = _items
return _dict

@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of MultiArrays from a dict"""
if obj is None:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)

_obj = cls.model_validate({
"tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None,
"files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None
})
return _obj


Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501


import unittest

from petstore_api.models.multi_arrays import MultiArrays

class TestMultiArrays(unittest.TestCase):
"""MultiArrays unit test stubs"""

def setUp(self):
pass

def tearDown(self):
pass

def make_instance(self, include_optional) -> MultiArrays:
"""Test MultiArrays
include_optional 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 `MultiArrays`
"""
model = MultiArrays()
if include_optional:
return MultiArrays(
tags = [
petstore_api.models.tag.Tag(
id = 56,
name = '', )
],
files = [
petstore_api.models.file.File(
source_uri = '', )
]
)
else:
return MultiArrays(
)
"""

def testMultiArrays(self):
"""Test MultiArrays"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ docs/MapTest.md
docs/MixedPropertiesAndAdditionalPropertiesClass.md
docs/Model200Response.md
docs/ModelReturn.md
docs/MultiArrays.md
docs/Name.md
docs/NullableClass.md
docs/NullableProperty.md
Expand Down Expand Up @@ -188,6 +189,7 @@ petstore_api/models/map_test.py
petstore_api/models/mixed_properties_and_additional_properties_class.py
petstore_api/models/model200_response.py
petstore_api/models/model_return.py
petstore_api/models/multi_arrays.py
petstore_api/models/name.py
petstore_api/models/nullable_class.py
petstore_api/models/nullable_property.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Class | Method | HTTP request | Description
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
- [Model200Response](docs/Model200Response.md)
- [ModelReturn](docs/ModelReturn.md)
- [MultiArrays](docs/MultiArrays.md)
- [Name](docs/Name.md)
- [NullableClass](docs/NullableClass.md)
- [NullableProperty](docs/NullableProperty.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# MultiArrays


## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**tags** | [**List[Tag]**](Tag.md) | | [optional]
**files** | [**List[File]**](File.md) | Another array of objects in addition to tags (mypy check to not to reuse the same iterator) | [optional]

## Example

```python
from petstore_api.models.multi_arrays import MultiArrays

# TODO update the JSON string below
json = "{}"
# create an instance of MultiArrays from a JSON string
multi_arrays_instance = MultiArrays.from_json(json)
# print the JSON string representation of the object
print MultiArrays.to_json()

# convert the object into a dict
multi_arrays_dict = multi_arrays_instance.to_dict()
# create an instance of MultiArrays from a dict
multi_arrays_from_dict = MultiArrays.from_dict(multi_arrays_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)


Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
from petstore_api.models.model200_response import Model200Response
from petstore_api.models.model_return import ModelReturn
from petstore_api.models.multi_arrays import MultiArrays
from petstore_api.models.name import Name
from petstore_api.models.nullable_class import NullableClass
from petstore_api.models.nullable_property import NullableProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
from petstore_api.models.model200_response import Model200Response
from petstore_api.models.model_return import ModelReturn
from petstore_api.models.multi_arrays import MultiArrays
from petstore_api.models.name import Name
from petstore_api.models.nullable_class import NullableClass
from petstore_api.models.nullable_property import NullableProperty
Expand Down
Loading

0 comments on commit 12ae860

Please sign in to comment.