fix: unwrap single non-object array items in allOf#23838
Open
RomiRand wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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()); |
Contributor
There was a problem hiding this comment.
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); |
Contributor
There was a problem hiding this comment.
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>
Contributor
|
@RomiRand could you move the code to the OpenApiNormalizer? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #23837
This PR unwraps the entry of an
allOfcomposed 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.
InlineModelResolver, whenallOfhas one non-object schema, replaceallOfwith that schema (type and items).allOfremains after flattening.Written for commit 1a0451d. Summary will update on new commits. Review in cubic