Bug Report Checklist
Description
Given an OpenAPI specification for an endpoint that defines a request body for a content type that does not contain 'json' as a substring, and has a parameter defined (e.g. charset=UTF-8), then the request preparation will fail in generated client library when calling the respective endpoint.
openapi-generator version
7.23.0
OpenAPI declaration file content or url
openapi: 3.1.1
info:
title: Example
version: 1.0.0
paths:
/example:
post:
summary: Example
operationId: example
requestBody:
content:
multipart/form-data;charset=UTF-8:
schema:
type: object
properties:
field:
type: string
responses:
"200":
description: "Example"
Generation Details
java -jar openapi-generator-cli.jar generate -g python -i apispec.yml -o output
Steps to reproduce
- Create a new file called
apispec.yml from the yaml above.
- Download the latest openapi-generator-cli.jar and put it in the same folder.
- Run the command above.
- Run
cd output.
- Install the client
python setup.py install --user
- Run the following python script:
from openapi_client import DefaultApi, ApiClient, Configuration
configuration = Configuration(host="http://localhost")
api_client = ApiClient(configuration=configuration)
default_api = DefaultApi(api_client)
default_api.example(var_field="test")
The following error trace will be printed to console, instead of the request being sent:
Traceback (most recent call last):
File "/example/test.py", line 6, in <module>
default_api.example(var_field="test")
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/python313/Lib/site-packages/pydantic/_internal/_validate_call.py", line 40, in wrapper_function
return wrapper(*args, **kwargs)
File "/python313/Lib/site-packages/pydantic/_internal/_validate_call.py", line 137, in __call__
res = self.__pydantic_validator__.validate_python(pydantic_core.ArgsKwargs(args, kwargs))
File "/python313/site-packages/openapi_client/api/default_api.py", line 94, in example
response_data = self.api_client.call_api(
*_param,
_request_timeout=_request_timeout
)
File "/python313/site-packages/openapi_client/api_client.py", line 282, in call_api
raise e
File "/python313/site-packages/openapi_client/api_client.py", line 274, in call_api
response_data = self.rest_client.request(
method, url,
...<2 lines>...
_request_timeout=_request_timeout
)
File "/python313/site-packages/openapi_client/rest.py", line 247, in request
raise ApiException(status=0, reason=msg)
openapi_client.exceptions.ApiException: (0)
Reason: Cannot prepare a request message for provided
arguments. Please check that your arguments match
declared content type.
Related issues/PRs
I could not find any existing issue describing this exact same problem.
Suggest a fix
Adjust the content-type matching code in rest.py to account for parameters. I will create a PR.
Bug Report Checklist
Description
Given an OpenAPI specification for an endpoint that defines a request body for a content type that does not contain 'json' as a substring, and has a parameter defined (e.g.
charset=UTF-8), then the request preparation will fail in generated client library when calling the respective endpoint.openapi-generator version
7.23.0
OpenAPI declaration file content or url
Generation Details
java -jar openapi-generator-cli.jar generate -g python -i apispec.yml -o outputSteps to reproduce
apispec.ymlfrom the yaml above.cd output.python setup.py install --userThe following error trace will be printed to console, instead of the request being sent:
Related issues/PRs
I could not find any existing issue describing this exact same problem.
Suggest a fix
Adjust the content-type matching code in
rest.pyto account for parameters. I will create a PR.