@orpc/openapi 1.14.11 → 1.14.12
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 +71 -52
- package/dist/adapters/aws-lambda/index.d.mts +20 -0
- package/dist/adapters/aws-lambda/index.d.ts +20 -0
- package/dist/adapters/aws-lambda/index.mjs +18 -0
- package/dist/adapters/fastify/index.d.mts +23 -0
- package/dist/adapters/fastify/index.d.ts +23 -0
- package/dist/adapters/fastify/index.mjs +18 -0
- package/dist/adapters/fetch/index.d.mts +16 -20
- package/dist/adapters/fetch/index.d.ts +16 -20
- package/dist/adapters/fetch/index.mjs +8 -24
- package/dist/adapters/node/index.d.mts +13 -8
- package/dist/adapters/node/index.d.ts +13 -8
- package/dist/adapters/node/index.mjs +7 -10
- package/dist/adapters/standard/index.d.mts +16 -46
- package/dist/adapters/standard/index.d.ts +16 -46
- package/dist/adapters/standard/index.mjs +6 -9
- package/dist/index.d.mts +105 -117
- package/dist/index.d.ts +105 -117
- package/dist/index.mjs +32 -850
- package/dist/plugins/index.d.mts +51 -55
- package/dist/plugins/index.d.ts +51 -55
- package/dist/plugins/index.mjs +142 -147
- package/dist/shared/openapi.BGy4N6eR.d.mts +120 -0
- package/dist/shared/openapi.BGy4N6eR.d.ts +120 -0
- package/dist/shared/openapi.BwdtJjDu.mjs +878 -0
- package/dist/shared/openapi.CdeSk3f7.d.mts +54 -0
- package/dist/shared/openapi.CdeSk3f7.d.ts +54 -0
- package/dist/shared/openapi.DPiCV5hl.mjs +208 -0
- package/package.json +24 -46
- package/dist/extensions/route.d.mts +0 -43
- package/dist/extensions/route.d.ts +0 -43
- package/dist/extensions/route.mjs +0 -14
- package/dist/helpers/index.d.mts +0 -51
- package/dist/helpers/index.d.ts +0 -51
- package/dist/helpers/index.mjs +0 -39
- package/dist/shared/openapi.B6hEbRyF.d.ts +0 -83
- package/dist/shared/openapi.B9PQzqBn.mjs +0 -49
- package/dist/shared/openapi.BOOA-bde.d.mts +0 -142
- package/dist/shared/openapi.BOOA-bde.d.ts +0 -142
- package/dist/shared/openapi.BafbB3uM.d.mts +0 -83
- package/dist/shared/openapi.Bt87OzTt.mjs +0 -131
- package/dist/shared/openapi.ByT4oUeY.d.mts +0 -18
- package/dist/shared/openapi.ByT4oUeY.d.ts +0 -18
- package/dist/shared/openapi.C-p_Q2lb.mjs +0 -359
- package/dist/shared/openapi.CVgUshDP.mjs +0 -318
- package/dist/shared/openapi.DNNo0V-l.d.ts +0 -313
- package/dist/shared/openapi.hg_rhZ4x.d.mts +0 -313
- package/dist/shared/openapi.zZH_UksW.mjs +0 -278
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,90 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { OpenAPI } from '@orpc/contract';
|
|
2
|
+
import { Context, HTTPPath, Router } from '@orpc/server';
|
|
3
|
+
import { StandardHandlerInterceptorOptions, StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
3
4
|
import { Value, Promisable } from '@orpc/shared';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { a as OpenAPIDocument } from '../shared/openapi.ByT4oUeY.mjs';
|
|
8
|
-
import '@hey-api/spec-types';
|
|
9
|
-
import '@orpc/client';
|
|
5
|
+
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.BGy4N6eR.mjs';
|
|
6
|
+
import '@orpc/openapi-client/standard';
|
|
7
|
+
import 'json-schema-typed/draft-2020-12';
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
interface OpenAPIReferenceHandlerPluginScalarConfig extends Partial<ApiReferenceConfiguration> {
|
|
13
|
-
}
|
|
14
|
-
interface OpenAPIReferenceHandlerPluginSwaggerConfig extends Partial<Omit<SwaggerUIOptions, 'dom_id' | 'presets' | 'plugins'>> {
|
|
15
|
-
dom_id?: undefined | never;
|
|
16
|
-
presets?: undefined | `SwaggerUIBundle.${string}`[];
|
|
17
|
-
plugins?: undefined | `SwaggerUIBundle.${string}`[];
|
|
18
|
-
}
|
|
19
|
-
interface OpenAPIReferenceHandlerPluginOptions<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> {
|
|
9
|
+
interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGeneratorOptions {
|
|
20
10
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
11
|
+
* Options to pass to the OpenAPI generate.
|
|
12
|
+
*
|
|
23
13
|
*/
|
|
24
|
-
|
|
14
|
+
specGenerateOptions?: Value<Promisable<OpenAPIGeneratorGenerateOptions>, [StandardHandlerInterceptorOptions<T>]>;
|
|
25
15
|
/**
|
|
26
16
|
* The URL path at which to serve the OpenAPI JSON.
|
|
27
17
|
*
|
|
28
18
|
* @default '/spec.json'
|
|
29
19
|
*/
|
|
30
|
-
specPath?:
|
|
20
|
+
specPath?: HTTPPath;
|
|
31
21
|
/**
|
|
32
|
-
* The
|
|
22
|
+
* The URL path at which to serve the API reference UI.
|
|
33
23
|
*
|
|
34
|
-
* @default '
|
|
24
|
+
* @default '/'
|
|
35
25
|
*/
|
|
36
|
-
|
|
26
|
+
docsPath?: HTTPPath;
|
|
37
27
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
28
|
+
* The document title for the API reference UI.
|
|
29
|
+
*
|
|
30
|
+
* @default 'API Reference'
|
|
40
31
|
*/
|
|
41
|
-
|
|
32
|
+
docsTitle?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
42
33
|
/**
|
|
43
|
-
*
|
|
34
|
+
* The UI library to use for rendering the API reference.
|
|
44
35
|
*
|
|
45
|
-
* @default '
|
|
36
|
+
* @default 'scalar'
|
|
46
37
|
*/
|
|
47
|
-
|
|
38
|
+
docsProvider?: 'scalar' | 'swagger';
|
|
48
39
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @default undefined | 'https://unpkg.com/swagger-ui-dist/swagger-ui.css'
|
|
40
|
+
* Arbitrary configuration object for the UI.
|
|
52
41
|
*/
|
|
53
|
-
|
|
42
|
+
docsConfig?: Value<Promisable<Record<string, unknown>>, [StandardHandlerInterceptorOptions<T>]>;
|
|
54
43
|
/**
|
|
55
|
-
*
|
|
44
|
+
* HTML to inject into the <head> of the docs page.
|
|
56
45
|
*
|
|
57
|
-
* @
|
|
46
|
+
* @warning This is not escaped special characters, so must be used with caution to avoid XSS vulnerabilities.
|
|
47
|
+
*
|
|
48
|
+
* @default ''
|
|
58
49
|
*/
|
|
59
|
-
|
|
50
|
+
docsHead?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
60
51
|
/**
|
|
61
|
-
*
|
|
52
|
+
* URL of the external script bundle for the reference UI.
|
|
62
53
|
*
|
|
63
|
-
*
|
|
54
|
+
* - For Scalar: defaults to 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
|
|
55
|
+
* - For Swagger UI: defaults to 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui-bundle.js'
|
|
64
56
|
*/
|
|
65
|
-
|
|
57
|
+
docsScriptUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
66
58
|
/**
|
|
67
|
-
*
|
|
68
|
-
* Useful for custom stylesheets, meta tags, or scripts.
|
|
59
|
+
* URL of the external CSS bundle for the reference UI (used by Swagger UI).
|
|
69
60
|
*
|
|
70
|
-
* @default ''
|
|
61
|
+
* @default 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui.css' (if swagger)
|
|
62
|
+
*/
|
|
63
|
+
docsCssUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
64
|
+
/**
|
|
65
|
+
* Override function to generate the full HTML for the docs page.
|
|
71
66
|
*/
|
|
72
|
-
|
|
67
|
+
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec: OpenAPI.Document, docsProvider: 'scalar' | 'swagger', cssUrl: string | undefined) => string;
|
|
73
68
|
}
|
|
74
|
-
declare class
|
|
75
|
-
|
|
76
|
-
private readonly
|
|
69
|
+
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
70
|
+
private readonly generator;
|
|
71
|
+
private readonly specGenerateOptions;
|
|
77
72
|
private readonly specPath;
|
|
78
|
-
private readonly provider;
|
|
79
|
-
private readonly providerConfig;
|
|
80
|
-
private readonly providerScriptUrl;
|
|
81
|
-
private readonly providerCssUrl;
|
|
82
73
|
private readonly docsPath;
|
|
83
74
|
private readonly docsTitle;
|
|
84
75
|
private readonly docsHead;
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
private readonly docsProvider;
|
|
77
|
+
private readonly docsScriptUrl;
|
|
78
|
+
private readonly docsCssUrl;
|
|
79
|
+
private readonly docsConfig;
|
|
80
|
+
private readonly renderDocsHtml;
|
|
81
|
+
constructor(options?: OpenAPIReferencePluginOptions<T>);
|
|
82
|
+
init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
|
87
83
|
}
|
|
88
84
|
|
|
89
|
-
export {
|
|
90
|
-
export type {
|
|
85
|
+
export { OpenAPIReferencePlugin };
|
|
86
|
+
export type { OpenAPIReferencePluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,90 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { OpenAPI } from '@orpc/contract';
|
|
2
|
+
import { Context, HTTPPath, Router } from '@orpc/server';
|
|
3
|
+
import { StandardHandlerInterceptorOptions, StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
3
4
|
import { Value, Promisable } from '@orpc/shared';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { a as OpenAPIDocument } from '../shared/openapi.ByT4oUeY.js';
|
|
8
|
-
import '@hey-api/spec-types';
|
|
9
|
-
import '@orpc/client';
|
|
5
|
+
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.BGy4N6eR.js';
|
|
6
|
+
import '@orpc/openapi-client/standard';
|
|
7
|
+
import 'json-schema-typed/draft-2020-12';
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
interface OpenAPIReferenceHandlerPluginScalarConfig extends Partial<ApiReferenceConfiguration> {
|
|
13
|
-
}
|
|
14
|
-
interface OpenAPIReferenceHandlerPluginSwaggerConfig extends Partial<Omit<SwaggerUIOptions, 'dom_id' | 'presets' | 'plugins'>> {
|
|
15
|
-
dom_id?: undefined | never;
|
|
16
|
-
presets?: undefined | `SwaggerUIBundle.${string}`[];
|
|
17
|
-
plugins?: undefined | `SwaggerUIBundle.${string}`[];
|
|
18
|
-
}
|
|
19
|
-
interface OpenAPIReferenceHandlerPluginOptions<T extends Context, TProvider extends OpenAPIReferenceHandlerPluginProvider> {
|
|
9
|
+
interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGeneratorOptions {
|
|
20
10
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
11
|
+
* Options to pass to the OpenAPI generate.
|
|
12
|
+
*
|
|
23
13
|
*/
|
|
24
|
-
|
|
14
|
+
specGenerateOptions?: Value<Promisable<OpenAPIGeneratorGenerateOptions>, [StandardHandlerInterceptorOptions<T>]>;
|
|
25
15
|
/**
|
|
26
16
|
* The URL path at which to serve the OpenAPI JSON.
|
|
27
17
|
*
|
|
28
18
|
* @default '/spec.json'
|
|
29
19
|
*/
|
|
30
|
-
specPath?:
|
|
20
|
+
specPath?: HTTPPath;
|
|
31
21
|
/**
|
|
32
|
-
* The
|
|
22
|
+
* The URL path at which to serve the API reference UI.
|
|
33
23
|
*
|
|
34
|
-
* @default '
|
|
24
|
+
* @default '/'
|
|
35
25
|
*/
|
|
36
|
-
|
|
26
|
+
docsPath?: HTTPPath;
|
|
37
27
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
28
|
+
* The document title for the API reference UI.
|
|
29
|
+
*
|
|
30
|
+
* @default 'API Reference'
|
|
40
31
|
*/
|
|
41
|
-
|
|
32
|
+
docsTitle?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
42
33
|
/**
|
|
43
|
-
*
|
|
34
|
+
* The UI library to use for rendering the API reference.
|
|
44
35
|
*
|
|
45
|
-
* @default '
|
|
36
|
+
* @default 'scalar'
|
|
46
37
|
*/
|
|
47
|
-
|
|
38
|
+
docsProvider?: 'scalar' | 'swagger';
|
|
48
39
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @default undefined | 'https://unpkg.com/swagger-ui-dist/swagger-ui.css'
|
|
40
|
+
* Arbitrary configuration object for the UI.
|
|
52
41
|
*/
|
|
53
|
-
|
|
42
|
+
docsConfig?: Value<Promisable<Record<string, unknown>>, [StandardHandlerInterceptorOptions<T>]>;
|
|
54
43
|
/**
|
|
55
|
-
*
|
|
44
|
+
* HTML to inject into the <head> of the docs page.
|
|
56
45
|
*
|
|
57
|
-
* @
|
|
46
|
+
* @warning This is not escaped special characters, so must be used with caution to avoid XSS vulnerabilities.
|
|
47
|
+
*
|
|
48
|
+
* @default ''
|
|
58
49
|
*/
|
|
59
|
-
|
|
50
|
+
docsHead?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
60
51
|
/**
|
|
61
|
-
*
|
|
52
|
+
* URL of the external script bundle for the reference UI.
|
|
62
53
|
*
|
|
63
|
-
*
|
|
54
|
+
* - For Scalar: defaults to 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
|
|
55
|
+
* - For Swagger UI: defaults to 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui-bundle.js'
|
|
64
56
|
*/
|
|
65
|
-
|
|
57
|
+
docsScriptUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
66
58
|
/**
|
|
67
|
-
*
|
|
68
|
-
* Useful for custom stylesheets, meta tags, or scripts.
|
|
59
|
+
* URL of the external CSS bundle for the reference UI (used by Swagger UI).
|
|
69
60
|
*
|
|
70
|
-
* @default ''
|
|
61
|
+
* @default 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui.css' (if swagger)
|
|
62
|
+
*/
|
|
63
|
+
docsCssUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
64
|
+
/**
|
|
65
|
+
* Override function to generate the full HTML for the docs page.
|
|
71
66
|
*/
|
|
72
|
-
|
|
67
|
+
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec: OpenAPI.Document, docsProvider: 'scalar' | 'swagger', cssUrl: string | undefined) => string;
|
|
73
68
|
}
|
|
74
|
-
declare class
|
|
75
|
-
|
|
76
|
-
private readonly
|
|
69
|
+
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
70
|
+
private readonly generator;
|
|
71
|
+
private readonly specGenerateOptions;
|
|
77
72
|
private readonly specPath;
|
|
78
|
-
private readonly provider;
|
|
79
|
-
private readonly providerConfig;
|
|
80
|
-
private readonly providerScriptUrl;
|
|
81
|
-
private readonly providerCssUrl;
|
|
82
73
|
private readonly docsPath;
|
|
83
74
|
private readonly docsTitle;
|
|
84
75
|
private readonly docsHead;
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
private readonly docsProvider;
|
|
77
|
+
private readonly docsScriptUrl;
|
|
78
|
+
private readonly docsCssUrl;
|
|
79
|
+
private readonly docsConfig;
|
|
80
|
+
private readonly renderDocsHtml;
|
|
81
|
+
constructor(options?: OpenAPIReferencePluginOptions<T>);
|
|
82
|
+
init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
|
|
87
83
|
}
|
|
88
84
|
|
|
89
|
-
export {
|
|
90
|
-
export type {
|
|
85
|
+
export { OpenAPIReferencePlugin };
|
|
86
|
+
export type { OpenAPIReferencePluginOptions };
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,162 +1,157 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { stringifyJSON, once, value } from '@orpc/shared';
|
|
2
|
+
import { O as OpenAPIGenerator } from '../shared/openapi.BwdtJjDu.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';
|
|
2
9
|
|
|
3
|
-
class
|
|
4
|
-
|
|
5
|
-
|
|
10
|
+
class OpenAPIReferencePlugin {
|
|
11
|
+
generator;
|
|
12
|
+
specGenerateOptions;
|
|
6
13
|
specPath;
|
|
7
|
-
provider;
|
|
8
|
-
providerConfig;
|
|
9
|
-
providerScriptUrl;
|
|
10
|
-
providerCssUrl;
|
|
11
14
|
docsPath;
|
|
12
15
|
docsTitle;
|
|
13
16
|
docsHead;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.
|
|
21
|
-
this.docsTitle = options.docsTitle;
|
|
17
|
+
docsProvider;
|
|
18
|
+
docsScriptUrl;
|
|
19
|
+
docsCssUrl;
|
|
20
|
+
docsConfig;
|
|
21
|
+
renderDocsHtml;
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
this.specGenerateOptions = options.specGenerateOptions;
|
|
22
24
|
this.docsPath = options.docsPath ?? "/";
|
|
25
|
+
this.docsTitle = options.docsTitle ?? "API Reference";
|
|
26
|
+
this.docsConfig = options.docsConfig ?? void 0;
|
|
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);
|
|
23
30
|
this.docsHead = options.docsHead ?? "";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const span = getOpenTelemetryConfig()?.trace.getActiveSpan();
|
|
48
|
-
const spec = await value(this.spec, routingInterceptorOptions);
|
|
49
|
-
if (isSpecPath) {
|
|
50
|
-
span?.updateName(`${routingInterceptorOptions.request.method} ${routingInterceptorOptions.request.url} (openapi spec)`);
|
|
51
|
-
const specFile = new File([stringifyJSON(spec)], `${spec.info.title}.json`, {
|
|
52
|
-
type: "application/json"
|
|
53
|
-
});
|
|
54
|
-
return { matched: true, response: { status: 200, headers: {}, body: specFile } };
|
|
55
|
-
}
|
|
56
|
-
span?.updateName(`${routingInterceptorOptions.request.method} ${routingInterceptorOptions.request.url} (${this.provider} ui)`);
|
|
57
|
-
const docsTitle = await value(this.docsTitle, routingInterceptorOptions) ?? spec.info.title;
|
|
58
|
-
const docsHead = await value(this.docsHead, routingInterceptorOptions);
|
|
59
|
-
let html;
|
|
60
|
-
if (this.provider === "swagger") {
|
|
61
|
-
const scriptUrl = this.providerScriptUrl ?? "https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js";
|
|
62
|
-
const cssUrl = this.providerCssUrl ?? "https://unpkg.com/swagger-ui-dist/swagger-ui.css";
|
|
63
|
-
const config = {
|
|
64
|
-
dom_id: "#app",
|
|
65
|
-
spec,
|
|
66
|
-
deepLinking: true,
|
|
67
|
-
presets: [
|
|
68
|
-
"SwaggerUIBundle.presets.apis",
|
|
69
|
-
"SwaggerUIBundle.presets.standalone"
|
|
70
|
-
],
|
|
71
|
-
plugins: [
|
|
72
|
-
"SwaggerUIBundle.plugins.DownloadUrl"
|
|
73
|
-
],
|
|
74
|
-
...this.providerConfig
|
|
75
|
-
};
|
|
76
|
-
html = `
|
|
77
|
-
<!doctype html>
|
|
78
|
-
<html>
|
|
79
|
-
<head>
|
|
80
|
-
<meta charset="utf-8" />
|
|
81
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
82
|
-
<title>${escapeHtmlEntities(docsTitle)}</title>
|
|
83
|
-
<link rel="stylesheet" type="text/css" href="${escapeHtmlEntities(cssUrl)}" />
|
|
84
|
-
${docsHead}
|
|
85
|
-
</head>
|
|
86
|
-
<body>
|
|
87
|
-
<div id="app"></div>
|
|
31
|
+
this.specPath = options.specPath ?? "/spec.json";
|
|
32
|
+
this.generator = new OpenAPIGenerator(options);
|
|
33
|
+
const escapeHtmlEntities = (s) => s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
34
|
+
const escapeJsonForHtml = (obj) => stringifyJSON(obj).replace(/&/g, "\\u0026").replace(/'/g, "\\u0027").replace(/</g, "\\u003C").replace(/>/g, "\\u003E").replace(/\//g, "\\u002F");
|
|
35
|
+
this.renderDocsHtml = options.renderDocsHtml ?? ((specUrl, title, head, scriptUrl, config, spec, docsProvider, cssUrl) => {
|
|
36
|
+
let body;
|
|
37
|
+
if (docsProvider === "swagger") {
|
|
38
|
+
const swaggerConfig = {
|
|
39
|
+
dom_id: "#app",
|
|
40
|
+
spec,
|
|
41
|
+
deepLinking: true,
|
|
42
|
+
presets: [
|
|
43
|
+
"SwaggerUIBundle.presets.apis",
|
|
44
|
+
"SwaggerUIBundle.presets.standalone"
|
|
45
|
+
],
|
|
46
|
+
plugins: [
|
|
47
|
+
"SwaggerUIBundle.plugins.DownloadUrl"
|
|
48
|
+
],
|
|
49
|
+
...config
|
|
50
|
+
};
|
|
51
|
+
body = `
|
|
52
|
+
<body>
|
|
53
|
+
<div id="app"></div>
|
|
88
54
|
|
|
89
|
-
|
|
55
|
+
<script src="${escapeHtmlEntities(scriptUrl)}"><\/script>
|
|
90
56
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
57
|
+
<!-- IMPORTANT: assign to a variable first to prevent ), ( in values breaking the call expression. -->
|
|
58
|
+
<!-- IMPORTANT: escapeJsonForHtml ensures <, > cannot terminate the <\/script> tag prematurely. -->
|
|
59
|
+
<script>
|
|
60
|
+
const swaggerConfig = ${escapeJsonForHtml(swaggerConfig).replace(/"(SwaggerUIBundle\.[^"]+)"/g, "$1")}
|
|
95
61
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
${cssUrl ? `<link rel="stylesheet" type="text/css" href="${escapeHtmlEntities(cssUrl)}" />` : ""}
|
|
118
|
-
${docsHead}
|
|
119
|
-
</head>
|
|
120
|
-
<body>
|
|
121
|
-
<div id="app"></div>
|
|
122
|
-
|
|
123
|
-
<script src="${escapeHtmlEntities(scriptUrl)}"><\/script>
|
|
124
|
-
|
|
125
|
-
<!-- IMPORTANT: assign to a variable first to prevent ), ( in values breaking the call expression. -->
|
|
126
|
-
<!-- IMPORTANT: escapeJsonForHtml ensures <, > cannot terminate the <\/script> tag prematurely. -->
|
|
127
|
-
<script>
|
|
128
|
-
const scalarConfig = ${escapeJsonForHtml(config)}
|
|
62
|
+
window.onload = () => {
|
|
63
|
+
window.ui = SwaggerUIBundle(swaggerConfig)
|
|
64
|
+
}
|
|
65
|
+
<\/script>
|
|
66
|
+
</body>
|
|
67
|
+
`;
|
|
68
|
+
} else {
|
|
69
|
+
const scalarConfig = {
|
|
70
|
+
content: stringifyJSON(spec),
|
|
71
|
+
...config
|
|
72
|
+
};
|
|
73
|
+
body = `
|
|
74
|
+
<body>
|
|
75
|
+
<div id="app"></div>
|
|
76
|
+
|
|
77
|
+
<script src="${escapeHtmlEntities(scriptUrl)}"><\/script>
|
|
78
|
+
|
|
79
|
+
<!-- IMPORTANT: assign to a variable first to prevent ), ( in values breaking the call expression. -->
|
|
80
|
+
<!-- IMPORTANT: escapeJsonForHtml ensures <, > cannot terminate the <\/script> tag prematurely. -->
|
|
81
|
+
<script>
|
|
82
|
+
const scalarConfig = ${escapeJsonForHtml(scalarConfig)}
|
|
129
83
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
84
|
+
Scalar.createApiReference('#app', scalarConfig)
|
|
85
|
+
<\/script>
|
|
86
|
+
</body>
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
return `
|
|
90
|
+
<!doctype html>
|
|
91
|
+
<html>
|
|
92
|
+
<head>
|
|
93
|
+
<meta charset="utf-8" />
|
|
94
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
95
|
+
<title>${escapeHtmlEntities(title)}</title>
|
|
96
|
+
${cssUrl ? `<link rel="stylesheet" type="text/css" href="${escapeHtmlEntities(cssUrl)}" />` : ""}
|
|
97
|
+
${head}
|
|
98
|
+
</head>
|
|
99
|
+
${body}
|
|
100
|
+
</html>
|
|
101
|
+
`;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
init(options, router) {
|
|
105
|
+
options.interceptors ??= [];
|
|
106
|
+
options.interceptors.push(async (options2) => {
|
|
107
|
+
const res = await options2.next();
|
|
108
|
+
if (res.matched || options2.request.method !== "GET") {
|
|
109
|
+
return res;
|
|
110
|
+
}
|
|
111
|
+
const prefix = options2.prefix ?? "";
|
|
112
|
+
const requestPathname = options2.request.url.pathname.replace(/\/$/, "") || "/";
|
|
113
|
+
const docsUrl = new URL(`${prefix}${this.docsPath}`.replace(/\/$/, ""), options2.request.url.origin);
|
|
114
|
+
const specUrl = new URL(`${prefix}${this.specPath}`.replace(/\/$/, ""), options2.request.url.origin);
|
|
115
|
+
const generateSpec = once(async () => {
|
|
116
|
+
return await this.generator.generate(router, {
|
|
117
|
+
servers: [{ url: new URL(prefix, options2.request.url.origin).toString() }],
|
|
118
|
+
...await value(this.specGenerateOptions, options2)
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
if (requestPathname === specUrl.pathname) {
|
|
122
|
+
const spec = await generateSpec();
|
|
123
|
+
return {
|
|
124
|
+
matched: true,
|
|
125
|
+
response: {
|
|
126
|
+
status: 200,
|
|
127
|
+
headers: {},
|
|
128
|
+
body: new File([stringifyJSON(spec)], "spec.json", { type: "application/json" })
|
|
135
129
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (requestPathname === docsUrl.pathname) {
|
|
133
|
+
const html = this.renderDocsHtml(
|
|
134
|
+
specUrl.toString(),
|
|
135
|
+
await value(this.docsTitle, options2),
|
|
136
|
+
await value(this.docsHead, options2),
|
|
137
|
+
await value(this.docsScriptUrl, options2),
|
|
138
|
+
await value(this.docsConfig, options2),
|
|
139
|
+
await generateSpec(),
|
|
140
|
+
this.docsProvider,
|
|
141
|
+
await value(this.docsCssUrl, options2)
|
|
142
|
+
);
|
|
143
|
+
return {
|
|
144
|
+
matched: true,
|
|
145
|
+
response: {
|
|
146
|
+
status: 200,
|
|
147
|
+
headers: {},
|
|
148
|
+
body: new File([html], "api-reference.html", { type: "text/html" })
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return res;
|
|
153
|
+
});
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
|
-
function escapeHtmlEntities(s) {
|
|
156
|
-
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
157
|
-
}
|
|
158
|
-
function escapeJsonForHtml(obj) {
|
|
159
|
-
return stringifyJSON(obj).replace(/&/g, "\\u0026").replace(/'/g, "\\u0027").replace(/</g, "\\u003C").replace(/>/g, "\\u003E").replace(/\//g, "\\u002F");
|
|
160
|
-
}
|
|
161
156
|
|
|
162
|
-
export {
|
|
157
|
+
export { OpenAPIReferencePlugin };
|