OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-fetch] collectionFormat option is ignored for code generation

Open
#19,200 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I have identified an issue with the typescript-fetch code generator. The collectionFormat option, which is used for specifying the format of array parameters, is not being respected during code generation. Regardless of the collectionFormat specified in the OpenAPI specification, the generated code consistently defaults to using the CSV format.

openapi-generator version

7.7.0

OpenAPI declaration file content or url

A complete reproduction of this issue can be found in the following Replit environment:
https://replit.com/@sherlockdoyle19/openapi-issue

Generation Details

The generated code is available in the provided Replit. To regenerate the files, one can execute the npm run build script within the Replit console.

Alternatively, the following command can be used:

openapi-generator-cli generate -i openapi.json -g typescript-fetch -o ./generated
Steps to reproduce
  1. Create an OpenAPI specification file containing a parameter of type array.
  2. Set various collectionFormat options for different array parameters.
  3. Generate the typescript-fetch code using the OpenAPI Generator.
  4. Examine the generated code, particularly focusing on how array parameters are handled.

In the provided Replit, I have defined three parameters, each with a different collectionFormat. However, in the generated code, all three parameters utilize runtime.COLLECTION_FORMATS["csv"], disregarding the specified formats.

Related issues/PRs

A potentially similar issue: https://github.com/OpenAPITools/openapi-generator/issues/18506

Suggest a fix

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 OpenAPI declaration and generated code in the linked Replit environment, then run the documented openapi-generator-cli command or npm run build. Compare the generated handling of the three array parameters and their collectionFormat values; done means typescript-fetch preserves each specified format instead of defaulting all parameters to csv.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.