add support for union of strictfloat and strictint (#15124)

This commit is contained in:
William Cheng
2023-04-06 11:51:12 +08:00
committed by GitHub
parent b409ceb3a0
commit 07227d4650
38 changed files with 1530 additions and 34 deletions

View File

@@ -11,6 +11,7 @@ docs/DataQueryAllOf.md
docs/DefaultValue.md
docs/FormApi.md
docs/HeaderApi.md
docs/NumberPropertiesOnly.md
docs/PathApi.md
docs/Pet.md
docs/Query.md
@@ -36,6 +37,7 @@ openapi_client/models/category.py
openapi_client/models/data_query.py
openapi_client/models/data_query_all_of.py
openapi_client/models/default_value.py
openapi_client/models/number_properties_only.py
openapi_client/models/pet.py
openapi_client/models/query.py
openapi_client/models/string_enum_ref.py

View File

@@ -107,6 +107,7 @@ Class | Method | HTTP request | Description
- [DataQuery](docs/DataQuery.md)
- [DataQueryAllOf](docs/DataQueryAllOf.md)
- [DefaultValue](docs/DefaultValue.md)
- [NumberPropertiesOnly](docs/NumberPropertiesOnly.md)
- [Pet](docs/Pet.md)
- [Query](docs/Query.md)
- [StringEnumRef](docs/StringEnumRef.md)

View File

@@ -0,0 +1,30 @@
# NumberPropertiesOnly
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**number** | **float** | | [optional]
**float** | **float** | | [optional]
**double** | **float** | | [optional]
## Example
```python
from openapi_client.models.number_properties_only import NumberPropertiesOnly
# TODO update the JSON string below
json = "{}"
# create an instance of NumberPropertiesOnly from a JSON string
number_properties_only_instance = NumberPropertiesOnly.from_json(json)
# print the JSON string representation of the object
print NumberPropertiesOnly.to_json()
# convert the object into a dict
number_properties_only_dict = number_properties_only_instance.to_dict()
# create an instance of NumberPropertiesOnly from a dict
number_properties_only_form_dict = number_properties_only.from_dict(number_properties_only_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)

View File

@@ -39,6 +39,7 @@ from openapi_client.models.category import Category
from openapi_client.models.data_query import DataQuery
from openapi_client.models.data_query_all_of import DataQueryAllOf
from openapi_client.models.default_value import DefaultValue
from openapi_client.models.number_properties_only import NumberPropertiesOnly
from openapi_client.models.pet import Pet
from openapi_client.models.query import Query
from openapi_client.models.string_enum_ref import StringEnumRef

View File

@@ -20,6 +20,7 @@ from openapi_client.models.category import Category
from openapi_client.models.data_query import DataQuery
from openapi_client.models.data_query_all_of import DataQueryAllOf
from openapi_client.models.default_value import DefaultValue
from openapi_client.models.number_properties_only import NumberPropertiesOnly
from openapi_client.models.pet import Pet
from openapi_client.models.query import Query
from openapi_client.models.string_enum_ref import StringEnumRef

View File

@@ -0,0 +1,75 @@
# coding: utf-8
"""
Echo Server API
Echo Server API # noqa: E501
The version of the OpenAPI document: 0.1.0
Contact: team@openapitools.org
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
"""
from __future__ import annotations
from inspect import getfullargspec
import pprint
import re # noqa: F401
import json
from typing import Optional, Union
from pydantic import BaseModel, StrictFloat, StrictInt, confloat, conint
class NumberPropertiesOnly(BaseModel):
"""
NumberPropertiesOnly
"""
number: Optional[Union[StrictFloat, StrictInt]] = None
float: Optional[Union[StrictFloat, StrictInt]] = None
double: Optional[Union[confloat(le=50.2, ge=0.8, strict=True), conint(le=50, ge=1, strict=True)]] = None
__properties = ["number", "float", "double"]
class Config:
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) -> NumberPropertiesOnly:
"""Create an instance of NumberPropertiesOnly 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)
return _dict
@classmethod
def from_dict(cls, obj: dict) -> NumberPropertiesOnly:
"""Create an instance of NumberPropertiesOnly from a dict"""
if obj is None:
return None
if type(obj) is not dict:
return NumberPropertiesOnly.parse_obj(obj)
_obj = NumberPropertiesOnly.parse_obj({
"number": obj.get("number"),
"float": obj.get("float"),
"double": obj.get("double")
})
return _obj

View File

@@ -59,6 +59,17 @@ class TestManual(unittest.TestCase):
api_response = api_instance.test_binary_gif()
self.assertEqual((base64.b64encode(api_response)).decode("utf-8"), "R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==")
def testNumberPropertiesOnly(self):
n = openapi_client.NumberPropertiesOnly.from_json('{"number": 123, "float": 456, "double": 34}')
self.assertEqual(n.number, 123)
self.assertEqual(n.float, 456)
self.assertEqual(n.double, 34)
n = openapi_client.NumberPropertiesOnly.from_json('{"number": 123.1, "float": 456.2, "double": 34.3}')
self.assertEqual(n.number, 123.1)
self.assertEqual(n.float, 456.2)
self.assertEqual(n.double, 34.3)
class EchoServerResponseParser():
def __init__(self, http_response):
if http_response is None:

View File

@@ -0,0 +1,57 @@
# coding: utf-8
"""
Echo Server API
Echo Server API # noqa: E501
The version of the OpenAPI document: 0.1.0
Contact: team@openapitools.org
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
"""
import unittest
import datetime
import openapi_client
from openapi_client.models.number_properties_only import NumberPropertiesOnly # noqa: E501
from openapi_client.rest import ApiException
class TestNumberPropertiesOnly(unittest.TestCase):
"""NumberPropertiesOnly unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test NumberPropertiesOnly
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 `NumberPropertiesOnly`
"""
model = openapi_client.models.number_properties_only.NumberPropertiesOnly() # noqa: E501
if include_optional :
return NumberPropertiesOnly(
number = 1.337,
float = 1.337,
double = ''
)
else :
return NumberPropertiesOnly(
)
"""
def testNumberPropertiesOnly(self):
"""Test NumberPropertiesOnly"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()