Skip to content

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

Open
@eirikthon

Description

@eirikthon

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
#7215

Suggest a fix

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

Change "pipe" to "pipes"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions