feat(server): add specific 4xx error responses to REST OpenAPI spec#2504
feat(server): add specific 4xx error responses to REST OpenAPI spec#2504
Conversation
Use distinct error descriptions for 400, 403, 404, and 422 instead of a generic "Error". Add `respectAccessPolicies` option that inspects @@allow/@@deny rules per operation and conditionally includes 403 responses on mutations (create, update, delete, relationship changes) when access is not unconditionally allowed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Claude finished @ymc9's task —— View job Code Review Complete ✅I've thoroughly reviewed this PR that adds specific 4xx error responses to the REST OpenAPI spec. Here's my comprehensive analysis: Review Tasks:
✅ Strengths1. Well-Designed API Enhancement
2. Robust Policy Analysis LogicThe
3. Comprehensive Test CoverageThe new tests (lines 666-855) cover all critical scenarios:
4. Clean Implementation Details
🔍 Areas for Consideration1. Minor: Error Message Consistency
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an optional Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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
🧹 Nitpick comments (1)
packages/server/test/openapi/rest-openapi.test.ts (1)
733-751: Add one regression case for constant-false denyPlease add a case like
@@allow('all', true)+@@deny('all', false)asserting no403, to lock in unconditional-allow behavior when deny is statically impossible.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/server/test/openapi/rest-openapi.test.ts` around lines 733 - 751, Add a regression test that verifies a statically-impossible deny does not produce a 403: create a policySchema with @@allow('all', true) and @@deny('all', false), use createTestClient(...) to get the schema, instantiate RestApiHandler({ schema: client.$schema, endpoint: 'http://localhost/api' }), call await h.generateSpec({ respectAccessPolicies: true }) and assert that the generated spec does not include a 403 response (i.e., expect s.paths?.['/item']?.post?.responses?.['403'] toBeUndefined()). This mirrors the existing test that checks deny overrides, but ensures constant-false deny is ignored when allow is unconditional.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/server/src/api/rest/openapi.ts`:
- Around line 1068-1072: The code currently treats any matching @@deny attribute
as a deny regardless of its condition; update the logic in mayDenyAccess to
ignore @@deny entries whose condition is a literal false and only treat a deny
as effective when its condition evaluates truthy (or when there are no
args/unconditional). Concretely: replace the simple relevantDeny.length>0 check
with iterating relevantDeny, skip entries where attr.args is a literal boolean
false, and for the rest evaluate the condition using the same
evaluation/resolution used elsewhere (the same mechanism as matchesOperation or
the policy condition evaluator used for allows); return true only if any
evaluated deny condition yields true (or if an entry has no args), otherwise
return false.
---
Nitpick comments:
In `@packages/server/test/openapi/rest-openapi.test.ts`:
- Around line 733-751: Add a regression test that verifies a
statically-impossible deny does not produce a 403: create a policySchema with
@@allow('all', true) and @@deny('all', false), use createTestClient(...) to get
the schema, instantiate RestApiHandler({ schema: client.$schema, endpoint:
'http://localhost/api' }), call await h.generateSpec({ respectAccessPolicies:
true }) and assert that the generated spec does not include a 403 response
(i.e., expect s.paths?.['/item']?.post?.responses?.['403'] toBeUndefined()).
This mirrors the existing test that checks deny overrides, but ensures
constant-false deny is ignored when allow is unconditional.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 745cef07-df2e-4fb2-81b8-b900e689163f
📒 Files selected for processing (4)
packages/server/src/api/common/types.tspackages/server/src/api/rest/openapi.tspackages/server/test/openapi/baseline/rest.baseline.yamlpackages/server/test/openapi/rest-openapi.test.ts
…yAccess A @@deny('op', false) is a no-op that can never trigger, so it should not force a 403 response into the OpenAPI spec. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Claude finished @ymc9's task —— View job Code Review Complete ✅I've thoroughly reviewed this PR that adds specific 4xx error responses to the REST OpenAPI spec. Here's my comprehensive analysis: Review Tasks:
✅ Strengths1. Well-Designed API Enhancement
2. Robust Policy Analysis LogicThe
3. Comprehensive Test CoverageThe new tests (lines 666-875) cover all critical scenarios:
4. Clean Implementation Details
🔍 Areas for Consideration1. Minor: Error Message Consistency
|
Summary
respectAccessPoliciesoption toOpenApiSpecOptionsthat inspects@@allow/@@denyrules and conditionally includes 403 responses on mutation operations (create, update, delete, relationship changes) when access is not unconditionally allowedupdatepolicyTest plan
respectAccessPoliciescovering:@@allow('all', true)→ no 403@@denyrule overrides constant allow → 403🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements
Tests