Skip to content

[REQ][JAVA] Feature Request Description #19969

Open

Description

@robrez

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()

Activity

  1. sar009 commented on Oct 12, 2026

    @sar009

    +1. This affects the official Kubernetes Java client (kubernetes-client/java), which is
    generated with okhttp-gson. The Kubernetes API adds optional fields in minor releases, so with
    these models a cluster newer than the client fails reads, e.g. on EKS 1.37:

    The field runningInUserNamespace in the JSON string is not defined in the V1NodeSystemInfo properties

    Tracked downstream in kubernetes-client/java#4941 (earlier: kubernetes-client/java#3428, kubernetes-client/java#3980, kubernetes-client/java#4809).

    Would you accept a PR that adds a generator option, e.g. failOnUnknownProperties, defaulting to
    the current behaviour? It would skip the "check to see if the JSON string contains additional
    fields" loop in okhttp-gson/pojo.mustache, and leave the required-field and type checks as they
    are. That would let clients like kubernetes-client keep their other validation while tolerating
    schema growth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions