OpenAPITools / OpenAPITools/openapi-generator
[BUG][KOTLIN][KTOR] Mismatching collection delimiter for pipes
Nobody has claimed this yet.
- 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
- Create a yaml-file with the provided spec named
Example.yaml - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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