Skip to content

fix: unwrap single non-object array items in allOf#23838

Open
RomiRand wants to merge 1 commit into
OpenAPITools:masterfrom
RomiRand:unwrap-single-allOf
Open

fix: unwrap single non-object array items in allOf#23838
RomiRand wants to merge 1 commit into
OpenAPITools:masterfrom
RomiRand:unwrap-single-allOf

Conversation

@RomiRand
Copy link
Copy Markdown

@RomiRand RomiRand commented May 20, 2026

Fixes #23837

This PR unwraps the entry of an allOf composed schema, if it is the only (non-object) item.


Summary by cubic

Unwraps a single non-object entry in an allOf so the inner schema replaces the wrapper, fixing array item resolution and preventing invalid inline models. Resolves #23837.

  • Bug Fixes
    • In InlineModelResolver, when allOf has one non-object schema, replace allOf with that schema (type and items).
    • Added test and YAML spec to verify arrays-within-arrays are unwrapped correctly and no allOf remains after flattening.

Written for commit 1a0451d. Summary will update on new commits. Review in cubic

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

2 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


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

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java:420">
P1: Potential IndexOutOfBoundsException: newAllOf.get(0) is unsafe when allOf contains a single null entry</violation>

<violation number="2" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java:423">
P1: Unwrapping single non-object `allOf` entry copies only `type` and `items`, discarding inner schema constraints and metadata like `format`, `enum`, `pattern`, `minLength`, numeric limits, `default`, and vendor extensions.</violation>
</file>

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

Re-trigger cubic

Schema inner = (Schema) newAllOf.get(0);
if (inner.getType() != null && !"object".equals(inner.getType())) {
// replace allOf with the unwrapped inner schema
schema.setType(inner.getType());
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.

P1: Unwrapping single non-object allOf entry copies only type and items, discarding inner schema constraints and metadata like format, enum, pattern, minLength, numeric limits, default, and vendor extensions.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java, line 423:

<comment>Unwrapping single non-object `allOf` entry copies only `type` and `items`, discarding inner schema constraints and metadata like `format`, `enum`, `pattern`, `minLength`, numeric limits, `default`, and vendor extensions.</comment>

<file context>
@@ -417,6 +417,13 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
+                        Schema inner = (Schema) newAllOf.get(0);
+                        if (inner.getType() != null && !"object".equals(inner.getType())) {
+                            // replace allOf with the unwrapped inner schema
+                            schema.setType(inner.getType());
+                            schema.setItems(inner.getItems());
+                            schema.setAllOf(null);
</file context>

} else {
// allOf is just one or more types only so do not generate the inline allOf model
if (schema.getAllOf().size() == 1) {
Schema inner = (Schema) newAllOf.get(0);
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.

P1: Potential IndexOutOfBoundsException: newAllOf.get(0) is unsafe when allOf contains a single null entry

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java, line 420:

<comment>Potential IndexOutOfBoundsException: newAllOf.get(0) is unsafe when allOf contains a single null entry</comment>

<file context>
@@ -417,6 +417,13 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
                 } else {
                     // allOf is just one or more types only so do not generate the inline allOf model
                     if (schema.getAllOf().size() == 1) {
+                        Schema inner = (Schema) newAllOf.get(0);
+                        if (inner.getType() != null && !"object".equals(inner.getType())) {
+                            // replace allOf with the unwrapped inner schema
</file context>

@jpfinne
Copy link
Copy Markdown
Contributor

jpfinne commented May 20, 2026

@RomiRand could you move the code to the OpenApiNormalizer?

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] array schemas with single non-object allOf entry aren't resolved

2 participants