Skip to content

[BUG] [JavaScript] Cannot Output Multiple Response Types #5099

Description

@kvernon

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I need to be able to address multiple objects based on status code. These could be errors objects, it could be different response objects. In the case here we have to success status code objects where each is linked to a 200 and a 202.

Swagger allows for multiple types, but the generated code seems to be blocking this additional path.

openapi-generator version

using npm

"@openapitools/openapi-generator-cli": "1.0.8-4.1.3",

OpenAPI declaration file content or url
 "/submit": {
      "post": {
        "summary": "Order",
        "description": "order to be processed.",
        "operationId": "submitCartOrder",
        "parameters": [
          {
            "name": "CartOrderSubmitRequestDto",
            "required": true,
            "in": "body",
            "schema": {
              "$ref": "#/definitions/CartOrderSubmitRequestDto"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Order successfully submitted.",
            "schema": {
              "$ref": "#/definitions/OrderDetailDto"
            }
          },
          "202": {
            "description": "Order was successfully created but requires additional information to complete processing",
            "schema": {
              "$ref": "#/definitions/ServiceExceptionResponse"
            }
          },
          "400": {
            "description": "Failed to submit order."
          }
        },
        "tags": [
          "Cart"
        ],
        "produces": [
          "application/json"
        ],
        "consumes": [
          "application/json"
        ]
      }
    },
Command line used for generation

openapi-generator generate -g typescript-fetch -o .generated -i .swagger-spec.json

Steps to reproduce

after building the json swagger spec. I would run the command.

Related issues/PRs

#1562

Suggest a fix

Not the fix, but more like where the problem resides...
In the generated code, they all go to one translation type. It should be multiple.

const response = await this.request({
            path: `/submit`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: CartOrderSubmitRequestDtoToJSON(requestParameters.cartOrderSubmitRequestDto),
        });

        //This is the problem below, it's trying to do this for only 1 response type
        return new runtime.JSONApiResponse(response, (jsonValue) => OrderDetailDtoFromJSON(jsonValue));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions