fix(openapi): preserve component schema names through dereferencing#414
Closed
ALagoni97 wants to merge 1 commit into
Closed
fix(openapi): preserve component schema names through dereferencing#414ALagoni97 wants to merge 1 commit into
ALagoni97 wants to merge 1 commit into
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
Author
|
Will be reopenend towards main |
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.
Problem
Generating a client from an OpenAPI spec with namespaced component schemas (e.g. Safepay's
GetTransactions.Model.TransactionModel) produced corrupt payload models:$refcomponent names. Modelina then falls back to naming nested anonymous models after the property path, so everyitemsarray item across the whole spec was namedItemsItem.ItemsItem.tswritten (the users item model) silently replaced all others.GetV2TransactionsResponse_200.itemswas typed asItemsItem[]containingsafepayAccountId/name/phoneNumberinstead oftransactionId/amount/currency.Fix
components.schemas/definitionsentry with Modelina'sx-modelgen-inferred-namehint (lowest naming precedence — never overrides an author-providedtitle/$id, and no$idbase-URI side effects). Dereferencing inlines refs by object reference, so the tag on the component entry propagates to every usage site.GetTransactions.Model.TransactionModel→TransactionModel); ambiguous ones (GetUsers.Model/GetTransactions.Modelboth ending in.Model) keep the full name.otherPayloads) reuse the same chosen name, so the nested split model and the standalone component model resolve to one identical file instead of two divergent classes.x-modelina-status-codes; previously the shared post-dereference schema object was mutated, leaking status codes between operations reusing the same component.Result (safepay-v2)
No
ItemsItemanywhere; the full 203-file generated client type-checks cleanly.Testing
test/configs/openapi-shared-items.jsonreproducing the collision; end-to-end test asserts distinctTransactionModel/UserModelfiles with correct properties and noItemsItem.test/codegensuite: 372 passing, no snapshot changes.npm run lintclean.🤖 Generated with Claude Code