Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Schema Inaccuracy] response content type mismatch #2274

Open
dahpgjgamgan opened this issue Mar 4, 2023 · 0 comments
Open

[Schema Inaccuracy] response content type mismatch #2274

dahpgjgamgan opened this issue Mar 4, 2023 · 0 comments
Labels

Comments

@dahpgjgamgan
Copy link

dahpgjgamgan commented Mar 4, 2023

Schema Inaccuracy

disclaimer: I am neither an openapi nor an openapi-generator expert, and I'm interacting with github enterprise instance at my company, not 100% sure if the issue I'm facing really is a spec inaccuracy, but I thought this would be a good first step to ask before deciding to file the issue somewhere else)

An openapi-generator client generated from from https://github.com/github/rest-api-description/tree/main/descriptions/ghes-3.6 cannot accept any response from the server due to content type mismatch.

Expected

Schema declares all responses to be sent with "application/json" content type, e.g:

        "responses": {
          "200": {
            "description": "Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/global-hook-2"
                },
                "examples": {
                  "default": {
                    "$ref": "#/components/examples/global-hook-2"
                  }
                }
              }
            }
          }
        },

but (on the instance I'm testing) they're sent with: application/json; charset=utf-8

which is not accepted by the client I'm using (more details in reproduction steps)

Reproduction Steps

  1. Generate a python client with openapi-generator (6.4.0):
curl https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/ghes-3.6/ghes-3.6.json > openapi_clients/ghes-3.6.json

export _JAVA_OPTIONS="--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED -Xmx16G"
openapi-generator generate  -g python -i openapi_clients/ghes-3.6.json -o openapi_clients/github_openapi_client --package-name=github_openapi_client

use it like this (change auth/call args as applicable):

  import github_openapi_client as github_client
  import github_openapi_client.apis.tags.pulls_api as pulls_api
  
  configuration = github_client.Configuration(
      host="XYZ",
      # possibly other auth options
  )
  api_client = github_client.ApiClient(configuration)
  test_client = pulls_api.PullsApi(api_client)

  pull = test_client.pulls_get({
      "owner": "org_name",
      "repo": "repo_name",
      "pull_number": 111111111
  })
  assert pull is not None

run the code.

expected: the code executes fine.
actual: parsing the response from server fails with:

E               github_openapi_client.exceptions.ApiValueError: Invalid content_type returned. Content_type='application/json; charset=utf-8' was returned when only {'application/json'} are defined for status_code=200

(if I modify the schema json to change all instances of application json to one containing charsets, eg, via: sed -i '' 's/"application\/json"/"application\/json; charset=utf-8"/g' openapi_clients/ghes-3.6_with_charsets.json) the error goes away

I do recieve a different one, that's a separate issue though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants