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

[BUG] generated response body is always dynamic when status code is 202 #527

Closed
dJani97 opened this issue Dec 30, 2022 · 1 comment · Fixed by #529
Closed

[BUG] generated response body is always dynamic when status code is 202 #527

dJani97 opened this issue Dec 30, 2022 · 1 comment · Fixed by #529
Assignees
Labels
bug Something isn't working Triage needed

Comments

@dJani97
Copy link

dJani97 commented Dec 30, 2022

Describe the bug

When the response status code is 202, the response body type is not generated properly.

For example, change "200" to "202" in pet_service_json.json:

"/pet/{petId}": {
  "get": {
    "tags": [
      "pet"
    ],
    "summary": "Find pet by ID",
    "description": "Returns a single pet",
    "operationId": "getPetById",
    "produces": [
      "application/xml",
      "application/json"
    ],
    "parameters": [
      {
        "name": "petId",
        "in": "path",
        "description": "ID of pet to return",
        "required": true,
        "type": "integer",
        "format": "int64"
      }
    ],
    "responses": {
      "202": {
        "description": "successful operation",
        "schema": {
          "$ref": "#/definitions/Pet"
        }
      },
      "400": {
        "description": "Invalid ID supplied"
      },
      "404": {
        "description": "Pet not found"
      }
    },
  },

The generated code looks like this:

Future<chopper.Response> petPetIdGet //...

But it should look like this:

Future<chopper.Response<Pet>> petPetIdGet //...

The type is lost when the status is 202.

I have a swagger JSON file full of such 202 responses, and currently the only workaround is to manually replace them with 200.

Library versions used:
Latest example project

@dJani97 dJani97 added bug Something isn't working Triage needed labels Dec 30, 2022
@ihadabs
Copy link

ihadabs commented Dec 31, 2022

Same thing if schema was under responses.200.content.application/json.schema which is for OpenAPI 3

It should be able to handle:
responses.200.content.application/json.schema

Currently, it only handles:
responses.200.schema

Ref:
https://swagger.io/docs/specification/describing-responses/

Example:

{
   "paths":{
      "/health":{
         "get":{
            "responses":{
               "200":{
                  "description":"Default Response",
                  "content":{
                     "application/json":{
                        "schema":{
                           "type":"object",
                           "properties":{
                              "message":{
                                 "type":"string",
                                 "pattern":"ok"
                              },
                              "uptime":{
                                 "type":"number"
                              },
                              "date":{
                                 "type":"string",
                                 "format":"date-time"
                              }
                           },
                           "required":[ "message", "uptime", "date" ],
                           "additionalProperties":false
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Triage needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants