[BUG] fix(InlineModelResolver): do not merge distinct inline enums sharing the same values (#23978)#24009
Conversation
5663d49 to
e87bb24
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 — on closer inspection this is the same situation as #24007, so my "unrelated / nondeterminism" note doesn't hold. Breakdown:
As with #24007, the .NET breakage is generator-side and beyond the scope of this inline-resolver fix, so I'd appreciate maintainer guidance on the preferred direction. |
…the same values The structural-signature fallback added in OpenAPITools#23856 strips 'description', 'type' and 'example' before comparing schemas so that multi-file $ref object schemas mutated by the parser still deduplicate. For enum schemas this is too aggressive: two enums that list the same values but mean different things are distinguished only by their description, so stripping it wrongly unifies them and the second usage silently reuses the first enum's type (regression in 7.23.0, worked in 7.22.0). Skip the structural fallback for enum schemas in matchGenerated() so enums deduplicate on exact content only. Object-schema multi-file dedup is unaffected. Fixes OpenAPITools#23978
e87bb24 to
841c1ca
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>
841c1ca to
86f45b3
Compare
|
Update + correction to my earlier comment — I was wrong about the .NET failures, and I've now pushed a fix that greens them.
Clue for whoever digs deeper: within a single generation run, Attribution: this is PR-caused in that the split exposes the order/environment-dependent naming (master has no split, so it compiles everywhere) — but not "parallel-generation nondeterminism."
|
Fixes #23978
Problem
Since 7.23.0, inline enums that share the same values but are defined on different properties are no longer generated as separate types — only the first enum gets its own schema and the second property silently reuses it. This worked correctly in 7.22.0. The reporter bisected the change to #23856 (commit
170778a), and a second user confirmed the same behaviour onkotlin-spring.Root cause
#23856 added a structural-signature fallback to
matchGenerated(). To dedup the same multi-file$refobject schema across passes (where the Swagger Parser mutates sharedSchemaobjects), the structural mapper stripsdescription,typeandexamplebefore comparing.For object schemas that is fine, but for enum schemas it is too aggressive: two enums that list the same values but represent different things are distinguished only by their
description. Stripping it makes their structural signatures identical, so the second enum matches the first and reuses its$ref.Fix
Skip the structural-signature fallback for enum schemas in
matchGenerated()— enums deduplicate on exact content only (the 7.22.0 behaviour). Object-schema multi-file deduplication is unchanged.The diff is small and localized to
matchGenerated()plus a newisEnumSchema()helper.Test evidence
Added
InlineModelResolverTest#doNotMergeDistinctInlineEnumsSharingTheSameValues, which builds an object with two inline enum properties that share the same values but carry different descriptions and asserts each is promoted to its own schema. The test fails on master (the two$refs are equal) and passes with this fix.Full
InlineModelResolverTestrun: 56 tests, 0 failures — including the existing structural/multi-file dedup regression tests added by #23856 (resolveInlineModelDeduplicatesWhenParserMutatesPropertyTypes, theroot.yamldedup tests), confirming the multi-file object dedup behaviour is preserved.Verification done: (1) no in-flight PR (searched open PRs for
23978/InlineModelResolver enum); (2) issue unassigned, no claim comments; (3) code-focused (.javaonly); (4) reproduced on latestupstream/masterwith a failing unit test; (5) maintainer (@wing328) acknowledged the regression and cc'd the author of the change.Summary by cubic
Fixes a regression that merged distinct inline enums with the same values; each inline enum now generates its own schema. Regenerates samples so header/query string enums use the new
testEnumParameters_enum_header_string_parametertype.InlineModelResolver.matchGenerated(), skip structural-signature fallback for enum schemas; object-schema multi-file dedup stays the same.isEnumSchema()helper and unit testdoNotMergeDistinctInlineEnumsSharingTheSameValues.TestEnumParametersEnumHeaderStringParameter, update refs/converters, and align API signatures and tests (incl.FakeApiTests) to the new enum type.Written for commit 86f45b3. Summary will update on new commits.