OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JavaScript] Cannot Output Multiple Response Types
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
https://github.com/OpenAPITools/openapi-generator/issues/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));
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the shown openapi-generator command with the provided /submit specification, then inspect the generated typescript-fetch response handling around JSONApiResponse. Compare the generated behavior for the 200 and 202 responses; done means the client can distinguish and expose both response types instead of mapping only to OrderDetailDto.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100