docs(recipe): add NestJS + Swagger OpenAPI merge guide#626
Conversation
|
@lsmith77 is attempting to deploy a commit to the ZenStack Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
Next review available in: 45 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR adds documentation to docs/recipe/nestjs.md covering two NestJS integration patterns: sharing ZenStack's API handler across thin per-resource controllers via a shared service, and merging the generated ZenStack OpenAPI spec with NestJS's Swagger documentation. ChangesNestJS Recipe Docs
Estimated code review effort: 1 (Trivial) | ~5 minutes Related PRs: None mentioned. Suggested labels: documentation Suggested reviewers: None specified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 `@docs/recipe/nestjs.md`:
- Around line 188-194: The request path passed from handleRequest to
RestApiHandler still keeps a leading slash after removing the /api prefix, which
can break resource-relative route matching. Update the relativePath handling in
handleRequest so it strips the leading slash as well before calling
this.apiHandler.handleRequest, and keep the change localized around the existing
req.path normalization logic.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 7ad7dbc9-6a86-479f-a1d2-cd84d0a001c3
📒 Files selected for processing (1)
docs/recipe/nestjs.md
Extend the NestJS recipe with two patterns drawn from a production ZenStack + NestJS app: - Sharing the RestApiHandler across thin, per-resource controllers so guards, interceptors, and Swagger decorators can be attached per resource while delegation stays in one place. - Merging the handler's generated OpenAPI spec with @nestjs/swagger into a single Swagger UI: re-prefixing ZenStack paths to the NestJS global prefix, merging paths (NestJS operation wins) and component schemas, and using respectAccessPolicies so the published spec matches what the API exposes.
09e0260 to
4c2bc31
Compare
What
Extends the NestJS recipe (
docs/recipe/nestjs.md) with two patterns for going beyond the basic catch-all handler, both drawn from a production ZenStack 3.x + NestJS app.Sharing the handler across thin controllers
Wrapping
RestApiHandlerin a service and forwarding from small, per-resource controllers, so guards, interceptors, rate limits, and Swagger decorators attach per resource while the delegation logic stays in one place.Merging the OpenAPI spec with @nestjs/swagger
A single Swagger UI that documents both the handler's schema-generated endpoints and hand-written NestJS controllers. Covers the two things that actually trip people up:
endpoint(/post/{id}); NestJS paths carry the global prefix (/api/post/{id}). The helper re-prefixes ZenStack paths before merging.paths(NestJS operation wins on conflict) and unioncomponents.schemas.Uses
generateSpec({ respectAccessPolicies: true })so the published spec matches what the API actually exposes, and closes with a "going further" tip pointing at response-header merging, public/internal filtering, and schema pruning.Why
The existing recipe stops at the
@All('/*path')catch-all. There was no guidance on producing unified OpenAPI docs when a real app mixes schema-generated CRUD with custom NestJS endpoints — a common need, and easy to get the path-prefix/component merge subtly wrong.Open question: should some of this become shared code?
Parts of what this recipe documents by hand are generic enough to package, and I'd value maintainer input on whether/where that should land. The candidates split along a dependency line:
@nestjs/*deps) —pruneUnreferencedSchemas(BFS over$refchains to drop unreachablecomponents.schemas), path re-prefixing, and REST query normalization + default-vs-max page size (working aroundpageSizebeing both the default and the hard ceiling). These would fit naturally inapi/restalongsideopenapi.ts, and would benefit any framework serving the spec — not just NestJS.@nestjs/swagger) — the spec merge itself and an optional thin-controller helper. Can't live in core (no@nestjs/*deps there), so this would be a separate package.Would you be open to taking the framework-agnostic helpers into
api/rest? If a dedicated@zenstackhq/server/nestadapter is preferred instead, happy to scope that. Otherwise this stays a documentation-only contribution.Notes
service/openapi/restful.md; only touches the current (v3) recipe, not the versioned 2.x docs.Summary by CodeRabbit