Bug Report Checklist
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");
Bug Report Checklist
Description
Path parameter encoding is using
+instead of%20for white spaces when usingnativelibrary for java.The generated code is using
ApiClient.urlEncode(param.toString())which in turn usesURLEncoder.encode(s, UTF_8).openapi-generator version
5.3.0 and master
OpenAPI declaration file content or url
{ "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
api.getSomeParam("some parameter");http://localhost:8080/api/some+parameterRelated issues/PRs
Suggest a fix
Change encoding of path params when using the
nativelibrary for java similar to okhttp implementationURLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");