Skip to content

[Schema Inaccuracy] response content type mismatch #2274

Open
@dahpgjgamgan

Description

@dahpgjgamgan

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dahpgjgamgan@ahoglund

        Issue actions

          [Schema Inaccuracy] response content type mismatch · Issue #2274 · github/rest-api-description