feat(openapi): exclude procedures from spec generation#491
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe changes introduce an Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant OpenAPIGenerator
participant Procedure
User->>OpenAPIGenerator: generate({ exclude })
OpenAPIGenerator->>Procedure: resolveContractProcedures()
loop For each procedure
OpenAPIGenerator->>OpenAPIGenerator: exclude(procedure, path)?
alt Excluded
OpenAPIGenerator-->>Procedure: Skip
else
OpenAPIGenerator-->>Procedure: Include in OpenAPI doc
end
end
OpenAPIGenerator-->>User: Return OpenAPI document
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (2)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/nest
@orpc/openapi
@orpc/react
@orpc/openapi-client
@orpc/react-query
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/openapi/src/openapi-generator.test.ts (1)
776-789: Comprehensive test for new exclude optionThe test effectively verifies that the
excludeoption works as expected by:
- Creating an
OpenAPIGeneratorinstance- Providing an
excludefunction that always returns true- Verifying the generated document only contains default info
- Confirming the
excludefunction is called with the expected argumentsConsider adding another test case where some procedures are excluded and others are included to verify partial filtering works correctly.
it('openAPIGenerator.generate respect exclude option', async () => { const openAPIGenerator = new OpenAPIGenerator({ }) const exclude = vi.fn(() => true) await expect(openAPIGenerator.generate({ ping: oc }, { exclude })).resolves.toEqual({ openapi: '3.1.1', info: { title: 'API Reference', version: '0.0.0' }, }) expect(exclude).toHaveBeenCalledTimes(1) expect(exclude).toHaveBeenCalledWith(oc, ['ping']) }) + + it('openAPIGenerator.generate respects partial exclude filtering', async () => { + const openAPIGenerator = new OpenAPIGenerator({}) + + // Only exclude procedures that have a specific path + const exclude = vi.fn((_, path) => path[0] === 'admin') + + await expect(openAPIGenerator.generate({ + ping: oc, + admin: oc + }, { exclude })).resolves.toMatchObject({ + paths: { + '/': { + post: expect.any(Object) + } + } + }) + + expect(exclude).toHaveBeenCalledTimes(2) + })apps/content/docs/openapi/openapi-specification.md (1)
111-120: Clear documentation for the new featureThe new "Excluding Procedures" section clearly explains how to use the
excludeoption. The example is concise and demonstrates a practical use case.Consider enhancing the example to show that the exclude function receives both procedure and path parameters, even if the path isn't used in this example:
const spec = await generator.generate(router, { - exclude: procedure => !!procedure['~orpc'].route.tags?.includes('admin'), + exclude: (procedure, path) => !!procedure['~orpc'].route.tags?.includes('admin'), })This would better indicate to users that the path information is available for filtering decisions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/content/docs/openapi/openapi-specification.md(1 hunks)packages/openapi/src/openapi-generator.test.ts(1 hunks)packages/openapi/src/openapi-generator.ts(3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/openapi/src/openapi-generator.ts (4)
packages/server/src/procedure.ts (1)
AnyProcedure(73-73)packages/contract/src/procedure.ts (1)
AnyContractProcedure(49-49)packages/shared/src/object.ts (1)
clone(48-64)packages/server/src/router-utils.ts (1)
resolveContractProcedures(220-238)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: publish-commit
- GitHub Check: lint
🔇 Additional comments (6)
packages/openapi/src/openapi-generator.ts (5)
3-3: Good: Import statement updated to include AnyProcedureThe import statement has been properly updated to include
AnyProcedurealongsideAnyRouter, which is needed for the new exclude option type signature.
24-31: Well-documented interface extensionThe
OpenAPIGeneratorGenerateOptionsinterface has been extended with a well-documentedexcludeoption. The documentation clearly explains the purpose and includes the default behavior.
53-54: Proper initialization with sensible defaultThe
excludeoption is correctly initialized with a default function that always returns false, which means no procedures are excluded by default. This is a sensible choice that maintains backward compatibility.
59-59: Good practice: preventing option leakageSetting
exclude: undefinedin the output document prevents this implementation detail from leaking into the generated OpenAPI specification.
64-68: Effective implementation of procedure filteringThe filtering logic is properly implemented, ensuring that excluded procedures are filtered out before being processed further. This is the correct place to apply the filtering.
packages/openapi/src/openapi-generator.test.ts (1)
755-755: Good: Improved test organizationIntroducing a describe block to group related tests improves the organization and readability of the test suite.
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
Summary by CodeRabbit
excludeoption.