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
  • #4999
Closed
Open
Issue created Jan 14, 2020 by Administrator@rootContributor

[BUG][typescript-axios] emits wrong collection format code for parameter

Created by: DavidBiesack

Description

generator for typescript-axios and other typescript-* generators incorrectly generates pipe when the collection format is pipes.

openapi-generator version

4.2.3-SNAPSHOT

OpenAPI declaration file content or url

pipes.yaml:

swagger: '2.0'
info:
  title: pipes
  version: '0.0.0'
basePath: /test
paths:
  /data:
    get:
      parameters:
        - name: typeQueryParam
          in: query
          description: >-
            Subset the items to those matching one or more types (pipe-separated).
          type: array
          collectionFormat: pipes
          items:
            type: string
            enum:
              - a
              - b
              - c
              - d
      responses:
        '200':
          description: OK
Command line used for generation
openapi-generator generate -g typescript-axios -i pipes.yaml -o __sdk
Steps to reproduce

run the above command. The generated __sdk/api.ts contains

                localVarQueryParameter['typeQueryParam'] = typeQueryParam.join(COLLECTION_FORMATS.pipe);

but pipe should be pipes:

                localVarQueryParameter['typeQueryParam'] = typeQueryParam.join(COLLECTION_FORMATS.pipes);

The Mustache template ./modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache line looks correct

                localVarFormParams.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS.{{collectionFormat}}));{{/multipartFormData}}{{#multipartFormData}}

so perhaps openapi-codegen is converting the pipes in the source to the template variable {{collectionFormat}} with value pipe instead.

Related issues/PRs
Suggest a fix

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

        } else if (Parameter.StyleEnum.PIPEDELIMITED.equals(parameter.getStyle())) {
            return "pipe";

should be

protected String getCollectionFormat(Parameter parameter) {
...
    } else if (Parameter.StyleEnum.PIPEDELIMITED.equals(parameter.getStyle())) {
        return "pipes";

The line below looks incorrect as well:
    } else if (Parameter.StyleEnum.SPACEDELIMITED.equals(parameter.getStyle())) {
        return "space";

should be
    } else if (Parameter.StyleEnum.SPACEDELIMITED.equals(parameter.getStyle())) {
        return "ssv";
in order to match the generated definition

/** *

  • @export */ export const COLLECTION_FORMATS = { csv: ",", ssv: " ", tsv: "\t", pipes: "|", };

I can submit a PR
Assignee
Assign to
Time tracking