swagger-api / swagger-api/swagger-codegen
Python client code is wrong when an endpoint accept multiple MediaTypes
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
My OpenApi 3.0 specification contains an endpoint for which the response media type can be application/octet-stream or, if the query cannot be completed, application/json.
The generated Python client code builds a query with a MediaType being the concatenation of both: application/octet-streamapplication/json
Swagger-codegen version
Codegen 3.0.0-rc1
Swagger declaration file content or url
Below is my (simplified) OpenApi specification:
openapi: 3.0.0
servers:
- url: http://localhost/myapi
info:
version: "1.0"
title: My API
security:
- basicAuth: []
paths:
/download:
get:
operationId: download
responses:
200:
description: OK
content:
application/octet-stream:
schema:
type: string
format: binary
500:
description: Error
content:
application/json:
schema:
type: string
Command line used for generation
I call Swagger Codegen directly from my Java application:
CodegenConfigurator configurator = new CodegenConfigurator();
configurator.setInputSpec("spec.yml");
configurator.setGeneratorName("python");
configurator.setOutputDir("out");
new DefaultGenerator().opts(configurator.toClientOptInput()).generate();
Python test file
Running this script
import unittest
import openapi_client
configuration = openapi_client.Configuration()
configuration.debug = True
# create an instance of the API class
api_instance = openapi_client.DefaultApi(openapi_client.ApiClient(configuration))
class TestModels(unittest.TestCase):
def test_download(self):
api_instance.download()
if __name__ == '__main__':
unittest.main()
results in the following output:
2018-07-02 15:17:38,841 DEBUG Starting new HTTP connection (1): localhost
send: 'GET /myapi HTTP/1.1\r\nHost: localhost:10080\r\nAccept-Encoding: identity\r\nContent-Type: application/json\r\nAccept: application/octet-streamapplication/json\r\nAuthorization: Basic c2VtYWRtaW46c2VtYWRtaW4=\r\nUser-Agent: OpenAPI-Generator/1.0.0/python\r\n\r\n'
reply: 'HTTP/1.1 406 Not Acceptable\r\n'
...
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
Start with the generated Python client's request construction for the /download operation and compare it with the OpenAPI response content entries for application/octet-stream and application/json. Reproduce the issue with the provided spec and test script. Done means the generated request sends valid separate media types and no longer concatenates them into application/octet-streamapplication/json.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100