fix(openapi): spec generator in case commonSchemas + GET + compact + no params - #920
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThe 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
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 unit tests
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. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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
-
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. ↩
There was a problem hiding this comment.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-event-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@orpc/react
@orpc/react-query
@orpc/experimental-react-swr
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
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/unknownThe expectations correctly validate:
- No requestBody for GET,
- Single deepObject query param
userderived from a$ref’d object,- 200 response shape.
Consider adding one more case to prevent regressions for
$refpointing toany/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.
📒 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 thefindcommand to locateopenapi-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 inputThis route setup directly targets the bug scenario and keeps the fixture close to the “commonSchemas” suite. LGTM.
Summary by CodeRabbit
Bug Fixes
Tests