@orpc/openapi 2.0.0-beta.48 → 2.0.0-beta.49
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 +4 -4
- package/dist/adapters/aws-lambda/index.d.ts +15 -0
- package/dist/adapters/aws-lambda/index.js +1 -0
- package/dist/adapters/aws-lambda/openapi-handler.d.ts +18 -0
- package/dist/adapters/aws-lambda/openapi-handler.js +18 -0
- package/dist/adapters/fastify/index.d.ts +1 -0
- package/dist/adapters/fastify/index.js +1 -0
- package/dist/adapters/fastify/openapi-handler.d.ts +15 -0
- package/dist/adapters/fastify/openapi-handler.js +15 -0
- package/dist/adapters/fetch/index.d.ts +2 -0
- package/dist/adapters/fetch/index.js +2 -0
- package/dist/adapters/fetch/openapi-handler.d.ts +15 -0
- package/dist/adapters/fetch/openapi-handler.js +15 -0
- package/dist/adapters/fetch/openapi-link.d.ts +21 -0
- package/dist/adapters/fetch/openapi-link.js +20 -0
- package/dist/adapters/node/index.d.ts +1 -0
- package/dist/adapters/node/index.js +1 -0
- package/dist/adapters/node/openapi-handler.d.ts +15 -0
- package/dist/adapters/node/openapi-handler.js +15 -0
- package/dist/adapters/standard/index.d.ts +3 -0
- package/dist/adapters/standard/index.js +3 -0
- package/dist/adapters/standard/openapi-handler-codec.d.ts +62 -0
- package/dist/adapters/standard/openapi-handler-codec.js +220 -0
- package/dist/adapters/standard/openapi-link-codec.d.ts +62 -0
- package/dist/adapters/standard/openapi-link-codec.js +405 -0
- package/dist/adapters/standard/openapi-matcher.d.ts +29 -0
- package/dist/adapters/standard/openapi-matcher.js +108 -0
- package/dist/adapters/standard/utils.d.ts +4 -0
- package/dist/adapters/standard/utils.js +47 -0
- package/dist/bracket-notation.d.ts +26 -0
- package/dist/bracket-notation.js +185 -0
- package/dist/client-factory.d.ts +24 -0
- package/dist/client-factory.js +13 -0
- package/dist/constants.js +4 -0
- package/dist/extensions/route.d.ts +37 -0
- package/dist/extensions/route.js +12 -0
- package/dist/helpers/form-data.d.ts +57 -0
- package/dist/helpers/form-data.js +90 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +11 -0
- package/dist/meta.d.ts +325 -0
- package/dist/meta.js +84 -0
- package/dist/openapi-generator-components.d.ts +31 -0
- package/dist/openapi-generator-components.js +275 -0
- package/dist/openapi-generator-operation.d.ts +34 -0
- package/dist/openapi-generator-operation.js +469 -0
- package/dist/openapi-generator.d.ts +92 -0
- package/dist/openapi-generator.js +147 -0
- package/dist/openapi-json-serializer.d.ts +79 -0
- package/dist/openapi-json-serializer.js +260 -0
- package/dist/openapi-serializer.d.ts +43 -0
- package/dist/openapi-serializer.js +93 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/openapi-reference.d.ts +115 -0
- package/dist/plugins/openapi-reference.js +187 -0
- package/dist/router-utils.d.ts +20 -0
- package/dist/router-utils.js +36 -0
- package/dist/{types.d.mts → types.d.ts} +23 -19
- package/dist/utils.d.ts +14 -0
- package/dist/utils.js +47 -0
- package/package.json +69 -71
- package/dist/adapters/aws-lambda/index.d.mts +0 -15
- package/dist/adapters/aws-lambda/index.mjs +0 -1
- package/dist/adapters/aws-lambda/openapi-handler.d.mts +0 -17
- package/dist/adapters/aws-lambda/openapi-handler.mjs +0 -11
- package/dist/adapters/fastify/index.d.mts +0 -1
- package/dist/adapters/fastify/index.mjs +0 -1
- package/dist/adapters/fastify/openapi-handler.d.mts +0 -14
- package/dist/adapters/fastify/openapi-handler.mjs +0 -11
- package/dist/adapters/fetch/index.d.mts +0 -2
- package/dist/adapters/fetch/index.mjs +0 -2
- package/dist/adapters/fetch/openapi-handler.d.mts +0 -14
- package/dist/adapters/fetch/openapi-handler.mjs +0 -11
- package/dist/adapters/fetch/openapi-link.d.mts +0 -15
- package/dist/adapters/fetch/openapi-link.mjs +0 -11
- package/dist/adapters/node/index.d.mts +0 -1
- package/dist/adapters/node/index.mjs +0 -1
- package/dist/adapters/node/openapi-handler.d.mts +0 -14
- package/dist/adapters/node/openapi-handler.mjs +0 -11
- package/dist/adapters/standard/index.d.mts +0 -3
- package/dist/adapters/standard/index.mjs +0 -3
- package/dist/adapters/standard/openapi-handler-codec.d.mts +0 -61
- package/dist/adapters/standard/openapi-handler-codec.mjs +0 -203
- package/dist/adapters/standard/openapi-link-codec.d.mts +0 -53
- package/dist/adapters/standard/openapi-link-codec.mjs +0 -356
- package/dist/adapters/standard/openapi-matcher.d.mts +0 -29
- package/dist/adapters/standard/openapi-matcher.mjs +0 -105
- package/dist/adapters/standard/utils.d.mts +0 -4
- package/dist/adapters/standard/utils.mjs +0 -36
- package/dist/bracket-notation.d.mts +0 -26
- package/dist/bracket-notation.mjs +0 -156
- package/dist/client-factory.d.mts +0 -24
- package/dist/client-factory.mjs +0 -5
- package/dist/constants.mjs +0 -4
- package/dist/extensions/route.d.mts +0 -76
- package/dist/extensions/route.mjs +0 -12
- package/dist/helpers/form-data.d.mts +0 -57
- package/dist/helpers/form-data.mjs +0 -36
- package/dist/helpers/index.d.mts +0 -1
- package/dist/helpers/index.mjs +0 -1
- package/dist/index.d.mts +0 -13
- package/dist/index.mjs +0 -11
- package/dist/meta.d.mts +0 -345
- package/dist/meta.mjs +0 -56
- package/dist/openapi-generator-components.d.mts +0 -24
- package/dist/openapi-generator-components.mjs +0 -227
- package/dist/openapi-generator-operation.d.mts +0 -29
- package/dist/openapi-generator-operation.mjs +0 -447
- package/dist/openapi-generator.d.mts +0 -87
- package/dist/openapi-generator.mjs +0 -115
- package/dist/openapi-json-serializer.d.mts +0 -86
- package/dist/openapi-json-serializer.mjs +0 -229
- package/dist/openapi-serializer.d.mts +0 -43
- package/dist/openapi-serializer.mjs +0 -87
- package/dist/plugins/index.d.mts +0 -1
- package/dist/plugins/index.mjs +0 -1
- package/dist/plugins/openapi-reference.d.mts +0 -118
- package/dist/plugins/openapi-reference.mjs +0 -157
- package/dist/router-utils.d.mts +0 -18
- package/dist/router-utils.mjs +0 -29
- package/dist/utils.d.mts +0 -14
- package/dist/utils.mjs +0 -40
- /package/dist/{constants.d.mts → constants.d.ts} +0 -0
- /package/dist/{types.mjs → types.js} +0 -0
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { getTracer, matchesHttpPath, mergeHttpPath, stringifyJSON, toArray, value } from "@orpc/shared";
|
|
2
|
-
|
|
3
|
-
export class OpenAPIReferenceHandlerPlugin {
|
|
4
|
-
name = "~openapi-reference";
|
|
5
|
-
spec;
|
|
6
|
-
allow;
|
|
7
|
-
specPath;
|
|
8
|
-
provider;
|
|
9
|
-
providerConfig;
|
|
10
|
-
providerScriptUrl;
|
|
11
|
-
providerCssUrl;
|
|
12
|
-
docsPath;
|
|
13
|
-
docsTitle;
|
|
14
|
-
docsHead;
|
|
15
|
-
constructor(options) {
|
|
16
|
-
this.spec = options.spec;
|
|
17
|
-
this.allow = options.allow;
|
|
18
|
-
this.specPath = options.specPath ?? "/spec.json";
|
|
19
|
-
this.provider = options.provider ?? "scalar";
|
|
20
|
-
this.providerConfig = options.providerConfig;
|
|
21
|
-
this.providerScriptUrl = options.providerScriptUrl;
|
|
22
|
-
this.providerCssUrl = options.providerCssUrl;
|
|
23
|
-
this.docsTitle = options.docsTitle;
|
|
24
|
-
this.docsPath = options.docsPath ?? "/";
|
|
25
|
-
this.docsHead = options.docsHead ?? "";
|
|
26
|
-
}
|
|
27
|
-
init(options) {
|
|
28
|
-
return {
|
|
29
|
-
...options,
|
|
30
|
-
routingInterceptors: [...toArray(options.routingInterceptors), async ({ next, ...routingInterceptorOptions }) => {
|
|
31
|
-
const result = await next();
|
|
32
|
-
if (result.matched || routingInterceptorOptions.request.method !== "GET") {
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
const isSpecPath = matchesHttpPath(routingInterceptorOptions.request.url, routingInterceptorOptions.prefix ? mergeHttpPath(routingInterceptorOptions.prefix, this.specPath) : this.specPath);
|
|
36
|
-
const isDocsPath = matchesHttpPath(routingInterceptorOptions.request.url, routingInterceptorOptions.prefix ? mergeHttpPath(routingInterceptorOptions.prefix, this.docsPath) : this.docsPath);
|
|
37
|
-
if (!isSpecPath && !isDocsPath) {
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
if (await value(this.allow, routingInterceptorOptions) === false) {
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
const span = getTracer()?.getActiveSpan();
|
|
44
|
-
const spec = await value(this.spec, routingInterceptorOptions);
|
|
45
|
-
if (isSpecPath) {
|
|
46
|
-
span?.updateName(`${routingInterceptorOptions.request.method} ${routingInterceptorOptions.request.url} (openapi spec)`);
|
|
47
|
-
const specFile = new File([stringifyJSON(spec)], `${spec.info.title}.json`, { type: "application/json" });
|
|
48
|
-
return {
|
|
49
|
-
matched: true,
|
|
50
|
-
response: {
|
|
51
|
-
status: 200,
|
|
52
|
-
headers: {},
|
|
53
|
-
body: specFile
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
span?.updateName(`${routingInterceptorOptions.request.method} ${routingInterceptorOptions.request.url} (${this.provider} ui)`);
|
|
58
|
-
const docsTitle = await value(this.docsTitle, routingInterceptorOptions) ?? spec.info.title;
|
|
59
|
-
const docsHead = await value(this.docsHead, routingInterceptorOptions);
|
|
60
|
-
let html;
|
|
61
|
-
if (this.provider === "swagger") {
|
|
62
|
-
const scriptUrl = this.providerScriptUrl ?? "https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js";
|
|
63
|
-
const cssUrl = this.providerCssUrl ?? "https://unpkg.com/swagger-ui-dist/swagger-ui.css";
|
|
64
|
-
const config = {
|
|
65
|
-
dom_id: "#app",
|
|
66
|
-
spec,
|
|
67
|
-
deepLinking: true,
|
|
68
|
-
presets: ["SwaggerUIBundle.presets.apis"],
|
|
69
|
-
plugins: ["SwaggerUIBundle.plugins.DownloadUrl"],
|
|
70
|
-
...this.providerConfig
|
|
71
|
-
};
|
|
72
|
-
html = `
|
|
73
|
-
<!doctype html>
|
|
74
|
-
<html>
|
|
75
|
-
<head>
|
|
76
|
-
<meta charset="utf-8" />
|
|
77
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
78
|
-
<title>${escapeHtmlEntities(docsTitle)}</title>
|
|
79
|
-
<link rel="stylesheet" type="text/css" href="${escapeHtmlEntities(cssUrl)}" />
|
|
80
|
-
${docsHead}
|
|
81
|
-
</head>
|
|
82
|
-
<body>
|
|
83
|
-
<div id="app"></div>
|
|
84
|
-
|
|
85
|
-
<script src="${escapeHtmlEntities(scriptUrl)}"><\/script>
|
|
86
|
-
|
|
87
|
-
<!-- IMPORTANT: assign to a variable first to prevent ), ( in values breaking the call expression. -->
|
|
88
|
-
<!-- IMPORTANT: escapeJsonForHtml ensures <, > cannot terminate the <\/script> tag prematurely. -->
|
|
89
|
-
<!-- IMPORTANT: resolve presets/plugins global paths at runtime, never unquote them in the JSON, which also holds the spec. -->
|
|
90
|
-
<script>
|
|
91
|
-
const swaggerConfig = ${escapeJsonForHtml(config)}
|
|
92
|
-
|
|
93
|
-
window.onload = () => {
|
|
94
|
-
for (const key of ['presets', 'plugins']) {
|
|
95
|
-
swaggerConfig[key] &&= swaggerConfig[key].map(path => path.split('.').reduce((value, name) => value?.[name], window))
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
window.ui = SwaggerUIBundle(swaggerConfig)
|
|
99
|
-
}
|
|
100
|
-
<\/script>
|
|
101
|
-
</body>
|
|
102
|
-
</html>
|
|
103
|
-
`;
|
|
104
|
-
} else {
|
|
105
|
-
const scriptUrl = this.providerScriptUrl ?? "https://cdn.jsdelivr.net/npm/@scalar/api-reference";
|
|
106
|
-
const cssUrl = this.providerCssUrl;
|
|
107
|
-
const config = {
|
|
108
|
-
content: stringifyJSON(spec),
|
|
109
|
-
...this.providerConfig
|
|
110
|
-
};
|
|
111
|
-
html = `
|
|
112
|
-
<!doctype html>
|
|
113
|
-
<html>
|
|
114
|
-
<head>
|
|
115
|
-
<meta charset="utf-8" />
|
|
116
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
117
|
-
<title>${escapeHtmlEntities(docsTitle)}</title>
|
|
118
|
-
${cssUrl ? `<link rel="stylesheet" type="text/css" href="${escapeHtmlEntities(cssUrl)}" />` : ""}
|
|
119
|
-
${docsHead}
|
|
120
|
-
</head>
|
|
121
|
-
<body>
|
|
122
|
-
<div id="app"></div>
|
|
123
|
-
|
|
124
|
-
<script src="${escapeHtmlEntities(scriptUrl)}"><\/script>
|
|
125
|
-
|
|
126
|
-
<!-- IMPORTANT: assign to a variable first to prevent ), ( in values breaking the call expression. -->
|
|
127
|
-
<!-- IMPORTANT: escapeJsonForHtml ensures <, > cannot terminate the <\/script> tag prematurely. -->
|
|
128
|
-
<script>
|
|
129
|
-
const scalarConfig = ${escapeJsonForHtml(config)}
|
|
130
|
-
|
|
131
|
-
Scalar.createApiReference('#app', scalarConfig)
|
|
132
|
-
<\/script>
|
|
133
|
-
</body>
|
|
134
|
-
</html>
|
|
135
|
-
`;
|
|
136
|
-
}
|
|
137
|
-
const htmlBlob = new Blob([html], { type: "text/html" });
|
|
138
|
-
return {
|
|
139
|
-
matched: true,
|
|
140
|
-
response: {
|
|
141
|
-
status: 200,
|
|
142
|
-
headers: { "content-disposition": [] },
|
|
143
|
-
body: htmlBlob
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
}]
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function escapeHtmlEntities(s) {
|
|
152
|
-
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function escapeJsonForHtml(obj) {
|
|
156
|
-
return stringifyJSON(obj).replace(/&/g, "\\u0026").replace(/'/g, "\\u0027").replace(/</g, "\\u003C").replace(/>/g, "\\u003E").replace(/\//g, "\\u002F");
|
|
157
|
-
}
|
package/dist/router-utils.d.mts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { RouterContract } from "@orpc/contract";
|
|
2
|
-
import { ProcedureContract } from "@orpc/contract";
|
|
3
|
-
export type PopulatedContractRouterOpenAPIPaths<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : { [K in keyof T]: T[K] extends RouterContract ? PopulatedContractRouterOpenAPIPaths<T[K]> : never };
|
|
4
|
-
export interface PopulateRouterContractOpenAPIPathsOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Base path segments.
|
|
7
|
-
*/
|
|
8
|
-
path?: string[] | undefined;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Automatically populates missing openapi.path using router structure.
|
|
12
|
-
*
|
|
13
|
-
* Builds paths by joining router keys with `/`.
|
|
14
|
-
* Useful when you want to ensure all contracts define openapi.path, such as for NestJS integration requirements.
|
|
15
|
-
*
|
|
16
|
-
* @see {@link https://orpc.dev/docs/integrations/nest | Implement oRPC contract with NestJS}
|
|
17
|
-
*/
|
|
18
|
-
export declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedContractRouterOpenAPIPaths<T>;
|
package/dist/router-utils.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ProcedureContract, resolveMetaPlugins } from "@orpc/contract";
|
|
2
|
-
import { isTypescriptObject, pathToHttpPath, toArray } from "@orpc/shared";
|
|
3
|
-
import { getOpenAPIMeta, openapi } from "./meta.mjs";
|
|
4
|
-
|
|
5
|
-
export function populateRouterContractOpenAPIPaths(router, options = {}) {
|
|
6
|
-
const path = toArray(options.path);
|
|
7
|
-
if (router instanceof ProcedureContract) {
|
|
8
|
-
if (getOpenAPIMeta(router)?.path !== undefined) {
|
|
9
|
-
return router;
|
|
10
|
-
}
|
|
11
|
-
const [meta, metaPlugins] = resolveMetaPlugins(router["~orpc"].meta, router["~orpc"].metaPlugins, [openapi({ path: pathToHttpPath(path) })]);
|
|
12
|
-
return new ProcedureContract({
|
|
13
|
-
...router["~orpc"],
|
|
14
|
-
meta,
|
|
15
|
-
metaPlugins
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
if (!isTypescriptObject(router)) {
|
|
19
|
-
return router;
|
|
20
|
-
}
|
|
21
|
-
const populated = {};
|
|
22
|
-
for (const key of Object.keys(router)) {
|
|
23
|
-
populated[key] = populateRouterContractOpenAPIPaths(router[key], {
|
|
24
|
-
...options,
|
|
25
|
-
path: [...path, key]
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return populated;
|
|
29
|
-
}
|
package/dist/utils.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GET and HEAD requests cannot carry a request body,
|
|
3
|
-
* so their compact input maps to query parameters instead.
|
|
4
|
-
*/
|
|
5
|
-
export declare function isBodylessMethod(method: string): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Dynamic parameters are always returned in path order.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getDynamicPathParams(path: `/${string}`): {
|
|
10
|
-
segment: string;
|
|
11
|
-
startIndex: number;
|
|
12
|
-
parameterName: string;
|
|
13
|
-
allowsSlash: boolean;
|
|
14
|
-
}[] | undefined;
|
package/dist/utils.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export function isBodylessMethod(method) {
|
|
3
|
-
return method === "GET" || method === "HEAD";
|
|
4
|
-
}
|
|
5
|
-
const PARAMETER_NAME_REGEX = /^[\w-]+$/;
|
|
6
|
-
|
|
7
|
-
export function getDynamicPathParams(path) {
|
|
8
|
-
if (!path.includes("{")) {
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
const len = path.length;
|
|
12
|
-
let params;
|
|
13
|
-
let index = 1;
|
|
14
|
-
while (index < len) {
|
|
15
|
-
const segmentStart = index;
|
|
16
|
-
const slashPos = path.indexOf("/", index);
|
|
17
|
-
const segmentEnd = slashPos === -1 ? len : slashPos;
|
|
18
|
-
if (segmentEnd > segmentStart && path.charCodeAt(segmentStart) === 123 && path.charCodeAt(segmentEnd - 1) === 125) {
|
|
19
|
-
let parameterStart = segmentStart + 1;
|
|
20
|
-
let allowsSlash = false;
|
|
21
|
-
const operator = path.charCodeAt(parameterStart);
|
|
22
|
-
if (operator === 43) {
|
|
23
|
-
allowsSlash = true;
|
|
24
|
-
parameterStart++;
|
|
25
|
-
}
|
|
26
|
-
const parameterName = path.slice(parameterStart, segmentEnd - 1);
|
|
27
|
-
if (PARAMETER_NAME_REGEX.test(parameterName)) {
|
|
28
|
-
params ??= [];
|
|
29
|
-
params.push({
|
|
30
|
-
segment: path.slice(segmentStart, segmentEnd),
|
|
31
|
-
startIndex: segmentStart,
|
|
32
|
-
parameterName,
|
|
33
|
-
allowsSlash
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
index = segmentEnd + 1;
|
|
38
|
-
}
|
|
39
|
-
return params;
|
|
40
|
-
}
|
|
File without changes
|
|
File without changes
|