feat(openapi): Add Swagger UI support to OpenAPI Reference Plugin - #904
Conversation
|
@unnoq 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: unnoq <64189902+unnoq@users.noreply.github.com>
| import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins' | ||
|
|
||
| const plugin = new OpenAPIReferencePlugin({ | ||
| uiType: 'swagger', // Use Swagger UI instead of Scalar |
There was a problem hiding this comment.
There is any better option name for uiType ? docsProvider ? docsType? ...
There was a problem hiding this comment.
@copilot use better option name, make it more consistentcy
There was a problem hiding this comment.
I've renamed uiType to docsProvider for better consistency with the existing docs* naming pattern in the API. This change has been applied throughout the codebase including the TypeScript interface, implementation, tests, and documentation. Commit: 0e78373
| import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins' | ||
|
|
||
| const plugin = new OpenAPIReferencePlugin({ | ||
| uiType: 'swagger', // Use Swagger UI instead of Scalar |
There was a problem hiding this comment.
@copilot use better option name, make it more consistentcy
|
|
||
| ## Configuration Options | ||
|
|
||
| ### `uiType` |
There was a problem hiding this comment.
@copilot do not add extra any section - the first docs is enough now.
There was a problem hiding this comment.
I've simplified the documentation by removing the extra "Configuration Options" section and its subsections. The documentation now focuses on the essential setup and Swagger UI usage examples without the detailed configuration sections. Commit: 0e78373
Co-authored-by: unnoq <64189902+unnoq@users.noreply.github.com>
| By default, the API reference client is served at the root path (`/`), and the OpenAPI specification is available at `/spec.json`. You can customize these paths by providing the `docsPath` and `specPath` options. | ||
| ::: | ||
|
|
||
| ## Using Swagger UI |
There was a problem hiding this comment.
@copilot remove this section, only mention docsProvider in Setup section is enough
| await value(this.docsConfig, options), | ||
| await generateSpec(), | ||
| this.docsProvider, | ||
| this.docsCssUrl ? await value(this.docsCssUrl, options) : undefined, |
There was a problem hiding this comment.
@copilot NO need condition here, just await value directly
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Join our Discord community for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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: |
The OpenAPI Reference Plugin now supports both Scalar and Swagger UI for rendering API documentation, giving developers the flexibility to choose their preferred interface.
Changes Made
New Configuration Options
docsProvider: Choose between'scalar'(default) or'swagger'- renamed fromuiTypefor better consistency with the existingdocs*naming patterndocsCssUrl: CSS URL for Swagger UI styling (automatically configured)docsScriptUrlwith smart defaults based on UI typeImplementation Details
The plugin automatically configures the appropriate CDN URLs and HTML structure based on the selected UI type:
Scalar (default):
https://cdn.jsdelivr.net/npm/@scalar/api-referenceScalar.createApiReference()Swagger UI:
https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui-bundle.jshttps://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui.cssSwaggerUIBundle()Usage Examples
Using Swagger UI:
Using Scalar (default - no changes needed):
Documentation Improvements
Simplified the documentation by focusing on essential usage patterns and removing verbose configuration sections for better readability.
Backward Compatibility
This change includes a breaking change: the
uiTypeoption has been renamed todocsProviderfor better API consistency. However, all functionality remains the same, and the default behavior is unchanged (Scalar UI).Testing
Updated comprehensive test coverage including:
Fixes #903.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.