Skip to content

Reconcile matching schemas in root document to avoid anonymous structs #1573

Closed
percivalalb wants to merge 2 commits intooapi-codegen:mainfrom
percivalalb:alb/reconsole-schema-refs
Closed

Reconcile matching schemas in root document to avoid anonymous structs #1573
percivalalb wants to merge 2 commits intooapi-codegen:mainfrom
percivalalb:alb/reconsole-schema-refs

Conversation

@percivalalb
Copy link
Copy Markdown

@percivalalb percivalalb commented Apr 22, 2024

For #1362

OpenAPI specifications can be spread across different files for maintainability. However this is not great for code-gen which can't recognise when two schema refs refer to the same model. This results in the code-gen using duplicating anonymous structs (which can't easily be used).

I have added a patch to kin upstream (getkin/kin-openapi#945) which identifies when a ref refers to a schema from the root #/components/schemas and makes use of the go model generated from that.

See f71a97a which shows the change codegen changes:

image

Note: Also adds test spec to test for regression against #1572

@percivalalb
Copy link
Copy Markdown
Author

The changes needed to the kin-openapi library are present in v0.126.0, I'll wait for #1689 to be merged before completing this PR

@percivalalb percivalalb force-pushed the alb/reconsole-schema-refs branch from f662fa7 to f71a97a Compare July 9, 2024 10:03
@percivalalb percivalalb requested a review from a team as a code owner July 9, 2024 10:03
@percivalalb percivalalb changed the title Reconcile references to remote schemas to models from the root spec Reconcile matching schemas in root document to avoid anonymous structs Jul 9, 2024
@percivalalb percivalalb force-pushed the alb/reconsole-schema-refs branch from f71a97a to ffd7e20 Compare July 9, 2024 10:11
@percivalalb
Copy link
Copy Markdown
Author

This is now ready for review

@jamietanna jamietanna added bug Something isn't working area:external-refs Anything related to external references (referencing other file(s) within a spec) area:*of `oneOf`/`anyOf`/`allOf` labels Sep 29, 2024
@jamietanna jamietanna added this to the v2.5.0 milestone Sep 29, 2024
@percivalalb percivalalb force-pushed the alb/reconsole-schema-refs branch from cd5c969 to 3d69a64 Compare April 26, 2025 11:38
@jamietanna jamietanna modified the milestones: v2.5.0, v2.6.0 May 11, 2025
@mromaszewicz
Copy link
Copy Markdown
Member

Thank you for contributing, and I'm very sorry for taking so long to get to this PR. At this point, the code has changed so much that it's no longer relevant because this was blocked on an upstream kin-openapi dependency merge that was never completed, and the codebase has moved on.

@percivalalb
Copy link
Copy Markdown
Author

percivalalb commented Feb 24, 2026

Hi, the changes to the upstream dependancy were completed and merged in. Oapi-codegen is now using the required version of kin-openapi. I imagine this PR needs rebasing since it's been so long but it should still work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:external-refs Anything related to external references (referencing other file(s) within a spec) area:*of `oneOf`/`anyOf`/`allOf` awaiting reply bug Something isn't working upstream

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants