You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
For endpoints using path parameters, the generator for Java using the Retrofit 2 library creates a client that encodes characters in the parameter value according to the definition of path segments in RFC 3986.
This means that @, : and a set of other characters are not percent-encoded while e.g. / and ? are.
This does not conform to the stricter RFC 6570 that should be used for parameter expansion in this case according to the OpenAPI 3.0.3 specification:
The definition of parameter objects declares that path parameters should be serialized according to the simple style by default
According to that simple string expansion, only characters in the unreserved set are allowed
The unreserved set however contains only -, ., _, ~ as special characters.
A request containing @ in the path parameter value in fact broke for one server that received requests according to the API specification. That's how I found the issue.
Therefore, the generator should create code that expands path parameters as defined in the OpenAPI specification, i.e. according to RFC 6570, not RFC 3986. This means that anything except alphanumeric characters and -, ., _, ~ should be percent-encoded.
openapi-generator version
The issue occurs both in OpenAPI generator 4.2.3 and 5.2.1, as well as with the latest Docker image which is 5.3.0-SNAPSHOT.
Put the OpenAPI specification above in a file called api.yaml
Create a folder java-retrofit2-path-segment-encoding-example
Run the CLI command above
Modify java-retrofit2-path-segment-encoding-example/src/test/java/org/openapitools/client/api/DefaultApiTest.java such that the test method looks as follows:
The documentation for @Path says that a string converter is used to convert the value, then it is URL-encoded.
Although one can customise the string converter, this doesn't sound reasonable as it's meant for type conversion, not encoding, and I suspect it's also used in other places which could cause unexpected effects.
From a superficial look in the code, the URL encoding seems to be hard-coded and not customisable:
Therefore, it seems that @Path(encoded = true) would have to be set and the parameter value encoded according to RFC 6570 before passing it to the actual client method.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
For endpoints using path parameters, the generator for Java using the Retrofit 2 library creates a client that encodes characters in the parameter value according to the definition of path segments in RFC 3986.
This means that
@
,:
and a set of other characters are not percent-encoded while e.g./
and?
are.This does not conform to the stricter RFC 6570 that should be used for parameter expansion in this case according to the OpenAPI 3.0.3 specification:
simple
style by default-
,.
,_
,~
as special characters.A request containing
@
in the path parameter value in fact broke for one server that received requests according to the API specification. That's how I found the issue.Therefore, the generator should create code that expands path parameters as defined in the OpenAPI specification, i.e. according to RFC 6570, not RFC 3986. This means that anything except alphanumeric characters and
-
,.
,_
,~
should be percent-encoded.openapi-generator version
The issue occurs both in OpenAPI generator 4.2.3 and 5.2.1, as well as with the latest Docker image which is
5.3.0-SNAPSHOT
.OpenAPI declaration file content or url
Generation Details
Steps to reproduce
api.yaml
java-retrofit2-path-segment-encoding-example
java-retrofit2-path-segment-encoding-example/src/test/java/org/openapitools/client/api/DefaultApiTest.java
such that the test method looks as follows:As can be seen,
@
and:
are not percent-encoded.Related issues/PRs
/
in path parametersSuggest a fix
The generated client method looks as follows:
The documentation for
@Path
says that a string converter is used to convert the value, then it is URL-encoded.Although one can customise the string converter, this doesn't sound reasonable as it's meant for type conversion, not encoding, and I suspect it's also used in other places which could cause unexpected effects.
From a superficial look in the code, the URL encoding seems to be hard-coded and not customisable:
Therefore, it seems that
@Path(encoded = true)
would have to be set and the parameter value encoded according to RFC 6570 before passing it to the actual client method.The text was updated successfully, but these errors were encountered: