OpenAPITools / OpenAPITools/openapi-generator
Regarding optional requestParams getting added to Body section during code generation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Version of openapigenerator : v4.3.0
Issue description: In my openapi file if the entry of requestparams is like this
/v1/request-type/list:
post:
tags:
- request-type
summary: Testing
description: Testing
operationId: addRequestTypeList
requestBody:
content:
'/':
schema:
type: array
items:
$ref: '#/components/schemas/RequestType'
so the corresponding code that is getting gererated is like below
export interface AddRequestTypeListRequest {
requestType?: Array;
}
const response = await this.request({
path: /v1/request-type/list,
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: requestParameters.requestType.map(RequestTypeToJSON),
});
which gives error during compile time as
(property) AddRequestTypeListRequest.requestType?: RequestType[] | undefined
Object is possibly 'undefined'.
Ideally the body content should be created like this optional to resolve the above error
body: requestParameters.requestType.?map(RequestTypeToJSON),
Also checked the github code for the same. Can we add this provision or is there any other way
https://github.com/OpenAPITools/openapi-generator/blob/v4.3.0/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache
line no 255
line no 21
Can you help me to resolve this issue
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 in modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache at the referenced lines and inspect how optional request parameters are emitted into generated request bodies. Reproduce the v4.3.0 TypeScript fetch output from the issue and verify that the generated code compiles without an undefined optional-parameter error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100