Skip to content

fix(openapi): preserve component schema names through dereferencing#414

Closed
ALagoni97 wants to merge 1 commit into
add_parameter_interfacefrom
fix/openapi-preserve-component-schema-names
Closed

fix(openapi): preserve component schema names through dereferencing#414
ALagoni97 wants to merge 1 commit into
add_parameter_interfacefrom
fix/openapi-preserve-component-schema-names

Conversation

@ALagoni97

Copy link
Copy Markdown
Contributor

Problem

Generating a client from an OpenAPI spec with namespaced component schemas (e.g. Safepay's GetTransactions.Model.TransactionModel) produced corrupt payload models:

  • The parser fully dereferences the document, discarding all $ref component names. Modelina then falls back to naming nested anonymous models after the property path, so every items array item across the whole spec was named ItemsItem.
  • Each operation's payload is generated in a separate pass into the same output folder, and file dedup is first-path-wins — so the first ItemsItem.ts written (the users item model) silently replaced all others. GetV2TransactionsResponse_200.items was typed as ItemsItem[] containing safepayAccountId/name/phoneNumber instead of transactionId/amount/currency.

Fix

  • After dereferencing, tag each components.schemas / definitions entry with Modelina's x-modelgen-inferred-name hint (lowest naming precedence — never overrides an author-provided title/$id, and no $id base-URI side effects). Dereferencing inlines refs by object reference, so the tag on the component entry propagates to every usage site.
  • Namespaced names shorten to their last dot-segment when unambiguous across the spec (GetTransactions.Model.TransactionModelTransactionModel); ambiguous ones (GetUsers.Model / GetTransactions.Model both ending in .Model) keep the full name.
  • Standalone component models (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.
  • Response schemas are now copied before being decorated with 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)

// GetV2TransactionsResponse_200.ts
private _items?: TransactionModel[];

// TransactionModel.ts
private _transactionId: string;
private _amount: string | number;
private _currency: Currencies;

No ItemsItem anywhere; the full 203-file generated client type-checks cleanly.

Testing

  • New regression fixture test/configs/openapi-shared-items.json reproducing the collision; end-to-end test asserts distinct TransactionModel/UserModel files with correct properties and no ItemsItem.
  • Unit tests for the shortening/ambiguity rules and tag precedence.
  • Full test/codegen suite: 372 passing, no snapshot changes. npm run lint clean.

🤖 Generated with Claude Code

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>
@ALagoni97
ALagoni97 requested a review from jonaslagoni as a code owner July 15, 2026 07:41
@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
the-codegen-project Ready Ready Preview, Comment Jul 15, 2026 7:41am
the-codegen-project-mcp Ready Ready Preview, Comment Jul 15, 2026 7:41am

@ALagoni97

Copy link
Copy Markdown
Contributor Author

Will be reopenend towards main

@ALagoni97 ALagoni97 closed this Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant