swagger-api / swagger-api/swagger-codegen

ResponseClass is not translated to a response when converting 1.1 spec to 2.0 or 3.0

Open
#8,974 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When trying to convert a swagger 1.1 spec to 2.0 or 3.0 all the responses are missing response bodies. (A GET end-point that should return something only lists the error responses)

For example:

This part of the 1.1 spec has a responseClass field of type Channel

"path": "/channels/{channelId}",
            "description": "Active channel",
            "operations": [
                {
                    "httpMethod": "GET",
                    "summary": "Channel details.",
                    "nickname": "get",
                    "responseClass": "Channel",
                    "parameters": [
                        {
                            "name": "channelId",
                            "description": "Channel's id",
                            "paramType": "path",
                            "required": true,
                            "allowMultiple": false,
                            "dataType": "string"
                        }
                    ],
                    "errorResponses": [
                        {
                            "code": 404,
                            "reason": "Channel not found"
                        }
                    ]
                },

But the generated 2.0 spec has no response with a body

"/channels/{channelId}" : {
      "get" : {
        "tags" : [ "api-docschannels.{format}" ],
        "summary" : "Channel details.",
        "operationId" : "get",
        "parameters" : [ {
          "name" : "channelId",
          "in" : "path",
          "description" : "Channel's id",
          "required" : true,
          "type" : "string"
        } ],
        "responses" : {
          "404" : {
            "description" : "Channel not found"
          }
        }
      },

I would expect something like this to be present in the 2.0 variant

      "responses": {
          "200": {
            "description": "Some description",
            "schema": {
              "$ref": "#/definitions/Channel"
            }            
          },

How can I fix this problem, or is there another way to upgrade my 1.1 spec to a higher version so that the newer codegenerators will work with it?

Swagger-codegen version

I've tried 2.4.0, 2.3.1 and 3.0.0

Swagger declaration file content or url

See above

Command line used for generation

java -jar .\swagger-codegen-cli.jar generate -i ./resources.json -l swagger -o ./swagger

Where resources.json has the BasePath "." and lists all the apis that are in json files in the same directory.

Steps to reproduce
  1. Input a 1.1 swagger spec file with at least one path that contains a responseClass
  2. Generate the 2.0 or 3.0 swagger spec
  3. The output swagger file has no response body

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the listed Java swagger-codegen command with a Swagger 1.1 input containing responseClass. Trace the 1.1-to-2.0/3.0 conversion handling for responseClass, then verify that the generated document includes a success response whose schema references #/definitions/Channel alongside the existing error response.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.