Skip to content

Prepend #/components/schemas/ to typebox references while building schema#337

Open
StratusFearMe21 wants to merge 2 commits into
elysiajs:mainfrom
StratusFearMe21:fix-typebox-references
Open

Prepend #/components/schemas/ to typebox references while building schema#337
StratusFearMe21 wants to merge 2 commits into
elysiajs:mainfrom
StratusFearMe21:fix-typebox-references

Conversation

@StratusFearMe21

@StratusFearMe21 StratusFearMe21 commented May 9, 2026

Copy link
Copy Markdown

This PR fixes the bug described in #310 by crawling the TypeBox schema during the enumToOpenApi step, finding instances of references, and calling toRef on them. Absolutely love what you guys are doing, keep up the great work!

Summary by CodeRabbit

  • Refactor
    • Improved OpenAPI schema generation to better handle enum-like union schemas and schema references, returning normalized references where appropriate.
    • Expanded recursive conversion to traverse all schema properties for more consistent translation, improving compatibility and reducing edge-case mismatches in generated API schemas.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 137d3ead-3d05-42b7-a635-75dff197e57b

📥 Commits

Reviewing files that changed from the base of the PR and between 13f613c and 18b395b.

📒 Files selected for processing (1)
  • src/openapi.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openapi.ts

Walkthrough

enumToOpenApi gains JSDoc for enum-like unions, adds explicit TypeBox Ref detection and conversion to OpenAPI $ref via toRef(...), and changes recursion to generically walk and mutate every key/value in schema objects.

Changes

TypeBox Ref & Recursive Enum Normalization

Layer / File(s) Summary
Documentation & Contract
src/openapi.ts
JSDoc expanded to describe enum-like union handling and TypeBox t.Ref normalization (prefixing #/components/schemas/ when needed).
Ref Node Detection & Conversion
src/openapi.ts
Adds branch: when Kind === 'Ref' and $ref exists, return toRef(schema.$ref) to produce an OpenAPI-compatible $ref.
Generic Recursive Schema Walk
src/openapi.ts
Replaces prior object/array-specific recursion with iteration over all schema object keys, applying enumToOpenApi to each value and returning the mutated schema.

Possibly related PRs

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

Heh~ refs get prettified, aren’t you proud, baka~ (¬‿¬)♡
Enums tucked into OpenAPI like obedient little pets~ (^▽^)♡
A smug little walk through every key — so thorough, so rude~ (・ω<)♡
Schema pampering complete — go cry if you must~ (ノ≧ڡ≦)♡

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: prepending #/components/schemas/ to TypeBox references during schema building, which directly addresses the PR's core objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openapi.ts`:
- Around line 651-652: The current check only converts top-level Ref nodes
(schema[Kind] === 'Ref' && schema.$ref) via toRef, but does not traverse
composition schemas (TypeBox Union/Intersect/Discriminator or schemas with
anyOf/allOf/oneOf/not) so nested $ref values remain unnormalized; update the
normalization path that contains schema[Kind] and the toRef call to recursively
walk composition properties (anyOf/allOf/oneOf/not and discriminator mappings)
and replace any nested schema objects with toRef(schema.$ref) where schema[Kind]
=== 'Ref', and ensure Union/Intersect/Discriminator handling code invokes this
traversal so all internal refs are normalized consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 84eb15cd-b270-4939-8c1d-04aaeca7ba63

📥 Commits

Reviewing files that changed from the base of the PR and between dabaa94 and 1a27c0a.

📒 Files selected for processing (1)
  • src/openapi.ts

Comment thread src/openapi.ts
@StratusFearMe21

Copy link
Copy Markdown
Author

Thanks for catching that CodeRabbit. My solution was to just iterate through the entire object generically. The function itself stops iteration of the schema is not of type 'object', and only makes modifications to the schema if Kind is in _schema. Let me know if there's a better type I can put on the const schema declaration on line 655

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openapi.ts`:
- Around line 655-659: The code mutates the input _schema by assigning into
schema when iterating; instead create a cloned structure (e.g., deep
clone/structuredClone or a shallow copy of top-level entries and recursively map
nested objects) and run enumToOpenApi on the clone so the original _schema is
not modified; locate the block using _schema, schema and enumToOpenApi and
replace the in-place assignment with transformation into and return of a new
cloned object.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c5bc3daf-f770-4543-94b5-cf4af7b8ffe2

📥 Commits

Reviewing files that changed from the base of the PR and between 1a27c0a and 13f613c.

📒 Files selected for processing (1)
  • src/openapi.ts

Comment thread src/openapi.ts Outdated
@StratusFearMe21
StratusFearMe21 force-pushed the fix-typebox-references branch from 26c4ea9 to 18b395b Compare May 9, 2026 16:51
@StratusFearMe21

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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