OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-fetch] query params ignores content application/json

Open
#13,222 0 comments 3 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

the query parameter is not serialized as JSON, but exploded:

/customer/2000/audio/files/page?filters[durationMin]=151000&filters[durationMax]=337000

instead of:

/customer/2000/audio/files/page?filters=%7B%22durationMin%22%3A151000%2C%22durationMax%22%3A337000%7D

(obtained by encodeURIComponent(JSON.stringify({durationMin: 151000, durationMax: 337000})) )

openapi-generator version

6.0.1 but with locally installed, up-to-date typescript-fetch template

OpenAPI declaration file content or url

Full File as Gist

important lines:

        - in: query
          name: filters
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/QueryFilter"
Generation Details
openapi-generator generate -i ./openapi.yaml -g typescript-fetch -c ./swagger/clientgen.config.json -o ./src/lib/api/

./swagger/clientgen.config.json:

{
    "allowUnicodeIdentifiers": true,
    "modelPropertyNaming": "camelCase",
    "enumPropertyNaming": "camelCase",
    "paramNaming": "camelCase",
    "nullSafeAdditionalProps": true,
    "supportsES6": true,
    "typescriptThreePlus": true,
    "withoutRuntimeChecks": true,
    "legacyDiscriminatorBehavior": false
}

Steps to reproduce
  1. generate with given config
  2. call the api
Suggest a fix

this may be only a template issue. The function that currently creates the fetch params in the runtime
does not handle JSON serialization.

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 modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache, particularly the fetch-parameter logic around lines 114-157. Reproduce the issue using the linked OpenAPI declaration and the shown typescript-fetch generation command and configuration. Done means a query parameter declared with application/json is serialized as an encoded JSON value rather than exploded properties.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.