OpenAPITools / OpenAPITools/openapi-generator
[REQ][JAVA] Feature Request Description
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
Using the java generator, with okhttp-gson (the default), the model classes raise exceptions whenever the API returns a property the models do not know about. It does not seem that (at least) some of the other library generators share this problem, only based on my own brief inspection of the resulting code
Describe the solution you'd like
I would like for the models to tolerate properties that weren't known at the time of generation
Describe alternatives you've considered
Vending my own template, okhttp-gson/pojo.mustache
Additional context
The code I wish to remove looks like this:
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
// ...
Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
// check to see if the JSON string contains additional fields
for (Map.Entry<String, JsonElement> entry : entries) {
if (!Action.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `Action` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
}
}
// ...
}
The code I want would exclude that block or assign entries to Collections.emptySet()
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 Java generator's okhttp-gson/pojo.mustache template and inspect the validateJsonElement logic shown in the issue. The change is complete when generated model classes tolerate API properties unknown at generation time without raising the additional-field exception; no test file is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100