[Python] Client code is wrong when an endpoint accepts multiple MediaTypes
Created by: raubel
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
openapi-generator version
3.0.3
OpenAPI 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 the generator 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 with the generated openapi_client
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'
...