Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #10438
Closed
Open
Issue created Sep 21, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][typescript-fetch] Query parameters with `explode: true` not supported

Created by: dcasado

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 generated code does not take into account the field explode: true. It should generate separate parameters for each key-value pair of the map for the request as the specification says.

Passing an object to a query parameter that has the property explode: true eg "filters":{"lang": "en", "scope":"mobile"} the expected behavior is to generate ?lang=en&scope=mobile but the actual generated query is ?filters[lang]=en&filters[scope]=mobile

openapi-generator version

5.2.1

OpenAPI declaration file content or url
info:
  title: Example
  version: 1.0.0
openapi: 3.0.3
paths:
  "/resource":
    parameters:
      - name: filters
        in: query
        required: true
        schema:
          type: object
          additionalProperties:
            type: string
          example:
            lang: en
            scope: mobile
        style: form
        explode: true
    get:
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                properties:
                  id:
                    type: string
                type: object
Generation Details

Use generator [typescript-fetch] with default options

generatorName: typescript-fetch
Steps to reproduce
  1. Generate code
  2. Call await DefaultApi().resourceGet({filters:{lang: "en", scope: "mobile"}})
  3. See that request has filters[lang]=en&filters[scope]=mobile as query parameters
Related issues/PRs
Suggest a fix

The template code it does not take into account if the parameter has explode: true to assign it to the query parameters. https://github.com/OpenAPITools/openapi-generator/blob/ef0186c9cff7a14f7af6e1e7b6efc0a44b049a18/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache#L117

{{^isArray}}
if (requestParameters.{{paramName}} !== undefined) {
    {{#isDateTime}}
    queryParameters['{{baseName}}'] = (requestParameters.{{paramName}} as any).toISOString();
    {{/isDateTime}}
    {{^isDateTime}}
    {{#isDate}}
    queryParameters['{{baseName}}'] = (requestParameters.{{paramName}} as any).toISOString().substr(0,10);
    {{/isDate}}
    {{^isDate}}
    queryParameters['{{baseName}}'] = requestParameters.{{paramName}};
    {{/isDate}}
    {{/isDateTime}}
}

{{/isArray}}

We can add another case to check if the parameter is an object and has explode to true and generate the necessary code accordingly.

{{^isArray}}
if (requestParameters.{{paramName}} !== undefined) {
    {{#isDateTime}}
    queryParameters['{{baseName}}'] = (requestParameters.{{paramName}} as any).toISOString();
    {{/isDateTime}}
    {{^isDateTime}}
    {{#isDate}}
    queryParameters['{{baseName}}'] = (requestParameters.{{paramName}} as any).toISOString().substr(0,10);
    {{/isDate}}
    {{^isDate}}
    {{#isContainer}}
    {{#isExplode}}
    for (const key in requestParameters.{{paramName}}) {
        queryParameters[key] = requestParameters.{{paramName}}[key]
    }
    {{/isExplode}}
    {{^isExplode}}
    queryParameters['{{baseName}}'] = requestParameters.{{paramName}};
    {{/isExplode}}
    {{/isContainer}}
    {{^isContainer}}
    queryParameters['{{baseName}}'] = requestParameters.{{paramName}};
    {{/isContainer}}
    {{/isDate}}
    {{/isDateTime}}
}

{{/isArray}}
Assignee
Assign to
Time tracking