Skip to content

feat(openapi): exclude procedures from spec generation#491

Merged
dinwwwh merged 2 commits intomainfrom
feat/openapi/filter-generation
May 14, 2025
Merged

feat(openapi): exclude procedures from spec generation#491
dinwwwh merged 2 commits intomainfrom
feat/openapi/filter-generation

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented May 13, 2025

Summary by CodeRabbit

  • New Features
    • Added support for excluding specific procedures from the generated OpenAPI specification using a new exclude option.
  • Documentation
    • Updated documentation to include instructions and examples on how to use the new exclusion feature.
  • Tests
    • Added and reorganized tests to verify that the exclusion option works as intended.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2025

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

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 2:20am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2025

Walkthrough

The changes introduce an exclude option to the OpenAPI generator, allowing users to filter out specific procedures from the generated OpenAPI specification. Documentation was updated to describe this feature, the generator code was modified to support it, and new tests were added to verify its functionality.

Changes

File(s) Change Summary
apps/content/docs/openapi/openapi-specification.md Added documentation for the new exclude option in the OpenAPI generator, including usage examples.
packages/openapi/src/openapi-generator.ts Added exclude option to OpenAPIGeneratorGenerateOptions and updated logic to filter procedures accordingly.
packages/openapi/src/openapi-generator.test.ts Added and reorganized tests to verify the exclude option and error propagation in the generator.

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
Loading

Poem

In the warren of code, a new path appears,
Exclude what you wish—no need for cheers!
With a hop and a skip, the docs now explain,
How to filter your specs, with logic so plain.
Tests nibble and check, all works as it should—
This rabbit’s delighted, as only rabbits could! 🐇

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a8776cc and 4a74b00.

📒 Files selected for processing (2)
  • apps/content/docs/openapi/openapi-specification.md (1 hunks)
  • packages/openapi/src/openapi-generator.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/content/docs/openapi/openapi-specification.md
  • packages/openapi/src/openapi-generator.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint
✨ Finishing Touches
  • 📝 Generate Docstrings

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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @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 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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 13, 2025

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@491

@orpc/client

npm i https://pkg.pr.new/@orpc/client@491

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@491

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@491

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@491

@orpc/react

npm i https://pkg.pr.new/@orpc/react@491

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@491

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@491

@orpc/server

npm i https://pkg.pr.new/@orpc/server@491

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@491

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@491

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@491

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@491

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@491

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@491

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@491

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@491

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@491

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@491

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@491

commit: 4a74b00

Copy link
Copy Markdown

@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 (2)
packages/openapi/src/openapi-generator.test.ts (1)

776-789: Comprehensive test for new exclude option

The test effectively verifies that the exclude option works as expected by:

  1. Creating an OpenAPIGenerator instance
  2. Providing an exclude function that always returns true
  3. Verifying the generated document only contains default info
  4. Confirming the exclude function is called with the expected arguments

Consider 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 feature

The new "Excluding Procedures" section clearly explains how to use the exclude option. 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

📥 Commits

Reviewing files that changed from the base of the PR and between d888fab and a8776cc.

📒 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 AnyProcedure

The import statement has been properly updated to include AnyProcedure alongside AnyRouter, which is needed for the new exclude option type signature.


24-31: Well-documented interface extension

The OpenAPIGeneratorGenerateOptions interface has been extended with a well-documented exclude option. The documentation clearly explains the purpose and includes the default behavior.


53-54: Proper initialization with sensible default

The exclude option 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 leakage

Setting exclude: undefined in the output document prevents this implementation detail from leaking into the generated OpenAPI specification.


64-68: Effective implementation of procedure filtering

The 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 organization

Introducing a describe block to group related tests improves the organization and readability of the test suite.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@dinwwwh dinwwwh merged commit 3cc45a9 into main May 14, 2025
8 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.

1 participant