OpenAPITools / OpenAPITools/openapi-generator

typescript client does not respect optional parameters by default

Open
#18,191 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

According to the OpenAPI Spec, request parameters should be treated optional by default.

The client-generator for typescript treats them as mandatory by default, thus converting unspecified parameters to string undefined which may break the API:

https://github.com/OpenAPITools/openapi-generator/blob/1bfe800b9fdb74d31a41d7e7811ae1c3fbe7acd7/modules/openapi-generator/src/main/resources/typescript/api/api.mustache#L75

My suggestion is:

  1. check if the parameter is required and if not:
  2. check if the value is undefined or not before calling setHeaderParam.

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

Start with the linked modules/openapi-generator/src/main/resources/typescript/api/api.mustache template around line 75 and inspect how parameters are handled in generated TypeScript clients. The change is complete when optional, unspecified parameters are not converted to the string "undefined" before the request is sent.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.