Skip to content

[BUG][JAVA][jaxrs-spec] OAS 3.1: additionalProperties: false with inline object property generates non-compiling accessors #25430

Open

Description

@kurellajunior

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

With OpenAPI 3.1, a closed schema (additionalProperties: false) that has an inline object property gets the additional-properties accessors from JavaJaxRS/spec/additional_properties.mustache, but the class does not extend HashMap. The generated model does not compile:

public class PatchRequest   {
  ...
  @JsonAnySetter
  public PatchRequest putAdditionalProperty(String key, Object value) {
    this.put(key, value);   // cannot find symbol
    return this;
  }

  @JsonAnyGetter
  public Map<String, Object> getAdditionalProperties() {
    return this;            // incompatible types: PatchRequest cannot be converted to Map<String,Object>
  }

Expected: no accessors for a closed schema, as with OpenAPI 3.0.3.

Observations:

  • The same spec with openapi: 3.0.3 compiles and has no accessors.
  • Without additionalProperties: false on PatchRequest it compiles and has no accessors.
  • A $ref to a named local schema instead of the inline object does not trigger it. A $ref into another file does (seen in our real spec, not reduced further).
  • additionalProperties: true works as expected (extends HashMap<String, Object>).
openapi-generator version

7.26.0 (jaxrs-spec). Not a regression we know of.

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: Minimal reproduction
  version: 1.0.0
paths:
  /patch:
    post:
      operationId: patch
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PatchRequest"
      responses:
        "204":
          description: No content
components:
  schemas:
    PatchRequest:
      type: object
      properties:
        context:
          type: object
          additionalProperties: true
      additionalProperties: false
Generation Details

Default options:

java -jar openapi-generator-cli-7.26.0.jar generate -g jaxrs-spec -i openapi.yaml -o out
Steps to reproduce
  1. Generate as above.
  2. cd out && mvn compile
Related issues/PRs
Suggest a fix

Workaround in a custom template directory: wrap the partial in {{#parent}}…{{/parent}}, so the accessors are only rendered for models that extend a map. The root cause seems to be that the model is flagged with additionalProperties without getting the map parent.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

Activity

  1. jsteenbeeke commented on Nov 3, 2026

    @jsteenbeeke

    We hit this too. Two things that may help:

    It is a regression in 7.20.0. 7.19.0 generates a compiling model for the spec below, and 7.20.0 through 7.27.0 do not. The model state may already have been wrong before, but it only became visible when JavaJaxRS/spec/additional_properties.mustache was added and included from pojo.mustache in 7.20.0.

    An inline object property is not required to trigger it. A single schema with only scalar properties is enough:

    openapi: 3.1.0
    info:
      title: Minimal reproduction
      version: 1.0.0
    paths: {}
    components:
      schemas:
        Cookie:
          type: object
          additionalProperties: false
          properties:
            name:
              type: string
    <plugin>
      <groupId>org.openapitools</groupId>
      <artifactId>openapi-generator-maven-plugin</artifactId>
      <version>7.27.0</version>
      <executions>
        <execution>
          <goals>
            <goal>generate</goal>
          </goals>
          <configuration>
            <inputSpec>${project.basedir}/openapi.yaml</inputSpec>
            <generatorName>jaxrs-spec</generatorName>
          </configuration>
        </execution>
      </executions>
    </plugin>

    mvn compile on the generated project fails:

    Cookie.java:[60,9] cannot find symbol
    Cookie.java:[70,12] incompatible types: org.openapitools.model.Cookie cannot be converted to java.util.Map<java.lang.String,java.lang.Object>
    Cookie.java:[79,16] cannot find symbol
    
    Version openapi: 3.1.0 openapi: 3.0.3
    7.19.0 compiles compiles
    7.20.0 fails
    7.26.0 fails compiles
    7.27.0 fails

    Which schema is affected seems to depend on more than the schema itself:

    • With a second, identical schema (Other) added to the spec above, only Cookie is affected; Other compiles.
    • In our real spec (17 schemas, all additionalProperties: false), only the one schema not referenced by any operation is affected. That schema has only scalar properties and a type: [array, "null"] list.
    • In a spec with one referenced and one unreferenced schema, both with a single string property, neither is affected; adding required: [x] to the unreferenced one makes it affected.

    That fits the explanation in #25470 that swagger-parser sometimes represents additionalProperties: false as a boolean false schema, so the fix there probably covers these cases as well. I have not tested the PR branch.

    Workaround on our side: removing additionalProperties: false from the affected schema (or removing the unused schema) makes it compile again.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions