Repository navigation
fix: ignore kin-openapi source locations when comparing type definitions - #2601
Merged
mromaszewicz merged 4 commits intoOct 31, 2026
Conversation
Since oapi-codegen#2465 the loader sets IncludeOrigin, so every schema records the line it was declared on. TypeDefinitionsEquivalent compared schemas with reflect.DeepEqual, so two identical schemas with the same x-go-type-name on different lines no longer matched, and generation failed with "duplicate typename". Compare the schemas like reflect.DeepEqual does, but treat any two *openapi3.Origin values as equal. Comparing the JSON encodings instead would drop resolved $ref targets and OpenAPI 3.1 $ref siblings, so different schemas could be merged silently. Fixes oapi-codegen#2599 Co-Authored-By: Claude Opus 5.5 <[email protected]>
eyoshioka
marked this pull request as ready for review
October 8, 2026 10:40
Contributor
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryUpdates
Reviews (3) · Last reviewed commit: "Revert "fix: blank origins and reuse ref..." · Reviewed by Greptile |
…valent Instead of carrying a copy of reflect's deepValueEqual that skips *openapi3.Origin, walk both schemas once, nil every reachable Origin field, run the real reflect.DeepEqual, and restore the origins afterwards. Origins are still read later (for example to order paths by source line), so a test checks that they come back. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…gin-in-type-equivalence
Member
|
Thanks for doing this. I'm going to push a change to it. Rather than reimplementing so much of DeepEquals, we're going to back up and zero out the Origin on the schemas, then restore before exiting, so that we can reuse the existing DeepEquals representation. It's not as clean, but it's a lot simpler and works for us. |
Member
|
NVM, what I did is worse. Apologies. I'll put it back as it was, and I merged main into your branch so this applies cleanly. |
…ionsEquivalent" This reverts commit a4d1d606c1cc5bd5e1dbe42f2a2d7af1fa3c9bd4. Clearing the origins before calling reflect.DeepEqual was a mistake. Origins sit on every nested Schema, SchemaRef and Discriminator, so the "clear and restore" walker ends up being its own recursive traversal with cycle detection, while also mutating shared schema objects during the comparison. The original read-only comparer that skips *openapi3.Origin is the simpler and safer approach, so this restores it as submitted. Co-Authored-By: Claude Fable 5.1 <[email protected]>
mromaszewicz
approved these changes
Oct 31, 2026
mromaszewicz
enabled auto-merge (squash)
October 31, 2026 21:48
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 #2599.
Since #2465, the loader sets
IncludeOrigin, so every schema records where it was declared.TypeDefinitionsEquivalentusedreflect.DeepEqual, so identical schemas declared on different lines no longer matched.This implements option 2 from my comment on the issue. It compares the schemas the same way as
reflect.DeepEqual, but treats any two*openapi3.Originvalues as equal. The code follows the standard library'sdeepValueEqual, including cycle detection for recursive schemas, and its doc comment lists where the two differ. Fields are skipped by type, so this also coversOriginonSchemaRef,Discriminatorand other kin-openapi types, and on any fields added later. It adds no new dependency. If you'd rather use go-cmp, I'm happy to switch, and the tests stay the same.Tests:
TestTypeDefinitionsEquivalentIgnoresOrigincovers inline, nested and recursive schemas, which should be equal. It also covers two cases that must stay different: the same relative$refresolving to different files, and a 3.1$refwith a sibling keyword. Comparing JSON would fail both of these.TestTypeDefinitionsEquivalentCyclescompares two separately built self-referencing schemas. A loaded spec shares one*Schemaper$reftarget, so the loaded cases never reach the cycle detection. Without the detection, this test overflows the stack.TestIdenticalXGoTypeNameSchemasWithOriginruns the issue's spec throughGenerate.make generateproduces no diff with Go 1.27.1, which matches CI'sstable. With Go 1.25 or 1.26, only the embedded spec blobs change, with or without this change.make testandmake lintpass.I used Claude to help write this change. I've reviewed and tested it myself.