OpenAPITools / OpenAPITools/openapi-generator

[BUG][KOTLIN][KTOR] Mismatching collection delimiter for pipes

Open
#21,503 3 comments 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?
  • 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

When generating kotlin client apis using ktor for a spec that contains pipe delimited query parameters, the generated client does not separate the parameters correctly which results in an error when using the client. There seems to be an error in the ApiAbstractions-template for the method that translates the collectionFormat to a delimiter:

{{#nonPublicApi}}internal {{/nonPublicApi}}{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}fun collectionDelimiter(collectionFormat: String): String = when(collectionFormat) {
    "csv" -> ","
    "tsv" -> "\t"
    "pipe" -> "|"
    "space" -> " "
    else -> ""
}

The collectionFormat in this case is "pipes" but the method expects "pipe" and defaults to "" when there is no match. I think changing "pipe" to "pipes" in this template will fix the error.

openapi-generator version

I used version 7.14 and have not tried any earlier versions to see if this is a regression.

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Example-API
  version: 1.0.0
paths:
  /ping:
    get:
      summary: Example endpoint
      parameters:
        - name: fleetId
          in: query
          style: pipeDelimited
          schema:
            type: array
            items:
              type: string

      responses:
        '200':
          description: OK
Generation Details
generatorName: kotlin
outputDir: generated-server
library: jvm-ktor
inputSpec: Example.yaml
Steps to reproduce
  1. Create a yaml-file with the provided spec named Example.yaml
  2. run:
    openapi-generator generate
    -i Example.yaml
    -g kotlin
    --library jvm-ktor
    -o generated-server
Related issues/PRs

This seems to be a similar issue for typescript-axios
https://github.com/OpenAPITools/openapi-generator/issues/7215

Suggest a fix

At
modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiAbstractions.kt.mustache:8

Change "pipe" to "pipes"

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 at modules/openapi-generator/src/main/resources/kotlin-client/infrastructure/ApiAbstractions.kt.mustache:8 and inspect the collectionDelimiter mapping. Reproduce with Example.yaml using the kotlin generator and jvm-ktor library. Done means pipe-delimited query parameters use the expected delimiter instead of producing an empty delimiter.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.