Skip to content

fix(openapi): spec generator in case commonSchemas + GET + compact + no params - #920

Merged
dinwwwh merged 1 commit into
mainfrom
fix/openapi/spec/commonSchemas-get-compact-no-params
Aug 23, 2025
Merged

fix(openapi): spec generator in case commonSchemas + GET + compact + no params#920
dinwwwh merged 1 commit into
mainfrom
fix/openapi/spec/commonSchemas-get-compact-no-params

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Aug 23, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Corrected OpenAPI generation for GET endpoints using referenced query schemas, ensuring parameters are accurately expanded and validated.
    • Improved handling of complex query objects (e.g., deepObject style), producing precise parameter definitions in the spec.
  • Tests

    • Added a test case for a GET route with a referenced query object to verify correct parameter generation and response schema handling.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 23, 2025
@vercel

vercel Bot commented Aug 23, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
orpc Ready Ready Preview Comment Aug 23, 2025 1:20am

@coderabbitai

coderabbitai Bot commented Aug 23, 2025

Copy link
Copy Markdown

Walkthrough

The OpenAPI generator now resolves JSON Schema $ref for GET input before validation and parameter generation. Tests add a new GET route without params and validate the produced OpenAPI spec for deepObject query parameters and a 200 JSON response schema.

Changes

Cohort / File(s) Summary
OpenAPI generator logic
packages/openapi/src/openapi-generator.ts
Before generating query parameters for GET routes, the code resolves JSON Schema references, validates the resolved schema as an object, and uses it to produce OpenAPI parameters. Non-GET behavior unchanged.
Tests for GET without params
packages/openapi/src/openapi-generator.test.ts
Adds a route getWithoutParams with Query input and a test asserting a /getWithoutParams GET path with a single deepObject user query param (ref: User) and a 200 application/json response using anyOf.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant OC as OpenAPIGenerator
  participant Doc as OpenAPI Doc
  participant Ref as resolveOpenAPIJsonSchemaRef
  participant Val as isObjectSchema
  participant Param as toOpenAPIParameters

  OC->>Doc: Read route (GET) input schema (may be $ref)
  OC->>Ref: resolveOpenAPIJsonSchemaRef(doc, schema)
  Ref-->>OC: resolvedSchema
  OC->>Val: isObjectSchema(resolvedSchema)?
  alt Object schema
    OC->>Param: toOpenAPIParameters(resolvedSchema, "query")
    Param-->>OC: parameters[]
    OC->>Doc: Add parameters to path GET
  else Not object
    OC->>OC: Throw error: "GET input must be an object"
  end

  note over OC,Doc: Non-GET paths unchanged
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nudge the refs, then hop along,
Unwrap the schema, crisp and strong.
Query carrots in a tidy row,
Deep baskets where the users go.
Green ticks bloom—specs align—
Thump-thump, shipped on rabbit time. 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/openapi/spec/commonSchemas-get-compact-no-params

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

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

Copy link
Copy Markdown
Contributor

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 fixes a bug in the OpenAPI spec generator where GET requests using common schemas (via $ref) and a compact input structure would not be correctly processed, leading to an invalid or incomplete OpenAPI specification. The fix ensures that schema references are resolved before validation and parameter generation for GET requests, allowing the generator to correctly interpret and include parameters from referenced schemas.

Highlights

  • OpenAPI Schema Resolution: The OpenAPI generator now correctly resolves schema references ($ref) for GET request inputs before validating the schema type and generating query parameters. This addresses an issue where common schemas were not properly handled.
  • Improved GET Request Handling: Ensures that GET endpoints with input schemas defined as common schemas (e.g., User schema) are correctly represented in the generated OpenAPI specification, including their query parameters.
  • New Test Case: A new test has been added to validate the fix, specifically covering the scenario of a GET route with a compact input structure and a common schema used for its parameters.
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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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.

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

Copy link
Copy Markdown
Contributor

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 fixes an issue in the OpenAPI specification generator where it would fail for GET requests that use commonSchemas for their input. The change correctly resolves $ref schemas before processing them. The fix is well-tested with a new test case that covers the specific scenario. I've added one suggestion to further improve the logic to also handle any schemas referenced via commonSchemas, making the implementation more robust.

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

codecov Bot commented Aug 23, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pkg-pr-new

pkg-pr-new Bot commented Aug 23, 2025

Copy link
Copy Markdown
More templates

@orpc/arktype

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

@orpc/client

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

@orpc/contract

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

@orpc/experimental-durable-event-iterator

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

@orpc/hey-api

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

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@920

@orpc/json-schema

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

@orpc/nest

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@920

@orpc/react

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

@orpc/react-query

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

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@920

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-aws-lambda

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/standard-server-peer

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

@orpc/svelte-query

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

@orpc/tanstack-query

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

@orpc/trpc

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

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 949cb81

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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

1520-1555: Assertions cover deepObject query parameter generation; add a case for $ref→any/unknown

The expectations correctly validate:

  • No requestBody for GET,
  • Single deepObject query param user derived from a $ref’d object,
  • 200 response shape.

Consider adding one more case to prevent regressions for $ref pointing to any/unknown (allowed per error message). Example:

Add this test to the same “generator - commonSchemas” block:

it('works with method=GET + compact + input is $ref to any/unknown', async () => {
  const Unknown = z.unknown()
  const spec2 = await generator.generate({
    getUnknown: oc.route({ method: 'GET' }).input(Unknown),
  }, {
    commonSchemas: {
      Unknown: { schema: Unknown },
    },
  })

  // Should not throw and should not emit query params or requestBody
  expect(spec2.paths!['/getUnknown']).toEqual({
    get: {
      operationId: 'getUnknown',
      responses: {
          description: 'OK',
          content: expect.any(Object),
        },
      },
    },
  })
})
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 683afe7 and 949cb81.

📒 Files selected for processing (2)
  • packages/openapi/src/openapi-generator.test.ts (2 hunks)
  • packages/openapi/src/openapi-generator.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/openapi/src/openapi-generator.ts (2)
packages/openapi/src/openapi-utils.ts (2)
  • resolveOpenAPIJsonSchemaRef (171-179)
  • toOpenAPIParameters (103-138)
packages/openapi/src/schema-utils.ts (1)
  • isObjectSchema (15-17)
packages/openapi/src/openapi-generator.test.ts (1)
packages/contract/src/builder.ts (1)
  • oc (189-198)
⏰ 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). (4)
  • GitHub Check: publish-commit
  • GitHub Check: lint
  • GitHub Check: test
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
packages/openapi/src/openapi-generator.ts (1)

325-336: It seems the script is still pending execution. Please provide the output of the find command to locate openapi-generator.ts, or confirm if the file exists at a different path.

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

1085-1086: Good addition: exercising GET+compact with commonSchemas input

This route setup directly targets the bug scenario and keeps the fixture close to the “commonSchemas” suite. LGTM.

@dinwwwh
dinwwwh merged commit d7c4772 into main Aug 23, 2025
11 checks passed
@dinwwwh
dinwwwh deleted the fix/openapi/spec/commonSchemas-get-compact-no-params branch June 22, 2026 01:52
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.

1 participant