fix(InlineModelResolver): do not merge untitled inline schemas differing only by description (#24004)#24007
Conversation
e7bf897 to
9589d82
Compare
|
Rebased onto latest master and regenerated the affected samples (sequentially, to avoid the parallel-generation nondeterminism in The remaining red checks are generated-sample builds (.NET/PHP/Python) plus the csharp generichost |
|
Correction to my earlier comment — after digging into the failing checks, my "remaining failures are unrelated / parallel-generation nondeterminism" note was wrong for most of them. Accurate breakdown:
Since the .NET breakage is a generator-side issue beyond the scope of this inline-resolver fix, I'd welcome maintainer guidance on the preferred direction here. |
…ing only by description The structural-signature dedup fallback added for multi-file OAS 3.1 specs (OpenAPITools#23856) strips description/type/example at every level and was applied to all schemas in matchGenerated()/addGenerated(). For untitled inline schemas that are structurally identical once those fields are stripped but intentionally distinct (e.g. two response properties differing only by description), this collapsed them into a single generated type, changing one property's type and breaking compiling user code (regression since 7.23). Restrict the structural-signature fallback to titled schemas only, mirroring the existing titled-only guards in flatten() pre-population and deduplicateComponents() ("anonymous schemas may be intentionally distinct"). Exact-signature matching is unaffected, so genuine duplicates are still reused. Fixes OpenAPITools#24004 Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
9589d82 to
bcffcfa
Compare
Align the FakeApiTests enumHeaderString/enumQueryString parameter types with the FakeApi signature (EnumHeaderStringParameter) so the samples match CI-generated output and compile. Signed-off-by: seonwooj0810 <seonwooj0810@gmail.com>
bcffcfa to
44ac7ae
Compare
|
Update + correction to my earlier comments — I was wrong about the .NET failures, and I've now pushed a fix that greens them.
One concrete clue for whoever digs deeper: within a single generation run, To be clear on attribution: this is PR-caused in the sense that the split is what exposes the order/environment-dependent naming (master has no split, so it compiles everywhere) — but it is not "parallel-generation nondeterminism," which I'd earlier hand-waved at.
|
Fixes #24004
Problem
A schema with two structurally-identical inline (untitled) object properties that differ only in their descriptions is generated differently in 7.22 vs 7.23. Given:
abc→…Abc,def→…Def.defwith type…Abc, so code expecting…Defno longer compiles.Root cause
The structural-signature dedup fallback introduced in #23856 (to prevent numbered duplicate models from multi-file OAS 3.1 specs) serialises schemas with
description/type/examplestripped at every level and was consulted/registered for all schemas inmatchGenerated()/addGenerated(). Once those volatile fields are stripped,abcanddefproduce an identical signature, sodefis unified withabc.That fallback is only appropriate for titled named types (which should be reused wherever they appear, despite parser-induced volatility). Anonymous/untitled inline schemas may be intentionally distinct — exactly as the existing titled-only guards in
flatten()pre-population anddeduplicateComponents()already note ("anonymous schemas may be intentionally distinct").Fix
Restrict the structural-signature fallback (both lookup in
matchGenerated()and registration inaddGenerated()) to schemas with a non-nulltitle. Exact-signature matching is unchanged, so genuine duplicates are still reused, and the #23856 multi-file dedup behaviour (which operates on titled schemas) is preserved.Test evidence
Added
InlineModelResolverTest#resolveInlineModelKeepsUntitledSchemasDifferingOnlyByDescriptionDistinct, which reproduces the issue and assertsabc/defresolve to distinct$refs. Verified it fails on master and passes with this change.Full
InlineModelResolverTestsuite (including the #23856 structural-dedup regression tests…MutatesPropertyDescriptions,…MutatesPropertyTypes, and the multi-fileroot.yamlcases) passes:Verification done: built/tested on JDK 21 via
./mvnw -pl modules/openapi-generator -am test -Dtest=InlineModelResolverTest.PR checklist
./bin/to update Petstore samples — N/A: this change does not alter generated output for any existing sample (no committed sample uses two untitled inline schemas differing only by description); fullInlineModelResolverTestpasses unchanged.master.Summary by cubic
Stops merging untitled inline schemas that differ only by description by limiting structural-signature dedup to titled schemas, restoring distinct generated types and fixing the 7.23 regression. Regenerates samples (C# FormModels,
crystal-qdrant, Python clients) to reflect corrected model/type emission.Bug Fixes
InlineModelResolver(matchGenerated(),addGenerated()); keep exact-signature dedup.$refs forabc/def; preserve multi-file OAS 3.1 reuse for titled schemas.Migration
FilterMust/FilterMustNot/PrefetchPrefetchandTrackerStatusOneOf1incrystal-qdrant;TestEnumParametersEnumHeaderStringParameterin C#;UploadFileWithAdditionalPropertiesRequestObjectin Python clients.Written for commit 44ac7ae. Summary will update on new commits.