@orpc/openapi 0.0.0-next.62473ae → 0.0.0-next.64450c6
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 +27 -17
- package/dist/adapters/fetch/index.d.mts +12 -8
- package/dist/adapters/fetch/index.d.ts +12 -8
- package/dist/adapters/fetch/index.mjs +14 -6
- package/dist/adapters/node/index.d.mts +12 -8
- package/dist/adapters/node/index.d.ts +12 -8
- package/dist/adapters/node/index.mjs +8 -22
- package/dist/adapters/standard/index.d.mts +20 -8
- package/dist/adapters/standard/index.d.ts +20 -8
- package/dist/adapters/standard/index.mjs +5 -2
- package/dist/index.d.mts +91 -155
- package/dist/index.d.ts +91 -155
- package/dist/index.mjs +34 -654
- package/dist/plugins/index.d.mts +70 -0
- package/dist/plugins/index.d.ts +70 -0
- package/dist/plugins/index.mjs +108 -0
- package/dist/shared/{openapi.C_biOx82.mjs → openapi.C_UtQ8Us.mjs} +60 -28
- package/dist/shared/openapi.CwdCLgSU.d.mts +53 -0
- package/dist/shared/openapi.CwdCLgSU.d.ts +53 -0
- package/dist/shared/openapi.D3j94c9n.d.mts +12 -0
- package/dist/shared/openapi.D3j94c9n.d.ts +12 -0
- package/dist/shared/openapi.PDTdnRIU.mjs +595 -0
- package/package.json +15 -22
- package/dist/adapters/hono/index.d.mts +0 -6
- package/dist/adapters/hono/index.d.ts +0 -6
- package/dist/adapters/hono/index.mjs +0 -10
- package/dist/adapters/next/index.d.mts +0 -6
- package/dist/adapters/next/index.d.ts +0 -6
- package/dist/adapters/next/index.mjs +0 -10
- package/dist/shared/openapi.B6uueFtN.mjs +0 -29
- package/dist/shared/openapi.BHG_gu5Z.mjs +0 -8
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Context, HTTPPath, Router } from '@orpc/server';
|
|
2
|
+
import { StandardHandlerInterceptorOptions, StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
3
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
4
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
5
|
+
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.CwdCLgSU.mjs';
|
|
6
|
+
import '@orpc/contract';
|
|
7
|
+
import '@orpc/openapi-client/standard';
|
|
8
|
+
import 'json-schema-typed/draft-2020-12';
|
|
9
|
+
|
|
10
|
+
interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGeneratorOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Options to pass to the OpenAPI generate.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
specGenerateOptions?: Value<Promisable<OpenAPIGeneratorGenerateOptions>, [StandardHandlerInterceptorOptions<T>]>;
|
|
16
|
+
/**
|
|
17
|
+
* The URL path at which to serve the OpenAPI JSON.
|
|
18
|
+
*
|
|
19
|
+
* @default '/spec.json'
|
|
20
|
+
*/
|
|
21
|
+
specPath?: HTTPPath;
|
|
22
|
+
/**
|
|
23
|
+
* The URL path at which to serve the API reference UI.
|
|
24
|
+
*
|
|
25
|
+
* @default '/'
|
|
26
|
+
*/
|
|
27
|
+
docsPath?: HTTPPath;
|
|
28
|
+
/**
|
|
29
|
+
* The document title for the API reference UI.
|
|
30
|
+
*
|
|
31
|
+
* @default 'API Reference'
|
|
32
|
+
*/
|
|
33
|
+
docsTitle?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
34
|
+
/**
|
|
35
|
+
* Arbitrary configuration object for the UI.
|
|
36
|
+
*/
|
|
37
|
+
docsConfig?: Value<Promisable<Record<string, unknown>>, [StandardHandlerInterceptorOptions<T>]>;
|
|
38
|
+
/**
|
|
39
|
+
* HTML to inject into the <head> of the docs page.
|
|
40
|
+
*
|
|
41
|
+
* @default ''
|
|
42
|
+
*/
|
|
43
|
+
docsHead?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
44
|
+
/**
|
|
45
|
+
* URL of the external script bundle for the reference UI.
|
|
46
|
+
*
|
|
47
|
+
* @default 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
|
|
48
|
+
*/
|
|
49
|
+
docsScriptUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
50
|
+
/**
|
|
51
|
+
* Override function to generate the full HTML for the docs page.
|
|
52
|
+
*/
|
|
53
|
+
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec: OpenAPIV3_1.Document) => string;
|
|
54
|
+
}
|
|
55
|
+
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
56
|
+
private readonly generator;
|
|
57
|
+
private readonly specGenerateOptions;
|
|
58
|
+
private readonly specPath;
|
|
59
|
+
private readonly docsPath;
|
|
60
|
+
private readonly docsTitle;
|
|
61
|
+
private readonly docsHead;
|
|
62
|
+
private readonly docsScriptUrl;
|
|
63
|
+
private readonly docsConfig;
|
|
64
|
+
private readonly renderDocsHtml;
|
|
65
|
+
constructor(options?: OpenAPIReferencePluginOptions<T>);
|
|
66
|
+
init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { OpenAPIReferencePlugin };
|
|
70
|
+
export type { OpenAPIReferencePluginOptions };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Context, HTTPPath, Router } from '@orpc/server';
|
|
2
|
+
import { StandardHandlerInterceptorOptions, StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
3
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
4
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
5
|
+
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.CwdCLgSU.js';
|
|
6
|
+
import '@orpc/contract';
|
|
7
|
+
import '@orpc/openapi-client/standard';
|
|
8
|
+
import 'json-schema-typed/draft-2020-12';
|
|
9
|
+
|
|
10
|
+
interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGeneratorOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Options to pass to the OpenAPI generate.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
specGenerateOptions?: Value<Promisable<OpenAPIGeneratorGenerateOptions>, [StandardHandlerInterceptorOptions<T>]>;
|
|
16
|
+
/**
|
|
17
|
+
* The URL path at which to serve the OpenAPI JSON.
|
|
18
|
+
*
|
|
19
|
+
* @default '/spec.json'
|
|
20
|
+
*/
|
|
21
|
+
specPath?: HTTPPath;
|
|
22
|
+
/**
|
|
23
|
+
* The URL path at which to serve the API reference UI.
|
|
24
|
+
*
|
|
25
|
+
* @default '/'
|
|
26
|
+
*/
|
|
27
|
+
docsPath?: HTTPPath;
|
|
28
|
+
/**
|
|
29
|
+
* The document title for the API reference UI.
|
|
30
|
+
*
|
|
31
|
+
* @default 'API Reference'
|
|
32
|
+
*/
|
|
33
|
+
docsTitle?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
34
|
+
/**
|
|
35
|
+
* Arbitrary configuration object for the UI.
|
|
36
|
+
*/
|
|
37
|
+
docsConfig?: Value<Promisable<Record<string, unknown>>, [StandardHandlerInterceptorOptions<T>]>;
|
|
38
|
+
/**
|
|
39
|
+
* HTML to inject into the <head> of the docs page.
|
|
40
|
+
*
|
|
41
|
+
* @default ''
|
|
42
|
+
*/
|
|
43
|
+
docsHead?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
44
|
+
/**
|
|
45
|
+
* URL of the external script bundle for the reference UI.
|
|
46
|
+
*
|
|
47
|
+
* @default 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
|
|
48
|
+
*/
|
|
49
|
+
docsScriptUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
50
|
+
/**
|
|
51
|
+
* Override function to generate the full HTML for the docs page.
|
|
52
|
+
*/
|
|
53
|
+
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec: OpenAPIV3_1.Document) => string;
|
|
54
|
+
}
|
|
55
|
+
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
56
|
+
private readonly generator;
|
|
57
|
+
private readonly specGenerateOptions;
|
|
58
|
+
private readonly specPath;
|
|
59
|
+
private readonly docsPath;
|
|
60
|
+
private readonly docsTitle;
|
|
61
|
+
private readonly docsHead;
|
|
62
|
+
private readonly docsScriptUrl;
|
|
63
|
+
private readonly docsConfig;
|
|
64
|
+
private readonly renderDocsHtml;
|
|
65
|
+
constructor(options?: OpenAPIReferencePluginOptions<T>);
|
|
66
|
+
init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { OpenAPIReferencePlugin };
|
|
70
|
+
export type { OpenAPIReferencePluginOptions };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { stringifyJSON, once, value } from '@orpc/shared';
|
|
2
|
+
import { O as OpenAPIGenerator } from '../shared/openapi.PDTdnRIU.mjs';
|
|
3
|
+
import '@orpc/client';
|
|
4
|
+
import '@orpc/client/standard';
|
|
5
|
+
import '@orpc/contract';
|
|
6
|
+
import '@orpc/openapi-client/standard';
|
|
7
|
+
import '@orpc/server';
|
|
8
|
+
import 'json-schema-typed/draft-2020-12';
|
|
9
|
+
|
|
10
|
+
class OpenAPIReferencePlugin {
|
|
11
|
+
generator;
|
|
12
|
+
specGenerateOptions;
|
|
13
|
+
specPath;
|
|
14
|
+
docsPath;
|
|
15
|
+
docsTitle;
|
|
16
|
+
docsHead;
|
|
17
|
+
docsScriptUrl;
|
|
18
|
+
docsConfig;
|
|
19
|
+
renderDocsHtml;
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.specGenerateOptions = options.specGenerateOptions;
|
|
22
|
+
this.docsPath = options.docsPath ?? "/";
|
|
23
|
+
this.docsTitle = options.docsTitle ?? "API Reference";
|
|
24
|
+
this.docsConfig = options.docsConfig ?? void 0;
|
|
25
|
+
this.docsScriptUrl = options.docsScriptUrl ?? "https://cdn.jsdelivr.net/npm/@scalar/api-reference";
|
|
26
|
+
this.docsHead = options.docsHead ?? "";
|
|
27
|
+
this.specPath = options.specPath ?? "/spec.json";
|
|
28
|
+
this.generator = new OpenAPIGenerator(options);
|
|
29
|
+
const esc = (s) => s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
30
|
+
this.renderDocsHtml = options.renderDocsHtml ?? ((specUrl, title, head, scriptUrl, config, spec) => {
|
|
31
|
+
const finalConfig = {
|
|
32
|
+
content: stringifyJSON(spec),
|
|
33
|
+
...config
|
|
34
|
+
};
|
|
35
|
+
return `
|
|
36
|
+
<!doctype html>
|
|
37
|
+
<html>
|
|
38
|
+
<head>
|
|
39
|
+
<meta charset="utf-8" />
|
|
40
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
41
|
+
<title>${esc(title)}</title>
|
|
42
|
+
${head}
|
|
43
|
+
</head>
|
|
44
|
+
<body>
|
|
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>
|
|
53
|
+
</html>
|
|
54
|
+
`;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
init(options, router) {
|
|
58
|
+
options.interceptors ??= [];
|
|
59
|
+
options.interceptors.push(async (options2) => {
|
|
60
|
+
const res = await options2.next();
|
|
61
|
+
if (res.matched || options2.request.method !== "GET") {
|
|
62
|
+
return res;
|
|
63
|
+
}
|
|
64
|
+
const prefix = options2.prefix ?? "";
|
|
65
|
+
const requestPathname = options2.request.url.pathname.replace(/\/$/, "") || "/";
|
|
66
|
+
const docsUrl = new URL(`${prefix}${this.docsPath}`.replace(/\/$/, ""), options2.request.url.origin);
|
|
67
|
+
const specUrl = new URL(`${prefix}${this.specPath}`.replace(/\/$/, ""), options2.request.url.origin);
|
|
68
|
+
const generateSpec = once(async () => {
|
|
69
|
+
return await this.generator.generate(router, {
|
|
70
|
+
servers: [{ url: new URL(prefix, options2.request.url.origin).toString() }],
|
|
71
|
+
...await value(this.specGenerateOptions, options2)
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
if (requestPathname === specUrl.pathname) {
|
|
75
|
+
const spec = await generateSpec();
|
|
76
|
+
return {
|
|
77
|
+
matched: true,
|
|
78
|
+
response: {
|
|
79
|
+
status: 200,
|
|
80
|
+
headers: {},
|
|
81
|
+
body: new File([stringifyJSON(spec)], "spec.json", { type: "application/json" })
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (requestPathname === docsUrl.pathname) {
|
|
86
|
+
const html = this.renderDocsHtml(
|
|
87
|
+
specUrl.toString(),
|
|
88
|
+
await value(this.docsTitle, options2),
|
|
89
|
+
await value(this.docsHead, options2),
|
|
90
|
+
await value(this.docsScriptUrl, options2),
|
|
91
|
+
await value(this.docsConfig, options2),
|
|
92
|
+
await generateSpec()
|
|
93
|
+
);
|
|
94
|
+
return {
|
|
95
|
+
matched: true,
|
|
96
|
+
response: {
|
|
97
|
+
status: 200,
|
|
98
|
+
headers: {},
|
|
99
|
+
body: new File([html], "api-reference.html", { type: "text/html" })
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return res;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { OpenAPIReferencePlugin };
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
+
import { isORPCErrorStatus } from '@orpc/client';
|
|
1
4
|
import { fallbackContractConfig } from '@orpc/contract';
|
|
2
|
-
import { isObject } from '@orpc/shared';
|
|
3
|
-
import {
|
|
5
|
+
import { isObject, stringifyJSON } from '@orpc/shared';
|
|
6
|
+
import { toHttpPath } from '@orpc/client/standard';
|
|
7
|
+
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
|
4
8
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
5
|
-
import { s as standardizeHTTPPath } from './openapi.BHG_gu5Z.mjs';
|
|
6
9
|
|
|
7
|
-
class
|
|
10
|
+
class StandardOpenAPICodec {
|
|
8
11
|
constructor(serializer) {
|
|
9
12
|
this.serializer = serializer;
|
|
10
13
|
}
|
|
@@ -50,13 +53,21 @@ class OpenAPICodec {
|
|
|
50
53
|
body: this.serializer.serialize(output)
|
|
51
54
|
};
|
|
52
55
|
}
|
|
53
|
-
if (!
|
|
54
|
-
throw new Error(
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
if (!this.#isDetailedOutput(output)) {
|
|
57
|
+
throw new Error(`
|
|
58
|
+
Invalid "detailed" output structure:
|
|
59
|
+
\u2022 Expected an object with optional properties:
|
|
60
|
+
- status (number 200-399)
|
|
61
|
+
- headers (Record<string, string | string[]>)
|
|
62
|
+
- body (any)
|
|
63
|
+
\u2022 No extra keys allowed.
|
|
64
|
+
|
|
65
|
+
Actual value:
|
|
66
|
+
${stringifyJSON(output)}
|
|
67
|
+
`);
|
|
57
68
|
}
|
|
58
69
|
return {
|
|
59
|
-
status: successStatus,
|
|
70
|
+
status: output.status ?? successStatus,
|
|
60
71
|
headers: output.headers ?? {},
|
|
61
72
|
body: this.serializer.serialize(output.body)
|
|
62
73
|
};
|
|
@@ -65,21 +76,37 @@ class OpenAPICodec {
|
|
|
65
76
|
return {
|
|
66
77
|
status: error.status,
|
|
67
78
|
headers: {},
|
|
68
|
-
body: this.serializer.serialize(error.toJSON())
|
|
79
|
+
body: this.serializer.serialize(error.toJSON(), { outputFormat: "plain" })
|
|
69
80
|
};
|
|
70
81
|
}
|
|
82
|
+
#isDetailedOutput(output) {
|
|
83
|
+
if (!isObject(output)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (output.headers && !isObject(output.headers)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
71
94
|
}
|
|
72
95
|
|
|
73
|
-
|
|
96
|
+
function toRou3Pattern(path) {
|
|
97
|
+
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
|
98
|
+
}
|
|
99
|
+
function decodeParams(params) {
|
|
100
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class StandardOpenAPIMatcher {
|
|
74
104
|
tree = createRouter();
|
|
75
105
|
pendingRouters = [];
|
|
76
106
|
init(router, path = []) {
|
|
77
|
-
const laziedOptions =
|
|
78
|
-
router,
|
|
79
|
-
path
|
|
80
|
-
}, ({ path: path2, contract }) => {
|
|
107
|
+
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
|
81
108
|
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
|
82
|
-
const httpPath =
|
|
109
|
+
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
|
83
110
|
if (isProcedure(contract)) {
|
|
84
111
|
addRoute(this.tree, method, httpPath, {
|
|
85
112
|
path: path2,
|
|
@@ -99,8 +126,8 @@ class OpenAPIMatcher {
|
|
|
99
126
|
});
|
|
100
127
|
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
|
101
128
|
...option,
|
|
102
|
-
httpPathPrefix:
|
|
103
|
-
laziedPrefix:
|
|
129
|
+
httpPathPrefix: toHttpPath(option.path),
|
|
130
|
+
laziedPrefix: getLazyMeta(option.router).prefix
|
|
104
131
|
})));
|
|
105
132
|
}
|
|
106
133
|
async match(method, pathname) {
|
|
@@ -108,7 +135,7 @@ class OpenAPIMatcher {
|
|
|
108
135
|
const newPendingRouters = [];
|
|
109
136
|
for (const pendingRouter of this.pendingRouters) {
|
|
110
137
|
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
|
111
|
-
const { default: router } = await unlazy(pendingRouter.
|
|
138
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
|
112
139
|
this.init(router, pendingRouter.path);
|
|
113
140
|
} else {
|
|
114
141
|
newPendingRouters.push(pendingRouter);
|
|
@@ -121,14 +148,14 @@ class OpenAPIMatcher {
|
|
|
121
148
|
return void 0;
|
|
122
149
|
}
|
|
123
150
|
if (!match.data.procedure) {
|
|
124
|
-
const { default: maybeProcedure } = await unlazy(
|
|
151
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
|
|
125
152
|
if (!isProcedure(maybeProcedure)) {
|
|
126
153
|
throw new Error(`
|
|
127
|
-
[Contract-First] Missing or invalid implementation for procedure at path: ${
|
|
154
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
|
|
128
155
|
Ensure that the procedure is correctly defined and matches the expected contract.
|
|
129
156
|
`);
|
|
130
157
|
}
|
|
131
|
-
match.data.procedure = createContractedProcedure(match.data.contract
|
|
158
|
+
match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
|
|
132
159
|
}
|
|
133
160
|
return {
|
|
134
161
|
path: match.data.path,
|
|
@@ -137,11 +164,16 @@ class OpenAPIMatcher {
|
|
|
137
164
|
};
|
|
138
165
|
}
|
|
139
166
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
167
|
+
|
|
168
|
+
class StandardOpenAPIHandler extends StandardHandler {
|
|
169
|
+
constructor(router, options) {
|
|
170
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
171
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
|
172
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
173
|
+
const matcher = new StandardOpenAPIMatcher();
|
|
174
|
+
const codec = new StandardOpenAPICodec(serializer);
|
|
175
|
+
super(router, matcher, codec, options);
|
|
176
|
+
}
|
|
145
177
|
}
|
|
146
178
|
|
|
147
|
-
export {
|
|
179
|
+
export { StandardOpenAPICodec as S, StandardOpenAPIHandler as a, StandardOpenAPIMatcher as b, decodeParams as d, toRou3Pattern as t };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AnySchema, AnyContractProcedure, AnyContractRouter } from '@orpc/contract';
|
|
2
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
3
|
+
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
|
4
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
5
|
+
import { Promisable } from '@orpc/shared';
|
|
6
|
+
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
7
|
+
|
|
8
|
+
interface SchemaConvertOptions {
|
|
9
|
+
strategy: 'input' | 'output';
|
|
10
|
+
}
|
|
11
|
+
interface SchemaConverter {
|
|
12
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
13
|
+
}
|
|
14
|
+
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
15
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
16
|
+
}
|
|
17
|
+
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
18
|
+
private readonly converters;
|
|
19
|
+
constructor(converters: ConditionalSchemaConverter[]);
|
|
20
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
|
24
|
+
schemaConverters?: ConditionalSchemaConverter[];
|
|
25
|
+
}
|
|
26
|
+
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPIV3_1.Document, 'openapi'>> {
|
|
27
|
+
/**
|
|
28
|
+
* Exclude procedures from the OpenAPI specification.
|
|
29
|
+
*
|
|
30
|
+
* @default () => false
|
|
31
|
+
*/
|
|
32
|
+
exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
38
|
+
*/
|
|
39
|
+
declare class OpenAPIGenerator {
|
|
40
|
+
#private;
|
|
41
|
+
private readonly serializer;
|
|
42
|
+
private readonly converter;
|
|
43
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
|
44
|
+
/**
|
|
45
|
+
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
46
|
+
*
|
|
47
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
48
|
+
*/
|
|
49
|
+
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPIV3_1.Document>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { OpenAPIGenerator as b, CompositeSchemaConverter as d };
|
|
53
|
+
export type { ConditionalSchemaConverter as C, OpenAPIGeneratorOptions as O, SchemaConvertOptions as S, OpenAPIGeneratorGenerateOptions as a, SchemaConverter as c };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AnySchema, AnyContractProcedure, AnyContractRouter } from '@orpc/contract';
|
|
2
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
3
|
+
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
|
4
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
5
|
+
import { Promisable } from '@orpc/shared';
|
|
6
|
+
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
7
|
+
|
|
8
|
+
interface SchemaConvertOptions {
|
|
9
|
+
strategy: 'input' | 'output';
|
|
10
|
+
}
|
|
11
|
+
interface SchemaConverter {
|
|
12
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
13
|
+
}
|
|
14
|
+
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
15
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
16
|
+
}
|
|
17
|
+
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
18
|
+
private readonly converters;
|
|
19
|
+
constructor(converters: ConditionalSchemaConverter[]);
|
|
20
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
|
24
|
+
schemaConverters?: ConditionalSchemaConverter[];
|
|
25
|
+
}
|
|
26
|
+
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPIV3_1.Document, 'openapi'>> {
|
|
27
|
+
/**
|
|
28
|
+
* Exclude procedures from the OpenAPI specification.
|
|
29
|
+
*
|
|
30
|
+
* @default () => false
|
|
31
|
+
*/
|
|
32
|
+
exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
38
|
+
*/
|
|
39
|
+
declare class OpenAPIGenerator {
|
|
40
|
+
#private;
|
|
41
|
+
private readonly serializer;
|
|
42
|
+
private readonly converter;
|
|
43
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
|
44
|
+
/**
|
|
45
|
+
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
46
|
+
*
|
|
47
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
48
|
+
*/
|
|
49
|
+
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPIV3_1.Document>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { OpenAPIGenerator as b, CompositeSchemaConverter as d };
|
|
53
|
+
export type { ConditionalSchemaConverter as C, OpenAPIGeneratorOptions as O, SchemaConvertOptions as S, OpenAPIGeneratorGenerateOptions as a, SchemaConverter as c };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { Context, Router } from '@orpc/server';
|
|
3
|
+
import { StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
|
|
4
|
+
|
|
5
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
|
6
|
+
}
|
|
7
|
+
declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
|
|
8
|
+
constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { StandardOpenAPIHandler as a };
|
|
12
|
+
export type { StandardOpenAPIHandlerOptions as S };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { Context, Router } from '@orpc/server';
|
|
3
|
+
import { StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
|
|
4
|
+
|
|
5
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
|
6
|
+
}
|
|
7
|
+
declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
|
|
8
|
+
constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { StandardOpenAPIHandler as a };
|
|
12
|
+
export type { StandardOpenAPIHandlerOptions as S };
|