Skip to content

Conversation

@lsmith77
Copy link
Contributor

@lsmith77 lsmith77 commented Aug 8, 2025

adds docs for zenstackhq/zenstack#2188

Summary by CodeRabbit

  • Documentation
    • Expanded documentation for the RESTful API handler to describe the new optional externalIdMapping configuration.
    • Added an example showing how to expose models by unique fields instead of IDs in API URLs.
    • Clarified support for compound unique constraints and current limitations regarding custom index names.

@vercel
Copy link

vercel bot commented Aug 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zenstack-new-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 9:35am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

Walkthrough

The documentation for the RESTful API handler was updated to describe a new optional configuration option, externalIdMapping. This addition explains how to map model names to unique constraint names for exposing natural keys in API URLs, and provides an example usage and clarifications regarding its limitations.

Changes

Cohort / File(s) Change Summary
RESTful API Handler Documentation
docs/reference/server-adapters/api-handlers/rest.mdx
Extended documentation to describe the externalIdMapping option, its usage, example, and current limitations.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
docs/reference/server-adapters/api-handlers/rest.mdx (4)

104-104: Fix grammar/wording and clarify intent

Tighten the wording, fix typos, and clarify what the mapping targets.

-  Optional. An `Record<string, string>` value that provides a mapping from model names (as defined in ZModel) to unique contraint name. This is useful when you for example want to expose natural keys in place of a surrogate keys:
+  Optional. A `Record<string, string>` that maps model names (as defined in ZModel) to a unique constraint (field or composite) used as the external identifier in URLs. Useful when you want to expose natural keys instead of surrogate keys:

106-113: Polish the example comment (typos, phrasing, and URL placeholder)

Minor corrections for clarity and accuracy.

-  // Expose tags by unique name and not by ID, ie. /tag/blue intead of /tag/id
+  // Expose Tag resources by unique name rather than by ID (i.e., /tag/blue instead of /tag/:id)
   RestApiHandler({
       externalIdMapping: {
           Tag: 'name'
       }
   })

115-115: Correct typos and clarify compound unique behavior

Fix spelling; make the limitation precise; tie behavior to Compound ID documentation.

-  Currentlly it is not possible to use custom index names. This also works for compound unique contraints just like for [compound IDs](#compound-id-fields).
+  Currently, custom unique index/constraint names are not supported. Compound unique constraints are supported; the URL uses the same underscore-joined format described in [Compound ID Fields](#compound-id-fields) and inherits the same limitations.

102-115: Clarify how to reference a compound unique constraint in externalIdMapping

The value type is Record<string, string>, but for compound uniques it’s not obvious what string is expected (field list? implicit constraint identifier?). Please add a concrete example for a compound unique and specify the expected syntax.

For example, if the schema defines:

model Article {
  id       Int     @id @default(autoincrement())
  slug     String
  locale   String
  @@unique([slug, locale])
}
  • If the mapping expects a comma-separated field list, consider documenting this explicitly and add an example like:
RestApiHandler({
  externalIdMapping: {
    Article: 'slug,locale'
  }
})
// e.g., GET /article/hello-world_en
  • If it expects a different identifier (e.g., an implicit name), please document the exact format and show how the URL is formed, including the underscore-join and its limitations.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9f0855 and 47357f6.

📒 Files selected for processing (1)
  • docs/reference/server-adapters/api-handlers/rest.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/reference/server-adapters/api-handlers/rest.mdx

[grammar] ~104-~104: Ensure spelling is correct
Context: ... names (as defined in ZModel) to unique contraint name. This is useful when you for example wan...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~115-~115: Ensure spelling is correct
Context: ... Tag: 'name' } }) ``` Currentlly it is not possible to use custom index ...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[grammar] ~115-~115: Ensure spelling is correct
Context: ...es. This also works for compound unique contraints just like for [compound IDs](#compound-...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

Copy link
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks! I'll merge it after a new version is published.

@ymc9 ymc9 merged commit 10b0755 into zenstackhq:main Aug 9, 2025
4 checks passed
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.

2 participants