OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java] Incompatibility between typeMapping and supportUrlQuery
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 (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?
Description
When using type mapping for some model objects to Map with native library, the generator produces a class that doesn't compile because the type mapping is not taken into account in the toUrlQueryString() method. While the attribute type has been correctly changed following the type mapping, the implementation of toUrlQueryString() doesn't take the change into account calling an non-existent method.
The problem happens by default with native library (because supportUrlQuery is set to true by default for this library), but if you explicitly set supportUrlQuery to false, the result builds (because there's no toUrlQueryString() method).
The problem happens also for other libraries if you explicitly set supportUrlQuery to true.
private Map fields;
...
public Map getFields() {
return fields;
}
....
if (getFields() != null) {
joiner.add(getFields().toUrlQueryString(prefix + "fields" + suffix)); // <= DOESN'T COMPILE
}
....
openapi-generator version
I saw the problem with version 6.6.0, but I reproduced the problem with master : see the sample and test reproducing the problem
OpenAPI declaration file content or url
Simple OpenAPI declaration file used by the test reproducing the problem
Generation Details
See test reproducing the problem.
Steps to reproduce
See test reproducing the problem.
The generated model file shouldn't call getFields().toUrlQueryString().
Related issues/PRs
Suggest a fix
The problem seems to happen because pojo.mustache relies on {{#isModel}} to decide if it can use a call to toUrlQueryString() instead of a manual encoding (Java/pojo.mustache, Java/libraries/native/pojo.mustache) but {{#isModel}} doesn't take into account the type mapping.
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 with the linked reproducing test and compare the Java template files at modules/openapi-generator/src/main/resources/Java/pojo.mustache and Java/libraries/native/pojo.mustache, focusing on their isModel handling. Regenerate the sample model with typeMapping and supportUrlQuery enabled; done means the generated model no longer calls toUrlQueryString() on a mapped Map and compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100