Repository navigation
Conversation
…ti-type schemas Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
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. 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/java/org/openapitools/codegen/OpenAPINormalizerTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java:787">
P2: This regression test does not cover object `properties` or `required` fields, despite the fix moving those fields into the object `anyOf` branch. Add such fields to the fixture and assert they survive normalization; otherwise the test can pass while the claimed object conversion is broken.</violation>
</file>
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java:2352">
P1: Object-first unions that declare properties are still not normalized by this change. Because `normalizeSchema` handles non-empty properties before `processNormalize31Spec`, `type: [object, array]` remains a JsonSchema instead of becoming an `anyOf`, so Java generation can still treat it as an object-only model and lose the array alternative; normalize explicit multi-type schemas before the properties-only path (while preserving the existing implied-object behavior).</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| schema.addAnyOfItem(build31ArraySchema(schema, visitedSchemas)); | ||
| schema.setItems(null); | ||
| break; | ||
| case "object": |
There was a problem hiding this comment.
P1: Object-first unions that declare properties are still not normalized by this change. Because normalizeSchema handles non-empty properties before processNormalize31Spec, type: [object, array] remains a JsonSchema instead of becoming an anyOf, so Java generation can still treat it as an object-only model and lose the array alternative; normalize explicit multi-type schemas before the properties-only path (while preserving the existing implied-object behavior).
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/OpenAPINormalizer.java, line 2352:
<comment>Object-first unions that declare properties are still not normalized by this change. Because `normalizeSchema` handles non-empty properties before `processNormalize31Spec`, `type: [object, array]` remains a JsonSchema instead of becoming an `anyOf`, so Java generation can still treat it as an object-only model and lose the array alternative; normalize explicit multi-type schemas before the properties-only path (while preserving the existing implied-object behavior).</comment>
<file context>
@@ -2378,16 +2345,129 @@ protected Schema processNormalize31Spec(Schema schema, Set<Schema> visitedSchema
+ schema.addAnyOfItem(build31ArraySchema(schema, visitedSchemas));
+ schema.setItems(null);
+ break;
+ case "object":
+ schema.addAnyOfItem(build31ObjectSchema(schema, visitedSchemas));
+ schema.setProperties(null);
</file context>
| objOrArrayArray = (ArraySchema) subSchema; | ||
| } | ||
| } | ||
| assertNotNull(objOrArrayObject); |
There was a problem hiding this comment.
P2: This regression test does not cover object properties or required fields, despite the fix moving those fields into the object anyOf branch. Add such fields to the fixture and assert they survive normalization; otherwise the test can pass while the claimed object conversion is broken.
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/java/org/openapitools/codegen/OpenAPINormalizerTest.java, line 787:
<comment>This regression test does not cover object `properties` or `required` fields, despite the fix moving those fields into the object `anyOf` branch. Add such fields to the fixture and assert they survive normalization; otherwise the test can pass while the claimed object conversion is broken.</comment>
<file context>
@@ -744,6 +744,74 @@ public void testNormalize31Parameters() {
+ objOrArrayArray = (ArraySchema) subSchema;
+ }
+ }
+ assertNotNull(objOrArrayObject);
+ assertNotNull(objOrArrayArray);
+ assertEquals(objOrArrayArray.getDescription(), "Related case from the issue.");
</file context>
Fixes #25756
For
type: [array, string](2+ non-null types) the OAS 3.1 normalizer handled only scalar types;array/objecthit the "not yet supported" fallback and left the schema half-converted (typeskept alongside a partial anyOf). Downstream,getType()returned the first remaining type,InlineModelResolvertook the array branch without extracting the property, andgetSchemaType()composed a phantomanyOf<string>name — java emittedAnyOfString<String>with an import of a never-generated class (compile failure).OpenAPINormalizer.processNormalize31Specnow convertsarray(items + array constraints moved in) andobject(properties/additionalProperties/required moved in) multi-type schemas via newbuild31ArraySchema/build31ObjectSchemahelpers;typesis cleared after full conversion so a real wrapper model is extracted, and unknown types keep the old error path.Reproduced the issue output first; after the fix okhttp-gson/native/spring-http-interface generate proper
CompanyTradingNames/CompanyObjOrArraywrapper models with runtime adapters, and the generated clients compile. New normalizer test + fixture; OpenAPINormalizerTest 73/73, DefaultCodegenTest 185/185, CompositionNormalizationTest 13/13 green; okhttp-gson-3.1 sample regen shows only pre-existing stale-sample drift.Summary by cubic
Fixes #25756. The OAS 3.1 multi-type normalizer now converts
arrayandobjecttypes instead of leaving the schema half-converted, which previously caused Java generators to emit a phantomAnyOfString<String>model, import a never-generated class, and fail compilation.build31ArraySchema/build31ObjectSchemahelpers that moveitems,properties,additionalProperties, and related constraints into the convertedanyOfbranches.typesafter a full conversion so a real wrapper model is extracted; unknown types keep the old error path.Written for commit 8209b40. Summary will update on new commits.