forked from loafle/openapi-generator-original
use model class for request body with additionalProperties (#16613)
* try out simple fix * add test case * generate samples
This commit is contained in:
@@ -84,6 +84,7 @@ docs/SpecialModelName.md
|
||||
docs/SpecialName.md
|
||||
docs/StoreApi.md
|
||||
docs/Tag.md
|
||||
docs/TestInlineFreeformAdditionalPropertiesRequest.md
|
||||
docs/Tiger.md
|
||||
docs/User.md
|
||||
docs/UserApi.md
|
||||
@@ -178,6 +179,7 @@ petstore_api/models/special_character_enum.py
|
||||
petstore_api/models/special_model_name.py
|
||||
petstore_api/models/special_name.py
|
||||
petstore_api/models/tag.py
|
||||
petstore_api/models/test_inline_freeform_additional_properties_request.py
|
||||
petstore_api/models/tiger.py
|
||||
petstore_api/models/user.py
|
||||
petstore_api/models/with_nested_one_of.py
|
||||
|
||||
@@ -106,6 +106,7 @@ Class | Method | HTTP request | Description
|
||||
*FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
*FakeApi* | [**test_group_parameters**](docs/FakeApi.md#test_group_parameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
|
||||
*FakeApi* | [**test_inline_additional_properties**](docs/FakeApi.md#test_inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
|
||||
*FakeApi* | [**test_inline_freeform_additional_properties**](docs/FakeApi.md#test_inline_freeform_additional_properties) | **POST** /fake/inline-freeform-additionalProperties | test inline free-form additionalProperties
|
||||
*FakeApi* | [**test_json_form_data**](docs/FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data
|
||||
*FakeApi* | [**test_query_parameter_collection_format**](docs/FakeApi.md#test_query_parameter_collection_format) | **PUT** /fake/test-query-parameters |
|
||||
*FakeClassnameTags123Api* | [**test_classname**](docs/FakeClassnameTags123Api.md#test_classname) | **PATCH** /fake_classname_test | To test class name in snake case
|
||||
@@ -209,6 +210,7 @@ Class | Method | HTTP request | Description
|
||||
- [SpecialModelName](docs/SpecialModelName.md)
|
||||
- [SpecialName](docs/SpecialName.md)
|
||||
- [Tag](docs/Tag.md)
|
||||
- [TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md)
|
||||
- [Tiger](docs/Tiger.md)
|
||||
- [User](docs/User.md)
|
||||
- [WithNestedOneOf](docs/WithNestedOneOf.md)
|
||||
|
||||
@@ -23,6 +23,7 @@ Method | HTTP request | Description
|
||||
[**test_endpoint_parameters**](FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
|
||||
[**test_group_parameters**](FakeApi.md#test_group_parameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
|
||||
[**test_inline_additional_properties**](FakeApi.md#test_inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
|
||||
[**test_inline_freeform_additional_properties**](FakeApi.md#test_inline_freeform_additional_properties) | **POST** /fake/inline-freeform-additionalProperties | test inline free-form additionalProperties
|
||||
[**test_json_form_data**](FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data
|
||||
[**test_query_parameter_collection_format**](FakeApi.md#test_query_parameter_collection_format) | **PUT** /fake/test-query-parameters |
|
||||
|
||||
@@ -1370,6 +1371,71 @@ 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_inline_freeform_additional_properties**
|
||||
> test_inline_freeform_additional_properties(test_inline_freeform_additional_properties_request)
|
||||
|
||||
test inline free-form additionalProperties
|
||||
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
```python
|
||||
import time
|
||||
import os
|
||||
import petstore_api
|
||||
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
|
||||
# See configuration.py for a list of all supported configuration parameters.
|
||||
configuration = petstore_api.Configuration(
|
||||
host = "http://petstore.swagger.io:80/v2"
|
||||
)
|
||||
|
||||
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient(configuration) as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.FakeApi(api_client)
|
||||
test_inline_freeform_additional_properties_request = petstore_api.TestInlineFreeformAdditionalPropertiesRequest() # TestInlineFreeformAdditionalPropertiesRequest | request body
|
||||
|
||||
try:
|
||||
# test inline free-form additionalProperties
|
||||
api_instance.test_inline_freeform_additional_properties(test_inline_freeform_additional_properties_request)
|
||||
except Exception as e:
|
||||
print("Exception when calling FakeApi->test_inline_freeform_additional_properties: %s\n" % e)
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**test_inline_freeform_additional_properties_request** | [**TestInlineFreeformAdditionalPropertiesRequest**](TestInlineFreeformAdditionalPropertiesRequest.md)| request body |
|
||||
|
||||
### Return type
|
||||
|
||||
void (empty response body)
|
||||
|
||||
### Authorization
|
||||
|
||||
No authorization required
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: application/json
|
||||
- **Accept**: Not defined
|
||||
|
||||
### 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_json_form_data**
|
||||
> test_json_form_data(param, param2)
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# TestInlineFreeformAdditionalPropertiesRequest
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**some_property** | **str** | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of TestInlineFreeformAdditionalPropertiesRequest from a JSON string
|
||||
test_inline_freeform_additional_properties_request_instance = TestInlineFreeformAdditionalPropertiesRequest.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print TestInlineFreeformAdditionalPropertiesRequest.to_json()
|
||||
|
||||
# convert the object into a dict
|
||||
test_inline_freeform_additional_properties_request_dict = test_inline_freeform_additional_properties_request_instance.to_dict()
|
||||
# create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict
|
||||
test_inline_freeform_additional_properties_request_form_dict = test_inline_freeform_additional_properties_request.from_dict(test_inline_freeform_additional_properties_request_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)
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ from petstore_api.models.special_character_enum import SpecialCharacterEnum
|
||||
from petstore_api.models.special_model_name import SpecialModelName
|
||||
from petstore_api.models.special_name import SpecialName
|
||||
from petstore_api.models.tag import Tag
|
||||
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest
|
||||
from petstore_api.models.tiger import Tiger
|
||||
from petstore_api.models.user import User
|
||||
from petstore_api.models.with_nested_one_of import WithNestedOneOf
|
||||
|
||||
@@ -33,6 +33,7 @@ from petstore_api.models.outer_composite import OuterComposite
|
||||
from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty
|
||||
from petstore_api.models.pet import Pet
|
||||
from petstore_api.models.tag import Tag
|
||||
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest
|
||||
from petstore_api.models.user import User
|
||||
|
||||
from petstore_api.api_client import ApiClient
|
||||
@@ -2900,6 +2901,147 @@ class FakeApi:
|
||||
collection_formats=_collection_formats,
|
||||
_request_auth=_params.get('_request_auth'))
|
||||
|
||||
@validate_arguments
|
||||
def test_inline_freeform_additional_properties(self, test_inline_freeform_additional_properties_request : Annotated[TestInlineFreeformAdditionalPropertiesRequest, Field(..., description="request body")], **kwargs) -> None: # noqa: E501
|
||||
"""test inline free-form additionalProperties # noqa: E501
|
||||
|
||||
# noqa: E501
|
||||
This method makes a synchronous HTTP request by default. To make an
|
||||
asynchronous HTTP request, please pass async_req=True
|
||||
|
||||
>>> thread = api.test_inline_freeform_additional_properties(test_inline_freeform_additional_properties_request, async_req=True)
|
||||
>>> result = thread.get()
|
||||
|
||||
:param test_inline_freeform_additional_properties_request: request body (required)
|
||||
:type test_inline_freeform_additional_properties_request: TestInlineFreeformAdditionalPropertiesRequest
|
||||
:param async_req: Whether to execute the request asynchronously.
|
||||
:type async_req: bool, optional
|
||||
: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.
|
||||
:return: Returns the result object.
|
||||
If the method is called asynchronously,
|
||||
returns the request thread.
|
||||
:rtype: None
|
||||
"""
|
||||
kwargs['_return_http_data_only'] = True
|
||||
if '_preload_content' in kwargs:
|
||||
message = "Error! Please call the test_inline_freeform_additional_properties_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501
|
||||
raise ValueError(message)
|
||||
return self.test_inline_freeform_additional_properties_with_http_info(test_inline_freeform_additional_properties_request, **kwargs) # noqa: E501
|
||||
|
||||
@validate_arguments
|
||||
def test_inline_freeform_additional_properties_with_http_info(self, test_inline_freeform_additional_properties_request : Annotated[TestInlineFreeformAdditionalPropertiesRequest, Field(..., description="request body")], **kwargs) -> ApiResponse: # noqa: E501
|
||||
"""test inline free-form additionalProperties # noqa: E501
|
||||
|
||||
# noqa: E501
|
||||
This method makes a synchronous HTTP request by default. To make an
|
||||
asynchronous HTTP request, please pass async_req=True
|
||||
|
||||
>>> thread = api.test_inline_freeform_additional_properties_with_http_info(test_inline_freeform_additional_properties_request, async_req=True)
|
||||
>>> result = thread.get()
|
||||
|
||||
:param test_inline_freeform_additional_properties_request: request body (required)
|
||||
:type test_inline_freeform_additional_properties_request: TestInlineFreeformAdditionalPropertiesRequest
|
||||
:param async_req: Whether to execute the request asynchronously.
|
||||
:type async_req: bool, optional
|
||||
:param _preload_content: if False, the ApiResponse.data will
|
||||
be set to none and raw_data will store the
|
||||
HTTP response body without reading/decoding.
|
||||
Default is True.
|
||||
:type _preload_content: bool, optional
|
||||
:param _return_http_data_only: response data instead of ApiResponse
|
||||
object with status code, headers, etc
|
||||
:type _return_http_data_only: bool, optional
|
||||
: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.
|
||||
: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
|
||||
:type _content_type: string, optional: force content-type for the request
|
||||
:return: Returns the result object.
|
||||
If the method is called asynchronously,
|
||||
returns the request thread.
|
||||
:rtype: None
|
||||
"""
|
||||
|
||||
_params = locals()
|
||||
|
||||
_all_params = [
|
||||
'test_inline_freeform_additional_properties_request'
|
||||
]
|
||||
_all_params.extend(
|
||||
[
|
||||
'async_req',
|
||||
'_return_http_data_only',
|
||||
'_preload_content',
|
||||
'_request_timeout',
|
||||
'_request_auth',
|
||||
'_content_type',
|
||||
'_headers'
|
||||
]
|
||||
)
|
||||
|
||||
# validate the arguments
|
||||
for _key, _val in _params['kwargs'].items():
|
||||
if _key not in _all_params:
|
||||
raise ApiTypeError(
|
||||
"Got an unexpected keyword argument '%s'"
|
||||
" to method test_inline_freeform_additional_properties" % _key
|
||||
)
|
||||
_params[_key] = _val
|
||||
del _params['kwargs']
|
||||
|
||||
_collection_formats = {}
|
||||
|
||||
# process the path parameters
|
||||
_path_params = {}
|
||||
|
||||
# process the query parameters
|
||||
_query_params = []
|
||||
# process the header parameters
|
||||
_header_params = dict(_params.get('_headers', {}))
|
||||
# process the form parameters
|
||||
_form_params = []
|
||||
_files = {}
|
||||
# process the body parameter
|
||||
_body_params = None
|
||||
if _params['test_inline_freeform_additional_properties_request'] is not None:
|
||||
_body_params = _params['test_inline_freeform_additional_properties_request']
|
||||
|
||||
# set the HTTP header `Content-Type`
|
||||
_content_types_list = _params.get('_content_type',
|
||||
self.api_client.select_header_content_type(
|
||||
['application/json']))
|
||||
if _content_types_list:
|
||||
_header_params['Content-Type'] = _content_types_list
|
||||
|
||||
# authentication setting
|
||||
_auth_settings = [] # noqa: E501
|
||||
|
||||
_response_types_map = {}
|
||||
|
||||
return self.api_client.call_api(
|
||||
'/fake/inline-freeform-additionalProperties', 'POST',
|
||||
_path_params,
|
||||
_query_params,
|
||||
_header_params,
|
||||
body=_body_params,
|
||||
post_params=_form_params,
|
||||
files=_files,
|
||||
response_types_map=_response_types_map,
|
||||
auth_settings=_auth_settings,
|
||||
async_req=_params.get('async_req'),
|
||||
_return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501
|
||||
_preload_content=_params.get('_preload_content', True),
|
||||
_request_timeout=_params.get('_request_timeout'),
|
||||
collection_formats=_collection_formats,
|
||||
_request_auth=_params.get('_request_auth'))
|
||||
|
||||
@validate_arguments
|
||||
def test_json_form_data(self, param : Annotated[StrictStr, Field(..., description="field1")], param2 : Annotated[StrictStr, Field(..., description="field2")], **kwargs) -> None: # noqa: E501
|
||||
"""test json serialization of form data # noqa: E501
|
||||
|
||||
@@ -89,6 +89,7 @@ from petstore_api.models.special_character_enum import SpecialCharacterEnum
|
||||
from petstore_api.models.special_model_name import SpecialModelName
|
||||
from petstore_api.models.special_name import SpecialName
|
||||
from petstore_api.models.tag import Tag
|
||||
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest
|
||||
from petstore_api.models.tiger import Tiger
|
||||
from petstore_api.models.user import User
|
||||
from petstore_api.models.with_nested_one_of import WithNestedOneOf
|
||||
|
||||
@@ -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: \" \\
|
||||
|
||||
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 typing import Any, Dict, Optional
|
||||
from pydantic import BaseModel, Field, StrictStr
|
||||
|
||||
class TestInlineFreeformAdditionalPropertiesRequest(BaseModel):
|
||||
"""
|
||||
TestInlineFreeformAdditionalPropertiesRequest
|
||||
"""
|
||||
some_property: Optional[StrictStr] = Field(None, alias="someProperty")
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties = ["someProperty"]
|
||||
|
||||
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) -> TestInlineFreeformAdditionalPropertiesRequest:
|
||||
"""Create an instance of TestInlineFreeformAdditionalPropertiesRequest 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)
|
||||
# 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) -> TestInlineFreeformAdditionalPropertiesRequest:
|
||||
"""Create an instance of TestInlineFreeformAdditionalPropertiesRequest from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return TestInlineFreeformAdditionalPropertiesRequest.parse_obj(obj)
|
||||
|
||||
_obj = TestInlineFreeformAdditionalPropertiesRequest.parse_obj({
|
||||
"some_property": obj.get("someProperty")
|
||||
})
|
||||
# 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
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# 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
|
||||
import datetime
|
||||
|
||||
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest # noqa: E501
|
||||
|
||||
class TestTestInlineFreeformAdditionalPropertiesRequest(unittest.TestCase):
|
||||
"""TestInlineFreeformAdditionalPropertiesRequest unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional) -> TestInlineFreeformAdditionalPropertiesRequest:
|
||||
"""Test TestInlineFreeformAdditionalPropertiesRequest
|
||||
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 `TestInlineFreeformAdditionalPropertiesRequest`
|
||||
"""
|
||||
model = TestInlineFreeformAdditionalPropertiesRequest() # noqa: E501
|
||||
if include_optional:
|
||||
return TestInlineFreeformAdditionalPropertiesRequest(
|
||||
some_property = ''
|
||||
)
|
||||
else:
|
||||
return TestInlineFreeformAdditionalPropertiesRequest(
|
||||
)
|
||||
"""
|
||||
|
||||
def testTestInlineFreeformAdditionalPropertiesRequest(self):
|
||||
"""Test TestInlineFreeformAdditionalPropertiesRequest"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user