@orpc/openapi 1.8.1 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/adapters/fetch/index.d.mts +5 -2
- package/dist/adapters/fetch/index.d.ts +5 -2
- package/dist/adapters/node/index.d.mts +5 -2
- package/dist/adapters/node/index.d.ts +5 -2
- package/dist/plugins/index.d.mts +17 -2
- package/dist/plugins/index.d.ts +17 -2
- package/dist/plugins/index.mjs +57 -17
- package/package.json +8 -8
package/README.md
CHANGED
@@ -31,7 +31,7 @@
|
|
31
31
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
32
32
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
33
33
|
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
34
|
-
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
35
35
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
36
36
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
37
37
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
@@ -54,6 +54,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
54
54
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
55
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
56
56
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
57
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
57
58
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
58
59
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
59
60
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
2
|
-
import {
|
2
|
+
import { FetchHandlerOptions, FetchHandler } from '@orpc/server/fetch';
|
3
3
|
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.CQmjvnb0.mjs';
|
4
4
|
import '@orpc/openapi-client/standard';
|
5
5
|
import '@orpc/server/standard';
|
6
6
|
import '@orpc/client';
|
7
7
|
import '@orpc/shared';
|
8
8
|
|
9
|
+
interface OpenAPIHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<StandardOpenAPIHandlerOptions<T>, 'plugins'> {
|
10
|
+
}
|
9
11
|
/**
|
10
12
|
* OpenAPI Handler for Fetch Server
|
11
13
|
*
|
@@ -13,7 +15,8 @@ import '@orpc/shared';
|
|
13
15
|
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
14
16
|
*/
|
15
17
|
declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
|
16
|
-
constructor(router: Router<any, T>, options?: NoInfer<
|
18
|
+
constructor(router: Router<any, T>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
17
19
|
}
|
18
20
|
|
19
21
|
export { OpenAPIHandler };
|
22
|
+
export type { OpenAPIHandlerOptions };
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
2
|
-
import {
|
2
|
+
import { FetchHandlerOptions, FetchHandler } from '@orpc/server/fetch';
|
3
3
|
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.CQmjvnb0.js';
|
4
4
|
import '@orpc/openapi-client/standard';
|
5
5
|
import '@orpc/server/standard';
|
6
6
|
import '@orpc/client';
|
7
7
|
import '@orpc/shared';
|
8
8
|
|
9
|
+
interface OpenAPIHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<StandardOpenAPIHandlerOptions<T>, 'plugins'> {
|
10
|
+
}
|
9
11
|
/**
|
10
12
|
* OpenAPI Handler for Fetch Server
|
11
13
|
*
|
@@ -13,7 +15,8 @@ import '@orpc/shared';
|
|
13
15
|
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
14
16
|
*/
|
15
17
|
declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
|
16
|
-
constructor(router: Router<any, T>, options?: NoInfer<
|
18
|
+
constructor(router: Router<any, T>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
17
19
|
}
|
18
20
|
|
19
21
|
export { OpenAPIHandler };
|
22
|
+
export type { OpenAPIHandlerOptions };
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
2
|
-
import {
|
2
|
+
import { NodeHttpHandlerOptions, NodeHttpHandler } from '@orpc/server/node';
|
3
3
|
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.CQmjvnb0.mjs';
|
4
4
|
import '@orpc/openapi-client/standard';
|
5
5
|
import '@orpc/server/standard';
|
6
6
|
import '@orpc/client';
|
7
7
|
import '@orpc/shared';
|
8
8
|
|
9
|
+
interface OpenAPIHandlerOptions<T extends Context> extends NodeHttpHandlerOptions<T>, Omit<StandardOpenAPIHandlerOptions<T>, 'plugins'> {
|
10
|
+
}
|
9
11
|
/**
|
10
12
|
* OpenAPI Handler for Node Server
|
11
13
|
*
|
@@ -13,7 +15,8 @@ import '@orpc/shared';
|
|
13
15
|
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
14
16
|
*/
|
15
17
|
declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
|
16
|
-
constructor(router: Router<any, T>, options?: NoInfer<
|
18
|
+
constructor(router: Router<any, T>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
17
19
|
}
|
18
20
|
|
19
21
|
export { OpenAPIHandler };
|
22
|
+
export type { OpenAPIHandlerOptions };
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
2
|
-
import {
|
2
|
+
import { NodeHttpHandlerOptions, NodeHttpHandler } from '@orpc/server/node';
|
3
3
|
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.CQmjvnb0.js';
|
4
4
|
import '@orpc/openapi-client/standard';
|
5
5
|
import '@orpc/server/standard';
|
6
6
|
import '@orpc/client';
|
7
7
|
import '@orpc/shared';
|
8
8
|
|
9
|
+
interface OpenAPIHandlerOptions<T extends Context> extends NodeHttpHandlerOptions<T>, Omit<StandardOpenAPIHandlerOptions<T>, 'plugins'> {
|
10
|
+
}
|
9
11
|
/**
|
10
12
|
* OpenAPI Handler for Node Server
|
11
13
|
*
|
@@ -13,7 +15,8 @@ import '@orpc/shared';
|
|
13
15
|
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
14
16
|
*/
|
15
17
|
declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
|
16
|
-
constructor(router: Router<any, T>, options?: NoInfer<
|
18
|
+
constructor(router: Router<any, T>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
17
19
|
}
|
18
20
|
|
19
21
|
export { OpenAPIHandler };
|
22
|
+
export type { OpenAPIHandlerOptions };
|
package/dist/plugins/index.d.mts
CHANGED
@@ -30,6 +30,12 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
30
30
|
* @default 'API Reference'
|
31
31
|
*/
|
32
32
|
docsTitle?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
33
|
+
/**
|
34
|
+
* The UI library to use for rendering the API reference.
|
35
|
+
*
|
36
|
+
* @default 'scalar'
|
37
|
+
*/
|
38
|
+
docsProvider?: 'scalar' | 'swagger';
|
33
39
|
/**
|
34
40
|
* Arbitrary configuration object for the UI.
|
35
41
|
*/
|
@@ -43,13 +49,20 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
43
49
|
/**
|
44
50
|
* URL of the external script bundle for the reference UI.
|
45
51
|
*
|
46
|
-
*
|
52
|
+
* - For Scalar: defaults to 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
|
53
|
+
* - For Swagger UI: defaults to 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui-bundle.js'
|
47
54
|
*/
|
48
55
|
docsScriptUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
56
|
+
/**
|
57
|
+
* URL of the external CSS bundle for the reference UI (used by Swagger UI).
|
58
|
+
*
|
59
|
+
* @default 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui.css' (if swagger)
|
60
|
+
*/
|
61
|
+
docsCssUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
49
62
|
/**
|
50
63
|
* Override function to generate the full HTML for the docs page.
|
51
64
|
*/
|
52
|
-
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec: OpenAPI.Document) => string;
|
65
|
+
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec: OpenAPI.Document, docsProvider: 'scalar' | 'swagger', cssUrl: string | undefined) => string;
|
53
66
|
}
|
54
67
|
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
55
68
|
private readonly generator;
|
@@ -58,7 +71,9 @@ declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandl
|
|
58
71
|
private readonly docsPath;
|
59
72
|
private readonly docsTitle;
|
60
73
|
private readonly docsHead;
|
74
|
+
private readonly docsProvider;
|
61
75
|
private readonly docsScriptUrl;
|
76
|
+
private readonly docsCssUrl;
|
62
77
|
private readonly docsConfig;
|
63
78
|
private readonly renderDocsHtml;
|
64
79
|
constructor(options?: OpenAPIReferencePluginOptions<T>);
|
package/dist/plugins/index.d.ts
CHANGED
@@ -30,6 +30,12 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
30
30
|
* @default 'API Reference'
|
31
31
|
*/
|
32
32
|
docsTitle?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
33
|
+
/**
|
34
|
+
* The UI library to use for rendering the API reference.
|
35
|
+
*
|
36
|
+
* @default 'scalar'
|
37
|
+
*/
|
38
|
+
docsProvider?: 'scalar' | 'swagger';
|
33
39
|
/**
|
34
40
|
* Arbitrary configuration object for the UI.
|
35
41
|
*/
|
@@ -43,13 +49,20 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
43
49
|
/**
|
44
50
|
* URL of the external script bundle for the reference UI.
|
45
51
|
*
|
46
|
-
*
|
52
|
+
* - For Scalar: defaults to 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
|
53
|
+
* - For Swagger UI: defaults to 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui-bundle.js'
|
47
54
|
*/
|
48
55
|
docsScriptUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
56
|
+
/**
|
57
|
+
* URL of the external CSS bundle for the reference UI (used by Swagger UI).
|
58
|
+
*
|
59
|
+
* @default 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui.css' (if swagger)
|
60
|
+
*/
|
61
|
+
docsCssUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
49
62
|
/**
|
50
63
|
* Override function to generate the full HTML for the docs page.
|
51
64
|
*/
|
52
|
-
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec: OpenAPI.Document) => string;
|
65
|
+
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec: OpenAPI.Document, docsProvider: 'scalar' | 'swagger', cssUrl: string | undefined) => string;
|
53
66
|
}
|
54
67
|
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
55
68
|
private readonly generator;
|
@@ -58,7 +71,9 @@ declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandl
|
|
58
71
|
private readonly docsPath;
|
59
72
|
private readonly docsTitle;
|
60
73
|
private readonly docsHead;
|
74
|
+
private readonly docsProvider;
|
61
75
|
private readonly docsScriptUrl;
|
76
|
+
private readonly docsCssUrl;
|
62
77
|
private readonly docsConfig;
|
63
78
|
private readonly renderDocsHtml;
|
64
79
|
constructor(options?: OpenAPIReferencePluginOptions<T>);
|
package/dist/plugins/index.mjs
CHANGED
@@ -14,7 +14,9 @@ class OpenAPIReferencePlugin {
|
|
14
14
|
docsPath;
|
15
15
|
docsTitle;
|
16
16
|
docsHead;
|
17
|
+
docsProvider;
|
17
18
|
docsScriptUrl;
|
19
|
+
docsCssUrl;
|
18
20
|
docsConfig;
|
19
21
|
renderDocsHtml;
|
20
22
|
constructor(options = {}) {
|
@@ -22,16 +24,59 @@ class OpenAPIReferencePlugin {
|
|
22
24
|
this.docsPath = options.docsPath ?? "/";
|
23
25
|
this.docsTitle = options.docsTitle ?? "API Reference";
|
24
26
|
this.docsConfig = options.docsConfig ?? void 0;
|
25
|
-
this.
|
27
|
+
this.docsProvider = options.docsProvider ?? "scalar";
|
28
|
+
this.docsScriptUrl = options.docsScriptUrl ?? (this.docsProvider === "swagger" ? "https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js" : "https://cdn.jsdelivr.net/npm/@scalar/api-reference");
|
29
|
+
this.docsCssUrl = options.docsCssUrl ?? (this.docsProvider === "swagger" ? "https://unpkg.com/swagger-ui-dist/swagger-ui.css" : void 0);
|
26
30
|
this.docsHead = options.docsHead ?? "";
|
27
31
|
this.specPath = options.specPath ?? "/spec.json";
|
28
32
|
this.generator = new OpenAPIGenerator(options);
|
29
33
|
const esc = (s) => s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
30
|
-
this.renderDocsHtml = options.renderDocsHtml ?? ((specUrl, title, head, scriptUrl, config, spec) => {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
this.renderDocsHtml = options.renderDocsHtml ?? ((specUrl, title, head, scriptUrl, config, spec, docsProvider, cssUrl) => {
|
35
|
+
let body;
|
36
|
+
if (docsProvider === "swagger") {
|
37
|
+
const swaggerConfig = {
|
38
|
+
dom_id: "#app",
|
39
|
+
spec,
|
40
|
+
deepLinking: true,
|
41
|
+
presets: [
|
42
|
+
"SwaggerUIBundle.presets.apis",
|
43
|
+
"SwaggerUIBundle.presets.standalone"
|
44
|
+
],
|
45
|
+
plugins: [
|
46
|
+
"SwaggerUIBundle.plugins.DownloadUrl"
|
47
|
+
],
|
48
|
+
...config
|
49
|
+
};
|
50
|
+
body = `
|
51
|
+
<body>
|
52
|
+
<div id="app"></div>
|
53
|
+
|
54
|
+
<script src="${esc(scriptUrl)}"><\/script>
|
55
|
+
|
56
|
+
<script>
|
57
|
+
window.onload = () => {
|
58
|
+
window.ui = SwaggerUIBundle(${stringifyJSON(swaggerConfig).replace(/"(SwaggerUIBundle\.[^"]+)"/g, "$1")})
|
59
|
+
}
|
60
|
+
<\/script>
|
61
|
+
</body>
|
62
|
+
`;
|
63
|
+
} else {
|
64
|
+
const scalarConfig = {
|
65
|
+
content: stringifyJSON(spec),
|
66
|
+
...config
|
67
|
+
};
|
68
|
+
body = `
|
69
|
+
<body>
|
70
|
+
<div id="app" data-config="${esc(stringifyJSON(scalarConfig))}"></div>
|
71
|
+
|
72
|
+
<script src="${esc(scriptUrl)}"><\/script>
|
73
|
+
|
74
|
+
<script>
|
75
|
+
Scalar.createApiReference('#app', JSON.parse(document.getElementById('app').dataset.config))
|
76
|
+
<\/script>
|
77
|
+
</body>
|
78
|
+
`;
|
79
|
+
}
|
35
80
|
return `
|
36
81
|
<!doctype html>
|
37
82
|
<html>
|
@@ -39,19 +84,12 @@ class OpenAPIReferencePlugin {
|
|
39
84
|
<meta charset="utf-8" />
|
40
85
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
41
86
|
<title>${esc(title)}</title>
|
87
|
+
${cssUrl ? `<link rel="stylesheet" type="text/css" href="${esc(cssUrl)}" />` : ""}
|
42
88
|
${head}
|
43
89
|
</head>
|
44
|
-
|
45
|
-
<div id="app" data-config="${esc(stringifyJSON(finalConfig))}"></div>
|
46
|
-
|
47
|
-
<script src="${esc(scriptUrl)}"><\/script>
|
48
|
-
|
49
|
-
<script>
|
50
|
-
Scalar.createApiReference('#app', JSON.parse(document.getElementById('app').dataset.config))
|
51
|
-
<\/script>
|
52
|
-
</body>
|
90
|
+
${body}
|
53
91
|
</html>
|
54
|
-
|
92
|
+
`;
|
55
93
|
});
|
56
94
|
}
|
57
95
|
init(options, router) {
|
@@ -89,7 +127,9 @@ class OpenAPIReferencePlugin {
|
|
89
127
|
await value(this.docsHead, options2),
|
90
128
|
await value(this.docsScriptUrl, options2),
|
91
129
|
await value(this.docsConfig, options2),
|
92
|
-
await generateSpec()
|
130
|
+
await generateSpec(),
|
131
|
+
this.docsProvider,
|
132
|
+
await value(this.docsCssUrl, options2)
|
93
133
|
);
|
94
134
|
return {
|
95
135
|
matched: true,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/openapi",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.8.
|
4
|
+
"version": "1.8.3",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -50,13 +50,13 @@
|
|
50
50
|
],
|
51
51
|
"dependencies": {
|
52
52
|
"rou3": "^0.7.3",
|
53
|
-
"@orpc/
|
54
|
-
"@orpc/interop": "1.8.
|
55
|
-
"@orpc/client": "1.8.
|
56
|
-
"@orpc/
|
57
|
-
"@orpc/server": "1.8.
|
58
|
-
"@orpc/shared": "1.8.
|
59
|
-
"@orpc/standard-server": "1.8.
|
53
|
+
"@orpc/client": "1.8.3",
|
54
|
+
"@orpc/interop": "1.8.3",
|
55
|
+
"@orpc/openapi-client": "1.8.3",
|
56
|
+
"@orpc/contract": "1.8.3",
|
57
|
+
"@orpc/server": "1.8.3",
|
58
|
+
"@orpc/shared": "1.8.3",
|
59
|
+
"@orpc/standard-server": "1.8.3"
|
60
60
|
},
|
61
61
|
"devDependencies": {
|
62
62
|
"zod": "^4.0.17"
|