Skip to content

Commit

Permalink
[python-experimental] fixes delete endpoint with no body use case (#1…
Browse files Browse the repository at this point in the history
…2287)

* Generates delete_coffee endpoint

* Adds test of delete_coffee

* Removes .run files

* Fixes bug and adds test

* Reverts version file

* Reverts function sig

* Removes comma
  • Loading branch information
spacether committed May 3, 2022
1 parent 153e1db commit 8fc8553
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 10 deletions.
Expand Up @@ -127,15 +127,21 @@ class RESTClientObject(object):
len(timeout) == 2):
timeout = urllib3.Timeout(connect=timeout[0], read=timeout[1])

if 'Content-Type' not in headers:
headers['Content-Type'] = 'application/json'

try:
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
if query_params:
url += '?' + urlencode(query_params)
if headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
if 'Content-Type' not in headers and body is None:
r = self.pool_manager.request(
method,
url,
fields=query_params,
preload_content=not stream,
timeout=timeout,
headers=headers
)
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
r = self.pool_manager.request(
method, url,
fields=fields,
Expand Down
Expand Up @@ -1558,6 +1558,25 @@ paths:
content:
application/json: {}
application/xml: {}
/fake/deleteCoffee/{id}:
delete:
operationId: deleteCoffee
summary: Delete coffee
description: Delete the coffee identified by the given id, (delete without request body)
tags:
- fake
parameters:
- name: id
in: path
description: The internal object id
required: true
schema:
type: string
responses:
'200':
description: OK
default:
description: Unexpected error
servers:
- url: 'http://{server}.swagger.io:{port}/v2'
description: petstore server
Expand Down
Expand Up @@ -93,6 +93,7 @@ Class | Method | HTTP request | Description
*FakeApi* | [**case_sensitive_params**](docs/FakeApi.md#case_sensitive_params) | **PUT** /fake/case-sensitive-params |
*FakeApi* | [**client_model**](docs/FakeApi.md#client_model) | **PATCH** /fake | To test \"client\" model
*FakeApi* | [**composed_one_of_different_types**](docs/FakeApi.md#composed_one_of_different_types) | **POST** /fake/refs/composed_one_of_number_with_validations |
*FakeApi* | [**delete_coffee**](docs/FakeApi.md#delete_coffee) | **DELETE** /fake/deleteCoffee/{id} | Delete coffee
*FakeApi* | [**endpoint_parameters**](docs/FakeApi.md#endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*FakeApi* | [**enum_parameters**](docs/FakeApi.md#enum_parameters) | **GET** /fake | To test enum parameters
*FakeApi* | [**fake_health_get**](docs/FakeApi.md#fake_health_get) | **GET** /fake/health | Health check endpoint
Expand Down
Expand Up @@ -13,6 +13,7 @@ Method | HTTP request | Description
[**case_sensitive_params**](FakeApi.md#case_sensitive_params) | **PUT** /fake/case-sensitive-params |
[**client_model**](FakeApi.md#client_model) | **PATCH** /fake | To test \"client\" model
[**composed_one_of_different_types**](FakeApi.md#composed_one_of_different_types) | **POST** /fake/refs/composed_one_of_number_with_validations |
[**delete_coffee**](FakeApi.md#delete_coffee) | **DELETE** /fake/deleteCoffee/{id} | Delete coffee
[**endpoint_parameters**](FakeApi.md#endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
[**enum_parameters**](FakeApi.md#enum_parameters) | **GET** /fake | To test enum parameters
[**fake_health_get**](FakeApi.md#fake_health_get) | **GET** /fake/health | Health check endpoint
Expand Down Expand Up @@ -826,6 +827,95 @@ 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)

# **delete_coffee**
> delete_coffee(id)
Delete coffee

Delete the coffee identified by the given id, (delete without request body)

### Example

```python
import petstore_api
from petstore_api.api import fake_api
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 = fake_api.FakeApi(api_client)

# example passing only required values which don't have defaults set
path_params = {
'id': "id_example",
}
try:
# Delete coffee
api_response = api_instance.delete_coffee(
path_params=path_params,
)
except petstore_api.ApiException as e:
print("Exception when calling FakeApi->delete_coffee: %s\n" % e)
```
### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
path_params | RequestPathParams | |
stream | bool | default is False | if True then the response.content will be streamed and loaded from a file like object. When downloading a file, set this to True to force the code to deserialize the content to a FileSchema file
timeout | typing.Optional[typing.Union[int, typing.Tuple]] | default is None | the timeout used by the rest client
skip_deserialization | bool | default is False | when True, headers and body will be unset and an instance of api_client.ApiResponseWithoutDeserialization will be returned

### path_params
#### RequestPathParams

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
id | IdSchema | |

#### IdSchema

Type | Description | Notes
------------- | ------------- | -------------
**str** | |

### Return Types, Responses

Code | Class | Description
------------- | ------------- | -------------
n/a | api_client.ApiResponseWithoutDeserialization | When skip_deserialization is True this response is returned
200 | ApiResponseFor200 | OK
default | ApiResponseForDefault | Unexpected error

#### ApiResponseFor200
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
response | urllib3.HTTPResponse | Raw response |
body | Unset | body was not defined |
headers | Unset | headers were not defined |

#### ApiResponseForDefault
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
response | urllib3.HTTPResponse | Raw response |
body | Unset | body was not defined |
headers | Unset | headers were not defined |


void (empty response body)

### Authorization

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)

# **endpoint_parameters**
> endpoint_parameters()
Expand Down
Expand Up @@ -19,6 +19,7 @@
from petstore_api.api.fake_api_endpoints.case_sensitive_params import CaseSensitiveParams
from petstore_api.api.fake_api_endpoints.client_model import ClientModel
from petstore_api.api.fake_api_endpoints.composed_one_of_different_types import ComposedOneOfDifferentTypes
from petstore_api.api.fake_api_endpoints.delete_coffee import DeleteCoffee
from petstore_api.api.fake_api_endpoints.endpoint_parameters import EndpointParameters
from petstore_api.api.fake_api_endpoints.enum_parameters import EnumParameters
from petstore_api.api.fake_api_endpoints.fake_health_get import FakeHealthGet
Expand Down Expand Up @@ -52,6 +53,7 @@ class FakeApi(
CaseSensitiveParams,
ClientModel,
ComposedOneOfDifferentTypes,
DeleteCoffee,
EndpointParameters,
EnumParameters,
FakeHealthGet,
Expand Down
@@ -0,0 +1,180 @@
# coding: utf-8

"""
Generated by: https://openapi-generator.tech
"""

from dataclasses import dataclass
import re # noqa: F401
import sys # noqa: F401
import typing
import urllib3
import functools # noqa: F401

from petstore_api import api_client, exceptions
import decimal # noqa: F401
from datetime import date, datetime # noqa: F401
from frozendict import frozendict # noqa: F401

from petstore_api.schemas import ( # noqa: F401
AnyTypeSchema,
ComposedSchema,
DictSchema,
ListSchema,
StrSchema,
IntSchema,
Int32Schema,
Int64Schema,
Float32Schema,
Float64Schema,
NumberSchema,
UUIDSchema,
DateSchema,
DateTimeSchema,
DecimalSchema,
BoolSchema,
BinarySchema,
NoneSchema,
none_type,
Configuration,
Unset,
unset,
ComposedBase,
ListBase,
DictBase,
NoneBase,
StrBase,
IntBase,
Int32Base,
Int64Base,
Float32Base,
Float64Base,
NumberBase,
UUIDBase,
DateBase,
DateTimeBase,
BoolBase,
BinaryBase,
Schema,
_SchemaValidator,
_SchemaTypeChecker,
_SchemaEnumMaker
)

# path params
IdSchema = StrSchema
RequestRequiredPathParams = typing.TypedDict(
'RequestRequiredPathParams',
{
'id': IdSchema,
}
)
RequestOptionalPathParams = typing.TypedDict(
'RequestOptionalPathParams',
{
},
total=False
)


class RequestPathParams(RequestRequiredPathParams, RequestOptionalPathParams):
pass


request_path_id = api_client.PathParameter(
name="id",
style=api_client.ParameterStyle.SIMPLE,
schema=IdSchema,
required=True,
)
_path = '/fake/deleteCoffee/{id}'
_method = 'DELETE'


@dataclass
class ApiResponseFor200(api_client.ApiResponse):
response: urllib3.HTTPResponse
body: Unset = unset
headers: Unset = unset


_response_for_200 = api_client.OpenApiResponse(
response_cls=ApiResponseFor200,
)


@dataclass
class ApiResponseForDefault(api_client.ApiResponse):
response: urllib3.HTTPResponse
body: Unset = unset
headers: Unset = unset


_response_for_default = api_client.OpenApiResponse(
response_cls=ApiResponseForDefault,
)
_status_code_to_response = {
'200': _response_for_200,
'default': _response_for_default,
}


class DeleteCoffee(api_client.Api):

def delete_coffee(
self: api_client.Api,
path_params: RequestPathParams = frozendict(),
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: bool = False,
) -> typing.Union[
ApiResponseFor200,
ApiResponseForDefault,
api_client.ApiResponseWithoutDeserialization
]:
"""
Delete coffee
:param skip_deserialization: If true then api_response.response will be set but
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
self._verify_typed_dict_inputs(RequestPathParams, path_params)

_path_params = {}
for parameter in (
request_path_id,
):
parameter_data = path_params.get(parameter.name, unset)
if parameter_data is unset:
continue
serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data)
# TODO add cookie handling

response = self.api_client.call_api(
resource_path=_path,
method=_method,
path_params=_path_params,
stream=stream,
timeout=timeout,
)

if skip_deserialization:
api_response = api_client.ApiResponseWithoutDeserialization(response=response)
else:
response_for_status = _status_code_to_response.get(str(response.status))
if response_for_status:
api_response = response_for_status.deserialize(response, self.api_client.configuration)
else:
default_response = _status_code_to_response.get('default')
if default_response:
api_response = default_response.deserialize(response, self.api_client.configuration)
else:
api_response = api_client.ApiResponseWithoutDeserialization(response=response)

if not 200 <= response.status <= 299:
raise exceptions.ApiException(api_response=api_response)

return api_response
Expand Up @@ -134,15 +134,21 @@ def request(
len(timeout) == 2):
timeout = urllib3.Timeout(connect=timeout[0], read=timeout[1])

if 'Content-Type' not in headers:
headers['Content-Type'] = 'application/json'

try:
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
if query_params:
url += '?' + urlencode(query_params)
if headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
if 'Content-Type' not in headers and body is None:
r = self.pool_manager.request(
method,
url,
fields=query_params,
preload_content=not stream,
timeout=timeout,
headers=headers
)
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
r = self.pool_manager.request(
method, url,
fields=fields,
Expand Down

0 comments on commit 8fc8553

Please sign in to comment.