python: type generated client using Self (#16693)

* python: type generated client using Self

This doesn't offer a clear win but this helps for:

* Using modern types and making the typing intent clearer
* Decreasing the need for `from __future__ import annotations`, since a
  class can now refer to itself without using its name
* Using more `cls` to automatically refer to the class, instead of
  respecifying the class name every time

Self is available from Python 3.11 and is provided in typing_extensions
(since 4.0.0) as a fallback for older versions

See: https://peps.python.org/pep-0673/
See: https://github.com/python/typing_extensions/blob/main/CHANGELOG.md#added-in-version-400

* generate code
This commit is contained in:
Jonathan Ballet
2023-10-01 17:31:39 +02:00
committed by GitHub
parent bd1caf69cb
commit cec5b8965a
195 changed files with 1723 additions and 824 deletions

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from openapi_client.api_client import ApiClient
@@ -130,18 +131,18 @@ class AuthApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -149,9 +150,9 @@ class AuthApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = ['http_auth'] # noqa: E501
_auth_settings: List[str] = ['http_auth'] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from pydantic import Field
from typing_extensions import Annotated
@@ -138,18 +139,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -157,9 +158,9 @@ class BodyApi:
['image/gif']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "bytearray",
}
@@ -275,18 +276,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
if _params['body'] is not None:
@@ -309,9 +310,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -427,18 +428,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
if _params['files'] is not None:
_files['files'] = _params['files']
_collection_formats['files'] = 'csv'
@@ -457,9 +458,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -575,18 +576,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
if _params['body'] is not None:
@@ -604,9 +605,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -722,18 +723,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
if _params['pet'] is not None:
@@ -751,9 +752,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "Pet",
}
@@ -869,18 +870,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
if _params['pet'] is not None:
@@ -898,9 +899,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -1016,18 +1017,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
if _params['tag'] is not None:
@@ -1045,9 +1046,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from pydantic import StrictBool, StrictInt, StrictStr
@@ -149,18 +150,18 @@ class FormApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
if _params['integer_form'] is not None:
_form_params.append(('integer_form', _params['integer_form']))
@@ -184,9 +185,9 @@ class FormApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -327,18 +328,18 @@ class FormApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
if _params['form1'] is not None:
_form_params.append(('form1', _params['form1']))
@@ -371,9 +372,9 @@ class FormApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from pydantic import StrictBool, StrictInt, StrictStr
@@ -149,13 +150,13 @@ class HeaderApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
if _params['integer_header'] is not None:
@@ -168,8 +169,8 @@ class HeaderApi:
_header_params['string_header'] = _params['string_header']
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -177,9 +178,9 @@ class HeaderApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from pydantic import StrictInt, StrictStr
@@ -142,10 +143,10 @@ class PathApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
if _params['path_string'] is not None:
_path_params['path_string'] = _params['path_string']
@@ -154,12 +155,12 @@ class PathApi:
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -167,9 +168,9 @@ class PathApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from datetime import date, datetime
@@ -144,21 +145,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('enum_ref_string_query') is not None: # noqa: E501
_query_params.append(('enum_ref_string_query', _params['enum_ref_string_query'].value))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -166,9 +167,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -294,13 +295,13 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('datetime_query') is not None: # noqa: E501
if isinstance(_params['datetime_query'], datetime):
_query_params.append(('datetime_query', _params['datetime_query'].strftime(self.api_client.configuration.datetime_format)))
@@ -319,8 +320,8 @@ class QueryApi:
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -328,9 +329,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -456,13 +457,13 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('integer_query') is not None: # noqa: E501
_query_params.append(('integer_query', _params['integer_query']))
@@ -475,8 +476,8 @@ class QueryApi:
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -484,9 +485,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -602,21 +603,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('query_object') is not None: # noqa: E501
_query_params.append(('query_object', _params['query_object']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -624,9 +625,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -742,21 +743,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('query_object') is not None: # noqa: E501
_query_params.append(('query_object', _params['query_object']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -764,9 +765,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -882,21 +883,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('query_object') is not None: # noqa: E501
_query_params.append(('query_object', _params['query_object']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -904,9 +905,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -1022,21 +1023,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('query_object') is not None: # noqa: E501
_query_params.append(('query_object', _params['query_object']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -1044,9 +1045,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -1162,21 +1163,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('query_object') is not None: # noqa: E501
_query_params.append(('query_object', _params['query_object']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -1184,9 +1185,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -21,6 +21,11 @@ import json
from typing import Optional
from pydantic import BaseModel, StrictStr
from typing import Dict, Any
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class Bird(BaseModel):
"""
@@ -46,7 +51,7 @@ class Bird(BaseModel):
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Bird:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of Bird from a JSON string"""
return cls.from_dict(json.loads(json_str))
@@ -59,20 +64,20 @@ class Bird(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: dict) -> Bird:
def from_dict(cls, obj: dict) -> Self:
"""Create an instance of Bird from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return Bird.model_validate(obj)
return cls.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in Bird) in the input: " + _key)
_obj = Bird.model_validate({
_obj = cls.model_validate({
"size": obj.get("size"),
"color": obj.get("color")
})

View File

@@ -21,6 +21,11 @@ import json
from typing import Optional
from pydantic import BaseModel, StrictInt, StrictStr
from typing import Dict, Any
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class Category(BaseModel):
"""
@@ -46,7 +51,7 @@ class Category(BaseModel):
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Category:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of Category from a JSON string"""
return cls.from_dict(json.loads(json_str))
@@ -59,20 +64,20 @@ class Category(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: dict) -> Category:
def from_dict(cls, obj: dict) -> Self:
"""Create an instance of Category from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return Category.model_validate(obj)
return cls.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in Category) in the input: " + _key)
_obj = Category.model_validate({
_obj = cls.model_validate({
"id": obj.get("id"),
"name": obj.get("name")
})

View File

@@ -23,6 +23,11 @@ from typing import Optional
from pydantic import StrictStr
from pydantic import Field
from openapi_client.models.query import Query
from typing import Dict, Any
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class DataQuery(Query):
"""
@@ -49,7 +54,7 @@ class DataQuery(Query):
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> DataQuery:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of DataQuery from a JSON string"""
return cls.from_dict(json.loads(json_str))
@@ -62,20 +67,20 @@ class DataQuery(Query):
return _dict
@classmethod
def from_dict(cls, obj: dict) -> DataQuery:
def from_dict(cls, obj: dict) -> Self:
"""Create an instance of DataQuery from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return DataQuery.model_validate(obj)
return cls.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in DataQuery) in the input: " + _key)
_obj = DataQuery.model_validate({
_obj = cls.model_validate({
"id": obj.get("id"),
"outcomes": obj.get("outcomes"),
"suffix": obj.get("suffix"),

View File

@@ -22,6 +22,11 @@ import json
from typing import List, Optional
from pydantic import BaseModel, StrictInt, StrictStr, field_validator
from openapi_client.models.string_enum_ref import StringEnumRef
from typing import Dict, Any
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class DefaultValue(BaseModel):
"""
@@ -64,7 +69,7 @@ class DefaultValue(BaseModel):
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> DefaultValue:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of DefaultValue from a JSON string"""
return cls.from_dict(json.loads(json_str))
@@ -92,20 +97,20 @@ class DefaultValue(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: dict) -> DefaultValue:
def from_dict(cls, obj: dict) -> Self:
"""Create an instance of DefaultValue from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return DefaultValue.model_validate(obj)
return cls.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in DefaultValue) in the input: " + _key)
_obj = DefaultValue.model_validate({
_obj = cls.model_validate({
"array_string_enum_ref_default": obj.get("array_string_enum_ref_default"),
"array_string_enum_default": obj.get("array_string_enum_default"),
"array_string_default": obj.get("array_string_default"),

View File

@@ -23,6 +23,11 @@ from typing import Optional, Union
from pydantic import BaseModel, StrictFloat, StrictInt
from pydantic import Field
from typing_extensions import Annotated
from typing import Dict, Any
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class NumberPropertiesOnly(BaseModel):
"""
@@ -49,7 +54,7 @@ class NumberPropertiesOnly(BaseModel):
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> NumberPropertiesOnly:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of NumberPropertiesOnly from a JSON string"""
return cls.from_dict(json.loads(json_str))
@@ -62,20 +67,20 @@ class NumberPropertiesOnly(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: dict) -> NumberPropertiesOnly:
def from_dict(cls, obj: dict) -> Self:
"""Create an instance of NumberPropertiesOnly from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return NumberPropertiesOnly.model_validate(obj)
return cls.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in NumberPropertiesOnly) in the input: " + _key)
_obj = NumberPropertiesOnly.model_validate({
_obj = cls.model_validate({
"number": obj.get("number"),
"float": obj.get("float"),
"double": obj.get("double")

View File

@@ -24,6 +24,11 @@ from pydantic import BaseModel, StrictInt, StrictStr, field_validator
from pydantic import Field
from openapi_client.models.category import Category
from openapi_client.models.tag import Tag
from typing import Dict, Any
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class Pet(BaseModel):
"""
@@ -63,7 +68,7 @@ class Pet(BaseModel):
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Pet:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of Pet from a JSON string"""
return cls.from_dict(json.loads(json_str))
@@ -86,20 +91,20 @@ class Pet(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: dict) -> Pet:
def from_dict(cls, obj: dict) -> Self:
"""Create an instance of Pet from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return Pet.model_validate(obj)
return cls.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in Pet) in the input: " + _key)
_obj = Pet.model_validate({
_obj = cls.model_validate({
"id": obj.get("id"),
"name": obj.get("name"),
"category": Category.from_dict(obj.get("category")) if obj.get("category") is not None else None,

View File

@@ -22,6 +22,11 @@ import json
from typing import List, Optional
from pydantic import BaseModel, StrictInt, StrictStr, field_validator
from pydantic import Field
from typing import Dict, Any
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class Query(BaseModel):
"""
@@ -58,7 +63,7 @@ class Query(BaseModel):
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Query:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of Query from a JSON string"""
return cls.from_dict(json.loads(json_str))
@@ -71,7 +76,7 @@ class Query(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: dict) -> Query:
def from_dict(cls, obj: dict) -> Self:
"""Create an instance of Query from a dict"""

View File

@@ -13,13 +13,18 @@
""" # noqa: E501
from __future__ import annotations
import json
import pprint
import re # noqa: F401
from aenum import Enum, no_arg
from enum import Enum
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class StringEnumRef(str, Enum):
@@ -35,8 +40,8 @@ class StringEnumRef(str, Enum):
UNCLASSIFIED = 'unclassified'
@classmethod
def from_json(cls, json_str: str) -> StringEnumRef:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of StringEnumRef from a JSON string"""
return StringEnumRef(json.loads(json_str))
return cls(json.loads(json_str))

View File

@@ -21,6 +21,11 @@ import json
from typing import Optional
from pydantic import BaseModel, StrictInt, StrictStr
from typing import Dict, Any
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class Tag(BaseModel):
"""
@@ -46,7 +51,7 @@ class Tag(BaseModel):
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Tag:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of Tag from a JSON string"""
return cls.from_dict(json.loads(json_str))
@@ -59,20 +64,20 @@ class Tag(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: dict) -> Tag:
def from_dict(cls, obj: dict) -> Self:
"""Create an instance of Tag from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return Tag.model_validate(obj)
return cls.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in Tag) in the input: " + _key)
_obj = Tag.model_validate({
_obj = cls.model_validate({
"id": obj.get("id"),
"name": obj.get("name")
})

View File

@@ -21,6 +21,11 @@ import json
from typing import Optional
from pydantic import BaseModel, StrictInt, StrictStr
from typing import Dict, Any
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseModel):
"""
@@ -48,7 +53,7 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a JSON string"""
return cls.from_dict(json.loads(json_str))
@@ -61,20 +66,20 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod
return _dict
@classmethod
def from_dict(cls, obj: dict) -> TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter:
def from_dict(cls, obj: dict) -> Self:
"""Create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_validate(obj)
return cls.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter) in the input: " + _key)
_obj = TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.model_validate({
_obj = cls.model_validate({
"size": obj.get("size"),
"color": obj.get("color"),
"id": obj.get("id"),

View File

@@ -21,6 +21,11 @@ import json
from typing import List, Optional
from pydantic import BaseModel, StrictStr
from typing import Dict, Any
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel):
"""
@@ -45,7 +50,7 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel):
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter:
def from_json(cls, json_str: str) -> Self:
"""Create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a JSON string"""
return cls.from_dict(json.loads(json_str))
@@ -58,20 +63,20 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: dict) -> TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter:
def from_dict(cls, obj: dict) -> Self:
"""Create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_validate(obj)
return cls.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter) in the input: " + _key)
_obj = TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.model_validate({
_obj = cls.model_validate({
"values": obj.get("values")
})
return _obj

View File

@@ -15,7 +15,6 @@ python = "^3.7"
urllib3 = ">= 1.25.3"
python-dateutil = ">=2.8.2"
pydantic = ">=2"
aenum = ">=3.1.11"
typing-extensions = ">=4.7.1"
[tool.poetry.dev-dependencies]

View File

@@ -2,5 +2,4 @@ python_dateutil >= 2.5.3
setuptools >= 21.0.0
urllib3 >= 1.25.3, < 2.1.0
pydantic >= 2
aenum >= 3.1.11
typing-extensions >= 4.7.1

View File

@@ -28,7 +28,6 @@ REQUIRES = [
"urllib3 >= 1.25.3, < 2.1.0",
"python-dateutil",
"pydantic >= 2",
"aenum",
"typing-extensions >= 4.7.1",
]