[BUG][Kotlin] Path parameter values with slashes are not encoded correctly
Created by: segevfiner
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
If you try to pass a path parameter value that has slashes in it, it won't be escaped correctly, leading to a 404.
openapi-generator version
5.4.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Test
version: 0.1.0
paths:
/repos/{repoPath}/documents:
get:
parameters:
- schema:
type: string
in: path
name: repoPath
required: true
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties: {}
Generation Details
{
"$schema": "../node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "5.4.0",
"generators": {
"kotlin": {
"generatorName": "kotlin",
"output": "kotlin",
"inputSpec": "openapi.yaml",
"additionalProperties": {
"groupId": "test",
"packageName": "test",
"artifactVersion": "0.1.0"
}
}
}
}
}
Steps to reproduce
- Use the generated client and pass a
repoPath
that has a slash in it.
Related issues/PRs
Suggest a fix
The problem is using addPathSegments
which splits on /
and doesn't escape it in the passed string. We will have to handle escaping by ourselves and use addEncodedPathSegments
or store the path as a list of String to pass to multiple calls to addPathSegment
.