Skip to content

feat(openapi): override operationId and spec callback for extending operations#818

Merged
dinwwwh merged 1 commit intomainfrom
feat/openapi/support-override-operatorId-and-extend-spec
Aug 2, 2025
Merged

feat(openapi): override operationId and spec callback for extending operations#818
dinwwwh merged 1 commit intomainfrom
feat/openapi/support-override-operatorId-and-extend-spec

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Aug 2, 2025

  • Allow overriding auto-generated operationId in route configuration
  • Accept route.spec as callback function for extending operation objects
  • Enable dynamic modification of OpenAPI operation specifications

Summary by CodeRabbit

  • New Features

    • Added support for explicitly setting an operation ID for endpoints in OpenAPI integration.
    • Enabled dynamic extension of OpenAPI operation objects using a callback function for advanced customization.
  • Documentation

    • Enhanced OpenAPI documentation with clearer explanations and new examples for setting operation IDs and extending operation objects.
  • Tests

    • Added new tests to verify dynamic extension and customization of OpenAPI operation objects.

…ending operations

- Allow overriding auto-generated operationId in route configuration
- Accept route.spec as callback function for extending operation objects
- Enable dynamic modification of OpenAPI operation specifications
@dinwwwh dinwwwh requested a review from Copilot August 2, 2025 02:54
@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 2, 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 Aug 2, 2025 2:57am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 2, 2025

Walkthrough

This change extends the Route interface to support an optional operationId and allows the spec property to be either an OpenAPI operation object or a function that modifies it. Documentation and tests are updated to reflect this, and the OpenAPI generator logic is adjusted to handle the new spec behavior.

Changes

Cohort / File(s) Change Summary
Documentation updates
apps/content/docs/openapi/openapi-specification.md
Enhanced documentation to clarify operationId usage, expanded spec property explanation to include function-based extension, added examples for security metadata and middleware, and made minor formatting improvements.
Route interface enhancement
packages/contract/src/route.ts
Added optional operationId property to Route interface and changed spec property type to allow either an OpenAPI operation object or a function that modifies it.
OpenAPI generator logic
packages/openapi/src/openapi-generator.ts
Refactored variable naming for clarity, updated logic to support spec as a function for dynamic operation object extension, and improved error messages.
OpenAPI tests
packages/openapi/src/openapi-generator.test.ts
Added tests for spec as a function, verifying operation object extension and correct merging of security and metadata. Updated existing tests to include explicit operationId usage.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Route
    participant OpenAPIGenerator

    User->>Route: Define route with optional operationId and spec (object or function)
    Route->>OpenAPIGenerator: Pass route definition
    OpenAPIGenerator->>OpenAPIGenerator: If spec is object, use as operation object
    OpenAPIGenerator->>OpenAPIGenerator: If spec is function, call with current operation object
    OpenAPIGenerator-->>User: Return generated OpenAPI operation with correct operationId and extensions
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

  • unnoq/orpc#577: Adds support for overriding the entire operation spec with a static object; this PR generalizes that by allowing dynamic modification via a function.

Suggested labels

size:M

Poem

A rabbit hopped through routes anew,
With specs that flex and functions too!
Operation IDs now clear and bright,
Docs and tests keep things just right.
Dynamic paths, security in tow—
OpenAPI grows, and off we go!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 8646d1e and 7cede84.

📒 Files selected for processing (4)
  • apps/content/docs/openapi/openapi-specification.md (3 hunks)
  • packages/contract/src/route.ts (2 hunks)
  • packages/openapi/src/openapi-generator.test.ts (3 hunks)
  • packages/openapi/src/openapi-generator.ts (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/openapi/src/openapi-generator.ts (1)
packages/zod/src/converter.ts (2)
  • def (643-680)
  • def (682-684)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint
  • GitHub Check: publish-commit
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (10)
apps/content/docs/openapi/openapi-specification.md (3)

171-171: LGTM! Clear documentation of new operationId feature.

The documentation correctly explains that operationId can override the auto-generated value, and the spec property can now be either an override object or a callback function for extending operations.

Also applies to: 177-177


208-208: Excellent documentation with clear callback example.

The updated description and example effectively demonstrate how to use route.spec as a callback function to extend operation objects. The security metadata example is practical and well-structured.

Also applies to: 213-222


232-232: Consistent documentation across different contexts.

The middleware example complements the route.spec callback documentation by showing how security metadata can be applied in various contexts, maintaining consistency in the documentation.

Also applies to: 239-239

packages/openapi/src/openapi-generator.ts (3)

122-122: Good variable renaming for clarity.

Renaming operationId to stringPath improves code readability and reduces confusion now that there's an actual operationId property in the route configuration.


132-151: Correct implementation of spec callback functionality.

The logic properly handles both use cases:

  • Uses spec directly when it's an object or creates default operation object with operationId fallback
  • Invokes spec as a function when provided, allowing dynamic extension of the operation object

The implementation correctly supports the new operationId property with appropriate fallback to stringPath.


163-163: Consistent error message update.

The error message correctly references stringPath instead of the old variable name, maintaining consistency with the refactoring.

packages/contract/src/route.ts (2)

24-30: Well-defined operationId property addition.

The new operationId property is properly typed as an optional string with clear documentation explaining its purpose and default behavior. The interface addition aligns perfectly with the implementation.


138-138: Correct type definition for spec callback functionality.

The updated type union properly supports both direct OpenAPI.OperationObject specification and callback functions that transform the current operation object. The function signature accurately reflects the intended behavior.

packages/openapi/src/openapi-generator.test.ts (2)

60-60: Proper test coverage for operationId functionality.

The test correctly validates that explicitly set operationId values are properly reflected in the generated OpenAPI specification, ensuring the new feature works as intended.

Also applies to: 71-71


901-927: Comprehensive test for spec callback functionality.

This test excellently validates the spec callback feature by:

  • Confirming the callback can extend the operation object with custom properties
  • Verifying security metadata from custom errors is properly merged
  • Ensuring auto-generated content (requestBody, responses) is preserved
  • Testing the integration of multiple features working together

The test provides thorough coverage of the new functionality.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/openapi/support-override-operatorId-and-extend-spec

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

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 2, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the OpenAPI generation capabilities by introducing more granular control over how operation specifications are defined. It allows developers to explicitly set operationId values and dynamically modify the generated OpenAPI operation objects using a callback function, providing greater flexibility and customization for API documentation.

Highlights

  • OpenAPI Customization: Introduced the ability to explicitly define operationId within route configurations, allowing developers to override the auto-generated values for better control over OpenAPI documentation.
  • Dynamic Spec Modification: Enabled the route.spec property to accept a callback function. This allows for dynamic and programmatic extension or modification of the OpenAPI operation object during generation, providing greater flexibility for complex scenarios.
  • Documentation & Testing: Updated the OpenAPI documentation with clear examples for the new operationId override and spec callback features, and added comprehensive test cases to ensure their correct implementation and behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances OpenAPI operation configuration by allowing dynamic customization of operation IDs and specifications. It enables developers to override auto-generated operation IDs and use callback functions to extend operation objects with custom properties like security configurations.

  • Add operationId field to route configuration for overriding auto-generated values
  • Support callback functions in route.spec for dynamic operation object extension
  • Update OpenAPI generator to handle both static and callback-based specifications

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/contract/src/route.ts Adds operationId field and updates spec type to support callback functions
packages/openapi/src/openapi-generator.ts Implements logic to handle custom operation IDs and callback-based spec extensions
packages/openapi/src/openapi-generator.test.ts Adds test cases for custom operation ID and callback spec functionality
apps/content/docs/openapi/openapi-specification.md Updates documentation with examples of new features

Comment thread packages/openapi/src/openapi-generator.ts
Comment thread packages/openapi/src/openapi-generator.ts
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the ability to override operationId and use a callback function for spec to extend operation objects, enhancing OpenAPI specification generation. A potential issue was identified in packages/openapi/src/openapi-generator.ts regarding the handling of null values for the spec property, and a code suggestion has been provided to address it.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Aug 2, 2025

More templates

@orpc/arktype

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

@orpc/client

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

@orpc/contract

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

@orpc/experimental-durable-event-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-event-iterator@818

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@818

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@818

@orpc/nest

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/react

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@818

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/standard-server-peer

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

@orpc/svelte-query

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

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@818

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@818

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 7cede84

@dinwwwh dinwwwh merged commit 9840356 into main Aug 2, 2025
11 checks passed
@dosubot dosubot Bot mentioned this pull request Sep 5, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants