[BUG][JAVA] Path parameter encoding is using + instead of %20 for white spaces
Created by: sorin-florea
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
Path parameter encoding is using +
instead of %20
for white spaces when using native
library for java.
The generated code is using ApiClient.urlEncode(param.toString())
which in turn uses URLEncoder.encode(s, UTF_8)
.
openapi-generator version
5.3.0 and master
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Bug reproducer
description: API for param encoding
version: "1.0.0"
servers:
- url: localhost:8080
paths:
/api/{someParam}:
parameters:
- in: path
name: someParam
schema:
type: string
required: true
description: Some parameter.
get:
operationId: GetSomeParam
summary: View some param
responses:
'200':
description: Some return value
content:
application/json:
schema:
$ref: '#/components/schemas/SomeReturnValue'
example:
someParam: someValue
components:
schemas:
SomeReturnValue:
type: object
required:
- someParam
properties:
someParam:
type: string
{
"library": "native",
"dateLibrary": "java8",
"modelPackage": "com.api.model",
"apiPackage": "com.api",
"invokerPackage": "com.api.client",
"hideGenerationTimestamp": true,
"openApiNullable": false,
"useBeanValidation": false,
"additionalModelTypeAnnotations": "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)"
}
Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java --library native -i openapi.yaml -o client-test
Steps to reproduce
- generate client and call
api.getSomeParam("some parameter");
- observe that the path is
http://localhost:8080/api/some+parameter
Related issues/PRs
Suggest a fix
Change encoding of path params when using the native
library for java similar to okhttp implementation URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");