Skip to content

Commit 0e78373

Browse files
Copilotunnoq
andcommitted
Rename uiType to docsProvider and simplify documentation
Co-authored-by: unnoq <64189902+unnoq@users.noreply.github.com>
1 parent 99f6cba commit 0e78373

File tree

3 files changed

+16
-64
lines changed

3 files changed

+16
-64
lines changed

apps/content/docs/openapi/plugins/openapi-reference.md

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ To use Swagger UI instead of the default Scalar interface:
4646
import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins'
4747

4848
const plugin = new OpenAPIReferencePlugin({
49-
uiType: 'swagger', // Use Swagger UI instead of Scalar
49+
docsProvider: 'swagger', // Use Swagger UI instead of Scalar
5050
schemaConverters: [
5151
new ZodToJsonSchemaConverter(),
5252
],
@@ -63,52 +63,4 @@ const handler = new OpenAPIHandler(router, {
6363
})
6464
```
6565

66-
## Configuration Options
6766

68-
### `uiType`
69-
70-
- **Type:** `'scalar' | 'swagger'`
71-
- **Default:** `'scalar'`
72-
73-
Choose which UI library to use for rendering the API reference documentation.
74-
75-
### `docsConfig`
76-
77-
Pass additional configuration to the UI library:
78-
79-
```ts
80-
const swaggerPlugin = new OpenAPIReferencePlugin({
81-
uiType: 'swagger',
82-
docsConfig: {
83-
// Swagger UI specific options
84-
tryItOutEnabled: true,
85-
deepLinking: true,
86-
// ... other Swagger UI options
87-
}
88-
})
89-
```
90-
91-
For Scalar:
92-
93-
```ts
94-
const scalarPlugin = new OpenAPIReferencePlugin({
95-
uiType: 'scalar', // or omit (default)
96-
docsConfig: {
97-
// Scalar specific options
98-
hideDownloadButton: true,
99-
// ... other Scalar options
100-
}
101-
})
102-
```
103-
104-
### Custom CDN URLs
105-
106-
You can customize the CDN URLs for the UI libraries:
107-
108-
```ts
109-
const plugin = new OpenAPIReferencePlugin({
110-
uiType: 'swagger',
111-
docsScriptUrl: 'https://your-cdn.com/swagger-ui-bundle.js',
112-
docsCssUrl: 'https://your-cdn.com/swagger-ui.css',
113-
})
114-
```

packages/openapi/src/plugins/openapi-reference.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ describe('openAPIReferencePlugin', () => {
129129
expect(await response!.text()).toContain('__SOME_VALUE__')
130130
})
131131

132-
it('should serve swagger UI when uiType is swagger', async () => {
132+
it('should serve swagger UI when docsProvider is swagger', async () => {
133133
const handler = new OpenAPIHandler(router, {
134134
plugins: [
135135
new OpenAPIReferencePlugin({
136136
schemaConverters: [jsonSchemaConverter],
137-
uiType: 'swagger',
137+
docsProvider: 'swagger',
138138
}),
139139
],
140140
})
@@ -152,12 +152,12 @@ describe('openAPIReferencePlugin', () => {
152152
expect(html).not.toContain('Scalar')
153153
})
154154

155-
it('should serve scalar UI when uiType is scalar (default)', async () => {
155+
it('should serve scalar UI when docsProvider is scalar (default)', async () => {
156156
const handler = new OpenAPIHandler(router, {
157157
plugins: [
158158
new OpenAPIReferencePlugin({
159159
schemaConverters: [jsonSchemaConverter],
160-
uiType: 'scalar',
160+
docsProvider: 'scalar',
161161
}),
162162
],
163163
})
@@ -182,7 +182,7 @@ describe('openAPIReferencePlugin', () => {
182182
plugins: [
183183
new OpenAPIReferencePlugin({
184184
schemaConverters: [jsonSchemaConverter],
185-
uiType: 'swagger',
185+
docsProvider: 'swagger',
186186
docsScriptUrl: customScriptUrl,
187187
docsCssUrl: customCssUrl,
188188
}),
@@ -204,7 +204,7 @@ describe('openAPIReferencePlugin', () => {
204204
plugins: [
205205
new OpenAPIReferencePlugin({
206206
schemaConverters: [jsonSchemaConverter],
207-
uiType: 'swagger',
207+
docsProvider: 'swagger',
208208
docsConfig: async () => ({
209209
tryItOutEnabled: true,
210210
customOption: '__SWAGGER_CONFIG__',

packages/openapi/src/plugins/openapi-reference.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAP
3939
*
4040
* @default 'scalar'
4141
*/
42-
uiType?: 'scalar' | 'swagger'
42+
docsProvider?: 'scalar' | 'swagger'
4343

4444
/**
4545
* Arbitrary configuration object for the UI.
@@ -78,7 +78,7 @@ export interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAP
7878
scriptUrl: string,
7979
config: Record<string, unknown> | undefined,
8080
spec: OpenAPI.Document,
81-
uiType: 'scalar' | 'swagger',
81+
docsProvider: 'scalar' | 'swagger',
8282
cssUrl?: string
8383
) => string
8484
}
@@ -90,7 +90,7 @@ export class OpenAPIReferencePlugin<T extends Context> implements StandardHandle
9090
private readonly docsPath: Exclude<OpenAPIReferencePluginOptions<T>['docsPath'], undefined>
9191
private readonly docsTitle: Exclude<OpenAPIReferencePluginOptions<T>['docsTitle'], undefined>
9292
private readonly docsHead: Exclude<OpenAPIReferencePluginOptions<T>['docsHead'], undefined>
93-
private readonly uiType: Exclude<OpenAPIReferencePluginOptions<T>['uiType'], undefined>
93+
private readonly docsProvider: Exclude<OpenAPIReferencePluginOptions<T>['docsProvider'], undefined>
9494
private readonly docsScriptUrl: Exclude<OpenAPIReferencePluginOptions<T>['docsScriptUrl'], undefined>
9595
private readonly docsCssUrl: OpenAPIReferencePluginOptions<T>['docsCssUrl']
9696
private readonly docsConfig: OpenAPIReferencePluginOptions<T>['docsConfig']
@@ -101,18 +101,18 @@ export class OpenAPIReferencePlugin<T extends Context> implements StandardHandle
101101
this.docsPath = options.docsPath ?? '/'
102102
this.docsTitle = options.docsTitle ?? 'API Reference'
103103
this.docsConfig = options.docsConfig ?? undefined
104-
this.uiType = options.uiType ?? 'scalar'
104+
this.docsProvider = options.docsProvider ?? 'scalar'
105105

106106
// Set default script URL based on UI type
107107
this.docsScriptUrl = options.docsScriptUrl ?? (
108-
this.uiType === 'swagger'
108+
this.docsProvider === 'swagger'
109109
? 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui-bundle.js'
110110
: 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
111111
)
112112

113113
// Set CSS URL for Swagger UI
114114
this.docsCssUrl = options.docsCssUrl ?? (
115-
this.uiType === 'swagger'
115+
this.docsProvider === 'swagger'
116116
? 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui.css'
117117
: undefined
118118
)
@@ -123,8 +123,8 @@ export class OpenAPIReferencePlugin<T extends Context> implements StandardHandle
123123

124124
const esc = (s: string) => s.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
125125

126-
this.renderDocsHtml = options.renderDocsHtml ?? ((specUrl, title, head, scriptUrl, config, spec, uiType, cssUrl) => {
127-
if (uiType === 'swagger') {
126+
this.renderDocsHtml = options.renderDocsHtml ?? ((specUrl, title, head, scriptUrl, config, spec, docsProvider, cssUrl) => {
127+
if (docsProvider === 'swagger') {
128128
// Swagger UI configuration
129129
const swaggerConfig = {
130130
dom_id: '#app',
@@ -237,7 +237,7 @@ export class OpenAPIReferencePlugin<T extends Context> implements StandardHandle
237237
await value(this.docsScriptUrl, options),
238238
await value(this.docsConfig, options),
239239
await generateSpec(),
240-
this.uiType,
240+
this.docsProvider,
241241
this.docsCssUrl ? await value(this.docsCssUrl, options) : undefined,
242242
)
243243

0 commit comments

Comments
 (0)