Skip to content

[core] Treat an OAS 3.1 boolean schema false as closed additionalProperties (#25430) - #25470

Open
cpruijsen wants to merge 1 commit into
OpenAPITools:masterfrom
cpruijsen:fix/jaxrs-spec-closed-inline-additional-props
Open

cpruijsen wants to merge 1 commit into
OpenAPITools:masterfrom
cpruijsen:fix/jaxrs-spec-closed-inline-additional-props

Conversation

@cpruijsen

@cpruijsen cpruijsen commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25430

With OAS 3.1, swagger-parser can represent additionalProperties: false as a Schema with booleanSchemaValue false. The issue spec triggers this representation when a property defines an inline map.

ModelUtils.isMapSchema treats this value as closed. DefaultCodegen.setAddProps previously treated it as a typed schema. The model therefore had additional-properties accessors but no HashMap parent. The generated jaxrs-spec model did not compile.

Treat a false boolean schema like Boolean.FALSE in setAddProps and addRequiredVarsMap. This matches the existing ModelUtils checks. A closed schema no longer exposes additional-properties members.

The shared codegen fix was chosen over a {{#parent}} guard in the jaxrs-spec template. The template guard would only hide the inconsistent model state for one generator.

Regenerating the affected samples changed only PropertiesWithAnyOf.cs. Its additionalProperties: false schema no longer produces an AdditionalProperties dictionary.

Testing

  • The new regression test fails on origin/master with java.lang.AssertionError: expected [false] but found [true]. It passes with the fix.
  • DefaultCodegenTest, JavaJAXRSSpecServerCodegenTest, OpenAPINormalizerTest, ModelUtilsTest, DefaultGeneratorTest, InlineModelResolverTest, and org.openapitools.codegen.java.**: 1822 tests, 0 failures, 0 errors.
  • The baseline issue project fails to compile with 3 errors in PatchRequest.java. The fixed issue project compiles successfully.
  • Regenerated all three sample configs whose OAS 3.1 inputs contain additionalProperties: false: csharp-generichost-latest-annotatedEnum, jetbrains-http-client-adyen-checkout-new, and rust-reqwest-regression-16119. No generated changes were missing from the commit.
  • The regenerated C# project builds with 0 warnings and 0 errors.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes OAS 3.1 additionalProperties: false handling so closed schemas no longer generate uncompilable jaxrs-spec models. Swagger-parser represents additionalProperties: false as a boolean schema instead of Boolean.FALSE, and DefaultCodegen.setAddProps previously treated it as a typed schema, producing additional-properties accessors without a HashMap parent. The fix treats a false boolean schema like Boolean.FALSE in setAddProps and addRequiredVarsMap, matching the existing ModelUtils checks. The shared codegen fix was chosen over a {{#parent}} template guard, which would only hide the inconsistent model state for one generator. Regenerated samples change only PropertiesWithAnyOf.cs, which no longer emits an AdditionalProperties dictionary. A regression test covers the inline-map case; it fails on master without the fix.

Written for commit b7fdf73. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/test/resources/3_1/issue_25430.yaml">

<violation number="1" location="modules/openapi-generator/src/test/resources/3_1/issue_25430.yaml:25">
P3: This fixture only covers the `setAddProps` change. Add a `required` entry for a property not declared in `properties` (for example `required: [missing]`) to `PatchRequest`, and assert the generated model in the test. That exercises the `addRequiredVarsMap` change, which the test does not currently cover.</violation>
</file>

<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java">

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java:3668">
P3: This helper repeats the false-boolean `additionalProperties` check that `ModelUtils.isMapSchema` and `ModelUtils.isModelWithPropertiesOnly` already inline. Move it to `ModelUtils` as a public static method and call it from both places, so the OAS 3.1 closed-schema rule lives in one place.</violation>

<violation number="2" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java:3670">
P2: The checked-in OpenAPI input uses `additionalProperties: {}` for `PropertiesWithAnyOf`, but this regeneration removes its `AdditionalProperties` dictionary. Preserve open empty schemas; only suppress the member for an actual boolean-false schema.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

// OAS 3.1 can parse `additionalProperties: false` as a boolean schema instead of Boolean.FALSE
private static boolean isBooleanSchemaFalse(Object additionalProperties) {
return additionalProperties instanceof Schema
&& Boolean.FALSE.equals(((Schema) additionalProperties).getBooleanSchemaValue());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The checked-in OpenAPI input uses additionalProperties: {} for PropertiesWithAnyOf, but this regeneration removes its AdditionalProperties dictionary. Preserve open empty schemas; only suppress the member for an actual boolean-false schema.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java, line 3670:

<comment>The checked-in OpenAPI input uses `additionalProperties: {}` for `PropertiesWithAnyOf`, but this regeneration removes its `AdditionalProperties` dictionary. Preserve open empty schemas; only suppress the member for an actual boolean-false schema.</comment>

<file context>
@@ -3664,6 +3664,12 @@ protected void setAddProps(Schema schema, IJsonSchemaValidationProperties proper
+    // OAS 3.1 can parse `additionalProperties: false` as a boolean schema instead of Boolean.FALSE
+    private static boolean isBooleanSchemaFalse(Object additionalProperties) {
+        return additionalProperties instanceof Schema
+                && Boolean.FALSE.equals(((Schema) additionalProperties).getBooleanSchemaValue());
+    }
+
</file context>

context:
type: object
additionalProperties: true
additionalProperties: false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This fixture only covers the setAddProps change. Add a required entry for a property not declared in properties (for example required: [missing]) to PatchRequest, and assert the generated model in the test. That exercises the addRequiredVarsMap change, which the test does not currently cover.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/test/resources/3_1/issue_25430.yaml, line 25:

<comment>This fixture only covers the `setAddProps` change. Add a `required` entry for a property not declared in `properties` (for example `required: [missing]`) to `PatchRequest`, and assert the generated model in the test. That exercises the `addRequiredVarsMap` change, which the test does not currently cover.</comment>

<file context>
@@ -0,0 +1,25 @@
+        context:
+          type: object
+          additionalProperties: true
+      additionalProperties: false
</file context>

}

// OAS 3.1 can parse `additionalProperties: false` as a boolean schema instead of Boolean.FALSE
private static boolean isBooleanSchemaFalse(Object additionalProperties) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This helper repeats the false-boolean additionalProperties check that ModelUtils.isMapSchema and ModelUtils.isModelWithPropertiesOnly already inline. Move it to ModelUtils as a public static method and call it from both places, so the OAS 3.1 closed-schema rule lives in one place.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java, line 3668:

<comment>This helper repeats the false-boolean `additionalProperties` check that `ModelUtils.isMapSchema` and `ModelUtils.isModelWithPropertiesOnly` already inline. Move it to `ModelUtils` as a public static method and call it from both places, so the OAS 3.1 closed-schema rule lives in one place.</comment>

<file context>
@@ -3664,6 +3664,12 @@ protected void setAddProps(Schema schema, IJsonSchemaValidationProperties proper
     }
 
+    // OAS 3.1 can parse `additionalProperties: false` as a boolean schema instead of Boolean.FALSE
+    private static boolean isBooleanSchemaFalse(Object additionalProperties) {
+        return additionalProperties instanceof Schema
+                && Boolean.FALSE.equals(((Schema) additionalProperties).getBooleanSchemaValue());
</file context>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant