[Python] Add echo_api test object serialization for multipart requests (#18176)

* [python] echo add test object serialization for multipart requests

* [echo api] update samples

* [echo api] update samples
This commit is contained in:
ふぁ
2024-03-23 22:40:10 +09:00
committed by GitHub
parent 420e49f258
commit 5e9546451c
137 changed files with 7427 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ docs/Query.md
docs/QueryApi.md
docs/StringEnumRef.md
docs/Tag.md
docs/TestFormObjectMultipartRequestMarker.md
docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md
docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md
git_push.sh
@@ -43,6 +44,7 @@ openapi_client/models/pet.py
openapi_client/models/query.py
openapi_client/models/string_enum_ref.py
openapi_client/models/tag.py
openapi_client/models/test_form_object_multipart_request_marker.py
openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.py
openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.py
openapi_client/py.typed

View File

@@ -107,6 +107,7 @@ Class | Method | HTTP request | Description
*BodyApi* | [**test_echo_body_string_enum**](docs/BodyApi.md#test_echo_body_string_enum) | **POST** /echo/body/string_enum | Test string enum response body
*BodyApi* | [**test_echo_body_tag_response_string**](docs/BodyApi.md#test_echo_body_tag_response_string) | **POST** /echo/body/Tag/response_string | Test empty json (request body)
*FormApi* | [**test_form_integer_boolean_string**](docs/FormApi.md#test_form_integer_boolean_string) | **POST** /form/integer/boolean/string | Test form parameter(s)
*FormApi* | [**test_form_object_multipart**](docs/FormApi.md#test_form_object_multipart) | **POST** /form/object/multipart | Test form parameter(s) for multipart schema
*FormApi* | [**test_form_oneof**](docs/FormApi.md#test_form_oneof) | **POST** /form/oneof | Test form parameter(s) for oneOf schema
*HeaderApi* | [**test_header_integer_boolean_string_enums**](docs/HeaderApi.md#test_header_integer_boolean_string_enums) | **GET** /header/integer/boolean/string/enums | Test header parameter(s)
*PathApi* | [**tests_path_string_path_string_integer_path_integer_enum_nonref_string_path_enum_ref_string_path**](docs/PathApi.md#tests_path_string_path_string_integer_path_integer_enum_nonref_string_path_enum_ref_string_path) | **GET** /path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path} | Test path parameter(s)
@@ -133,6 +134,7 @@ Class | Method | HTTP request | Description
- [Query](docs/Query.md)
- [StringEnumRef](docs/StringEnumRef.md)
- [Tag](docs/Tag.md)
- [TestFormObjectMultipartRequestMarker](docs/TestFormObjectMultipartRequestMarker.md)
- [TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter](docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md)
- [TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter](docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md)

View File

@@ -5,6 +5,7 @@ All URIs are relative to *http://localhost:3000*
Method | HTTP request | Description
------------- | ------------- | -------------
[**test_form_integer_boolean_string**](FormApi.md#test_form_integer_boolean_string) | **POST** /form/integer/boolean/string | Test form parameter(s)
[**test_form_object_multipart**](FormApi.md#test_form_object_multipart) | **POST** /form/object/multipart | Test form parameter(s) for multipart schema
[**test_form_oneof**](FormApi.md#test_form_oneof) | **POST** /form/oneof | Test form parameter(s) for oneOf schema
@@ -79,6 +80,74 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **test_form_object_multipart**
> str test_form_object_multipart(marker)
Test form parameter(s) for multipart schema
Test form parameter(s) for multipart schema
### Example
```python
import openapi_client
from openapi_client.models.test_form_object_multipart_request_marker import TestFormObjectMultipartRequestMarker
from openapi_client.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to http://localhost:3000
# See configuration.py for a list of all supported configuration parameters.
configuration = openapi_client.Configuration(
host = "http://localhost:3000"
)
# Enter a context with an instance of the API client
with openapi_client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = openapi_client.FormApi(api_client)
marker = openapi_client.TestFormObjectMultipartRequestMarker() # TestFormObjectMultipartRequestMarker |
try:
# Test form parameter(s) for multipart schema
api_response = api_instance.test_form_object_multipart(marker)
print("The response of FormApi->test_form_object_multipart:\n")
pprint(api_response)
except Exception as e:
print("Exception when calling FormApi->test_form_object_multipart: %s\n" % e)
```
### Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**marker** | [**TestFormObjectMultipartRequestMarker**](TestFormObjectMultipartRequestMarker.md)| |
### Return type
**str**
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: multipart/form-data
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
**200** | Successful operation | - |
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **test_form_oneof**
> str test_form_oneof(form1=form1, form2=form2, form3=form3, form4=form4, id=id, name=name)

View File

@@ -0,0 +1,29 @@
# TestFormObjectMultipartRequestMarker
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **str** | | [optional]
## Example
```python
from openapi_client.models.test_form_object_multipart_request_marker import TestFormObjectMultipartRequestMarker
# TODO update the JSON string below
json = "{}"
# create an instance of TestFormObjectMultipartRequestMarker from a JSON string
test_form_object_multipart_request_marker_instance = TestFormObjectMultipartRequestMarker.from_json(json)
# print the JSON string representation of the object
print(TestFormObjectMultipartRequestMarker.to_json())
# convert the object into a dict
test_form_object_multipart_request_marker_dict = test_form_object_multipart_request_marker_instance.to_dict()
# create an instance of TestFormObjectMultipartRequestMarker from a dict
test_form_object_multipart_request_marker_form_dict = test_form_object_multipart_request_marker.from_dict(test_form_object_multipart_request_marker_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

@@ -46,5 +46,6 @@ from openapi_client.models.pet import Pet
from openapi_client.models.query import Query
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.models.tag import Tag
from openapi_client.models.test_form_object_multipart_request_marker import TestFormObjectMultipartRequestMarker
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter

View File

@@ -19,6 +19,7 @@ from typing_extensions import Annotated
from pydantic import StrictBool, StrictInt, StrictStr
from typing import Optional
from openapi_client.models.test_form_object_multipart_request_marker import TestFormObjectMultipartRequestMarker
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
@@ -338,6 +339,276 @@ class FormApi:
@validate_call
def test_form_object_multipart(
self,
marker: TestFormObjectMultipartRequestMarker,
_request_timeout: Union[
None,
Annotated[StrictFloat, Field(gt=0)],
Tuple[
Annotated[StrictFloat, Field(gt=0)],
Annotated[StrictFloat, Field(gt=0)]
]
] = None,
_request_auth: Optional[Dict[StrictStr, Any]] = None,
_content_type: Optional[StrictStr] = None,
_headers: Optional[Dict[StrictStr, Any]] = None,
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
) -> str:
"""Test form parameter(s) for multipart schema
Test form parameter(s) for multipart schema
:param marker: (required)
:type marker: TestFormObjectMultipartRequestMarker
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:type _request_timeout: int, tuple(int, int), optional
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the
authentication in the spec for a single request.
:type _request_auth: dict, optional
:param _content_type: force content-type for the request.
:type _content_type: str, Optional
:param _headers: set to override the headers for a single
request; this effectively ignores the headers
in the spec for a single request.
:type _headers: dict, optional
:param _host_index: set to override the host_index for a single
request; this effectively ignores the host_index
in the spec for a single request.
:type _host_index: int, optional
:return: Returns the result object.
""" # noqa: E501
_param = self._test_form_object_multipart_serialize(
marker=marker,
_request_auth=_request_auth,
_content_type=_content_type,
_headers=_headers,
_host_index=_host_index
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
response_data = self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
).data
@validate_call
def test_form_object_multipart_with_http_info(
self,
marker: TestFormObjectMultipartRequestMarker,
_request_timeout: Union[
None,
Annotated[StrictFloat, Field(gt=0)],
Tuple[
Annotated[StrictFloat, Field(gt=0)],
Annotated[StrictFloat, Field(gt=0)]
]
] = None,
_request_auth: Optional[Dict[StrictStr, Any]] = None,
_content_type: Optional[StrictStr] = None,
_headers: Optional[Dict[StrictStr, Any]] = None,
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
) -> ApiResponse[str]:
"""Test form parameter(s) for multipart schema
Test form parameter(s) for multipart schema
:param marker: (required)
:type marker: TestFormObjectMultipartRequestMarker
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:type _request_timeout: int, tuple(int, int), optional
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the
authentication in the spec for a single request.
:type _request_auth: dict, optional
:param _content_type: force content-type for the request.
:type _content_type: str, Optional
:param _headers: set to override the headers for a single
request; this effectively ignores the headers
in the spec for a single request.
:type _headers: dict, optional
:param _host_index: set to override the host_index for a single
request; this effectively ignores the host_index
in the spec for a single request.
:type _host_index: int, optional
:return: Returns the result object.
""" # noqa: E501
_param = self._test_form_object_multipart_serialize(
marker=marker,
_request_auth=_request_auth,
_content_type=_content_type,
_headers=_headers,
_host_index=_host_index
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
response_data = self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
response_data.read()
return self.api_client.response_deserialize(
response_data=response_data,
response_types_map=_response_types_map,
)
@validate_call
def test_form_object_multipart_without_preload_content(
self,
marker: TestFormObjectMultipartRequestMarker,
_request_timeout: Union[
None,
Annotated[StrictFloat, Field(gt=0)],
Tuple[
Annotated[StrictFloat, Field(gt=0)],
Annotated[StrictFloat, Field(gt=0)]
]
] = None,
_request_auth: Optional[Dict[StrictStr, Any]] = None,
_content_type: Optional[StrictStr] = None,
_headers: Optional[Dict[StrictStr, Any]] = None,
_host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
) -> RESTResponseType:
"""Test form parameter(s) for multipart schema
Test form parameter(s) for multipart schema
:param marker: (required)
:type marker: TestFormObjectMultipartRequestMarker
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:type _request_timeout: int, tuple(int, int), optional
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the
authentication in the spec for a single request.
:type _request_auth: dict, optional
:param _content_type: force content-type for the request.
:type _content_type: str, Optional
:param _headers: set to override the headers for a single
request; this effectively ignores the headers
in the spec for a single request.
:type _headers: dict, optional
:param _host_index: set to override the host_index for a single
request; this effectively ignores the host_index
in the spec for a single request.
:type _host_index: int, optional
:return: Returns the result object.
""" # noqa: E501
_param = self._test_form_object_multipart_serialize(
marker=marker,
_request_auth=_request_auth,
_content_type=_content_type,
_headers=_headers,
_host_index=_host_index
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
response_data = self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
return response_data.response
def _test_form_object_multipart_serialize(
self,
marker,
_request_auth,
_content_type,
_headers,
_host_index,
) -> RequestSerialized:
_host = None
_collection_formats: Dict[str, str] = {
}
_path_params: Dict[str, str] = {}
_query_params: List[Tuple[str, str]] = []
_header_params: Dict[str, Optional[str]] = _headers or {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, Union[str, bytes]] = {}
_body_params: Optional[bytes] = None
# process the path parameters
# process the query parameters
# process the header parameters
# process the form parameters
if marker is not None:
_form_params.append(('marker', marker))
# process the body parameter
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
[
'text/plain'
]
)
# set the HTTP header `Content-Type`
if _content_type:
_header_params['Content-Type'] = _content_type
else:
_default_content_type = (
self.api_client.select_header_content_type(
[
'multipart/form-data'
]
)
)
if _default_content_type is not None:
_header_params['Content-Type'] = _default_content_type
# authentication setting
_auth_settings: List[str] = [
]
return self.api_client.param_serialize(
method='POST',
resource_path='/form/object/multipart',
path_params=_path_params,
query_params=_query_params,
header_params=_header_params,
body=_body_params,
post_params=_form_params,
files=_files,
auth_settings=_auth_settings,
collection_formats=_collection_formats,
_host=_host,
_request_auth=_request_auth
)
@validate_call
def test_form_oneof(
self,

View File

@@ -24,5 +24,6 @@ from openapi_client.models.pet import Pet
from openapi_client.models.query import Query
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.models.tag import Tag
from openapi_client.models.test_form_object_multipart_request_marker import TestFormObjectMultipartRequestMarker
from openapi_client.models.test_query_style_deep_object_explode_true_object_all_of_query_object_parameter import TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter

View File

@@ -0,0 +1,88 @@
# coding: utf-8
"""
Echo Server API
Echo Server API
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.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, ConfigDict, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self
class TestFormObjectMultipartRequestMarker(BaseModel):
"""
TestFormObjectMultipartRequestMarker
""" # noqa: E501
name: Optional[StrictStr] = None
__properties: ClassVar[List[str]] = ["name"]
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 TestFormObjectMultipartRequestMarker 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,
)
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of TestFormObjectMultipartRequestMarker from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"name": obj.get("name")
})
return _obj

View File

@@ -0,0 +1,52 @@
# coding: utf-8
"""
Echo Server API
Echo Server API
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.
""" # noqa: E501
import unittest
from openapi_client.models.test_form_object_multipart_request_marker import TestFormObjectMultipartRequestMarker
class TestTestFormObjectMultipartRequestMarker(unittest.TestCase):
"""TestFormObjectMultipartRequestMarker unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional) -> TestFormObjectMultipartRequestMarker:
"""Test TestFormObjectMultipartRequestMarker
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 `TestFormObjectMultipartRequestMarker`
"""
model = TestFormObjectMultipartRequestMarker()
if include_optional:
return TestFormObjectMultipartRequestMarker(
name = ''
)
else:
return TestFormObjectMultipartRequestMarker(
)
"""
def testTestFormObjectMultipartRequestMarker(self):
"""Test TestFormObjectMultipartRequestMarker"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@@ -265,6 +265,19 @@ User-Agent: OpenAPI-Generator/1.0.0/python
self.assertEqual(e.headers["Accept"], 'text/plain')
self.assertEqual(e.method, 'POST')
def test_form_object_multipart(self):
api_instance = openapi_client.FormApi()
marker = openapi_client.TestFormObjectMultipartRequestMarker(
name="name",
)
api_response = api_instance.test_form_object_multipart(
marker=marker,
)
e = EchoServerResponseParser(api_response)
self.assertEqual(e.path, "/form/object/multipart")
self.assertTrue(e.headers["Content-Type"].startswith("multipart/form-data"))
self.assertTrue("boundary=" in e.headers["Content-Type"])
class EchoServerResponseParser():
def __init__(self, http_response):
if http_response is None: