swagger-api / swagger-api/swagger-codegen
[PYTHON] multipart/form-data syntaxe for codegen
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When running swagger-codegen-v3 from docker for post.
post:
summary: Create something
operationId: createSomething
requestBody:
required: true
content:
multipart/form-data:
schema:
allOf:
- $ref: '#/components/schemas/SomethingProperties'
- type: object
properties:
file:
type: array
items:
type: string
format: binary
Does not produce the body for method create_something. By replacing multipart/form-data by multipart/formdata, the correct body model is added as argument for create_something. But does not send the files by giving a file path.
def create_something(self, body, **kwargs): # noqa: E501
"""
:param async_req bool
:param Body1 body: (required)
:return: InlineResponse2004
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('async_req'):
return self.create_something_with_http_info(body, **kwargs) # noqa: E501
else:
(data) = self.create_something_with_http_info(body, **kwargs) # noqa: E501
return data
Usage:
from __future__ import print_function
import app_pyclient
from app_pyclient.models import Body1, SomethingProperties
from app_pyclient.rest import ApiException
from pprint import pprint
import app_pyclient
configuration = app_pyclient.Configuration()
api_instance = app_pyclient.SomethingApi(app_pyclient.ApiClient(configuration))
try:
file = 'path/to/a/file'
payload = {'something_arg_1': 'value'}
body = Body1([file,], **payload)
api_response = api_instance.create_something(body=body)
pprint(api_response)
except ApiException as e:
print(e)
response: Cannot prepare a request message for provided arguments. Please check that your arguments match declared content type.
Swagger-codegen version
3.0.25
docker pull swaggerapi/swagger-codegen-cli-v3:3.0.25
Command line used for generation
docker run --rm -v "${PWD}:/local" swaggerapi/swagger-codegen-cli-v3:3.0.25 generate -i /local/my-specification.yaml -DpackageName=mypackage -l python -o /local/out/python
Steps to reproduce
Run the sample code provided.
Error message: Cannot prepare a request message for provided
arguments. Please check that your arguments match
declared content type.
Related issues/PRs
Suggest a fix/enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided OpenAPI schema using swagger-codegen 3.0.25 and the Python generator. Compare the generated create_something method and request handling for multipart/form-data versus multipart/formdata; done means the standard content type generates a usable body and successfully sends a file path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, openapi, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100