Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #440
Closed
Open
Issue created Jul 03, 2018 by Administrator@rootContributor

[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'
...
Assignee
Assign to
Time tracking