fix(openapi): preserve component schema names through dereferencing#416
Merged
Merged
Conversation
Dereferencing inlines $ref targets and discards component names, so Modelina named nested models after property paths - every 'items' array item became 'ItemsItem', and models from different operations collided on the same file and silently overwrote each other (a transactions response ended up typed with the users item model). Tag each components.schemas / definitions entry with Modelina's x-modelgen-inferred-name hint right after dereferencing. Inlined occurrences share object identity with the component entry, so the name propagates to every usage site. Namespaced names shorten to their last dot-segment when unambiguous (GetTransactions.Model.TransactionModel -> TransactionModel), otherwise the full name is used. Standalone component models reuse the same name so both generation paths resolve to a single identical file. Also copy response schemas before decorating with x-modelina-status-codes: the schema object is shared post-dereference, so mutating it leaked status codes across operations. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
🎉 This PR is included in version 0.75.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Re-plants the changes from #414 directly onto
main.#414 targets the
add_parameter_interfacefeature branch, which may not land. This PR contains only #414's own contribution (the three-dot deltaadd_parameter_interface...fix/openapi-preserve-component-schema-names) applied on top of the latestmain, so it can merge independently.What's included
The complete OpenAI component-schema-name fix from #414:
src/codegen/inputs/openapi/utils.ts— tagcomponents.schemas/definitionsentries with Modelina'sx-modelgen-inferred-nameafter dereferencing so component names survive$refinlining; namespaced names shorten to their last dot-segment when unambiguous.src/codegen/inputs/openapi/parser.ts— wire the tagging into the parse pipeline.src/codegen/inputs/openapi/generators/payloads.ts— copy response schemas before decorating withx-modelina-status-codesso status codes no longer leak across operations.test/codegen/inputs/openapi/utils.spec.ts,test/codegen/generators/typescript/payload.spec.ts, and fixturetest/configs/openapi-shared-items.json.What's excluded
Everything contributed by the
add_parameter_interfacebase branch (parameter-interface work). None of it is required for this fix — the delta applied tomainwith no conflicts.Verification
tsc --noEmit— cleaneslinton changed sources — cleanjestacrosstest/codegen/inputs/openapiandtest/codegen/generators/typescript— 174 tests / 78 snapshots pass, no snapshot regeneration needed🤖 Generated with Claude Code