@orpc/openapi 0.0.0-next.b6b0cc3 → 0.0.0-next.b6b8746
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 +127 -20
- 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 +11 -5
- package/dist/adapters/fetch/index.d.ts +11 -5
- package/dist/adapters/fetch/index.mjs +1 -1
- package/dist/adapters/node/index.d.mts +11 -5
- package/dist/adapters/node/index.d.ts +11 -5
- package/dist/adapters/node/index.mjs +1 -1
- package/dist/adapters/standard/index.d.mts +8 -23
- package/dist/adapters/standard/index.d.ts +8 -23
- package/dist/adapters/standard/index.mjs +1 -1
- package/dist/index.d.mts +25 -13
- package/dist/index.d.ts +25 -13
- package/dist/index.mjs +3 -3
- package/dist/plugins/index.d.mts +21 -5
- package/dist/plugins/index.d.ts +21 -5
- package/dist/plugins/index.mjs +69 -20
- package/dist/shared/{openapi.C_UtQ8Us.mjs → openapi.BB-W-NKv.mjs} +33 -8
- package/dist/shared/openapi.BGy4N6eR.d.mts +120 -0
- package/dist/shared/openapi.BGy4N6eR.d.ts +120 -0
- package/dist/shared/{openapi.PDTdnRIU.mjs → openapi.BwdtJjDu.mjs} +366 -83
- package/dist/shared/openapi.DwaweYRb.d.mts +54 -0
- package/dist/shared/openapi.DwaweYRb.d.ts +54 -0
- package/package.json +24 -14
- package/dist/shared/openapi.CwdCLgSU.d.mts +0 -53
- package/dist/shared/openapi.CwdCLgSU.d.ts +0 -53
- package/dist/shared/openapi.D3j94c9n.d.mts +0 -12
- package/dist/shared/openapi.D3j94c9n.d.ts +0 -12
package/dist/index.d.mts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { AnyContractProcedure } from '@orpc/contract';
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export { d as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, S as SchemaConvertOptions, c as SchemaConverter } from './shared/openapi.CwdCLgSU.mjs';
|
|
1
|
+
import { OpenAPI, AnyContractProcedure } from '@orpc/contract';
|
|
2
|
+
export { OpenAPI } from '@orpc/contract';
|
|
3
|
+
export { e as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, c as SchemaConvertOptions, d as SchemaConverter, S as SchemaConverterComponent } from './shared/openapi.BGy4N6eR.mjs';
|
|
5
4
|
import { HTTPPath, HTTPMethod } from '@orpc/client';
|
|
6
5
|
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
7
|
-
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
|
6
|
+
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from 'json-schema-typed/draft-2020-12';
|
|
8
7
|
import { JsonifiedClient } from '@orpc/openapi-client';
|
|
9
8
|
import { AnyRouter, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@orpc/server';
|
|
10
9
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
11
10
|
import '@orpc/openapi-client/standard';
|
|
12
11
|
|
|
13
|
-
type OverrideOperationValue = Partial<
|
|
12
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
|
14
13
|
/**
|
|
15
14
|
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
16
15
|
*
|
|
17
|
-
* @see {@link https://orpc.
|
|
16
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
|
|
18
17
|
*/
|
|
19
18
|
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
20
19
|
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
21
|
-
declare function applyCustomOpenAPIOperation(operation:
|
|
20
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* @internal
|
|
@@ -49,15 +48,15 @@ declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
|
49
48
|
/**
|
|
50
49
|
* @internal
|
|
51
50
|
*/
|
|
52
|
-
declare function toOpenAPIContent(schema: JSONSchema): Record<string,
|
|
51
|
+
declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
|
|
53
52
|
/**
|
|
54
53
|
* @internal
|
|
55
54
|
*/
|
|
56
|
-
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string,
|
|
55
|
+
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
|
|
57
56
|
/**
|
|
58
57
|
* @internal
|
|
59
58
|
*/
|
|
60
|
-
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'):
|
|
59
|
+
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
|
|
61
60
|
/**
|
|
62
61
|
* @internal
|
|
63
62
|
*/
|
|
@@ -65,7 +64,14 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
|
|
|
65
64
|
/**
|
|
66
65
|
* @internal
|
|
67
66
|
*/
|
|
68
|
-
declare function toOpenAPISchema(schema: JSONSchema):
|
|
67
|
+
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
68
|
+
declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
|
|
69
|
+
/**
|
|
70
|
+
* Simplifies composed object JSON Schemas (using anyOf, oneOf, allOf) by flattening nested compositions
|
|
71
|
+
*
|
|
72
|
+
* @warning The result is looser than the original schema and may not fully validate the same data.
|
|
73
|
+
*/
|
|
74
|
+
declare function simplifyComposedObjectJsonSchemasAndRefs(schema: JSONSchema, doc?: OpenAPI.Document): JSONSchema;
|
|
69
75
|
|
|
70
76
|
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
71
77
|
|
|
@@ -81,6 +87,7 @@ declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
|
|
|
81
87
|
* @internal
|
|
82
88
|
*/
|
|
83
89
|
declare function isAnySchema(schema: JSONSchema): boolean;
|
|
90
|
+
declare function isNeverSchema(schema: JSONSchema): boolean;
|
|
84
91
|
/**
|
|
85
92
|
* @internal
|
|
86
93
|
*/
|
|
@@ -96,10 +103,15 @@ declare function applySchemaOptionality(required: boolean, schema: JSONSchema):
|
|
|
96
103
|
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
|
97
104
|
*/
|
|
98
105
|
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
|
106
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
|
107
|
+
type: 'array';
|
|
108
|
+
items?: JSONSchema;
|
|
109
|
+
}];
|
|
110
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
|
99
111
|
|
|
100
112
|
declare const oo: {
|
|
101
113
|
spec: typeof customOpenAPIOperation;
|
|
102
114
|
};
|
|
103
115
|
|
|
104
|
-
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
116
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isNeverSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, simplifyComposedObjectJsonSchemasAndRefs, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
105
117
|
export type { FileSchema, ObjectSchema, OverrideOperationValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { AnyContractProcedure } from '@orpc/contract';
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export { d as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, S as SchemaConvertOptions, c as SchemaConverter } from './shared/openapi.CwdCLgSU.js';
|
|
1
|
+
import { OpenAPI, AnyContractProcedure } from '@orpc/contract';
|
|
2
|
+
export { OpenAPI } from '@orpc/contract';
|
|
3
|
+
export { e as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, c as SchemaConvertOptions, d as SchemaConverter, S as SchemaConverterComponent } from './shared/openapi.BGy4N6eR.js';
|
|
5
4
|
import { HTTPPath, HTTPMethod } from '@orpc/client';
|
|
6
5
|
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
7
|
-
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
|
6
|
+
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from 'json-schema-typed/draft-2020-12';
|
|
8
7
|
import { JsonifiedClient } from '@orpc/openapi-client';
|
|
9
8
|
import { AnyRouter, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@orpc/server';
|
|
10
9
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
11
10
|
import '@orpc/openapi-client/standard';
|
|
12
11
|
|
|
13
|
-
type OverrideOperationValue = Partial<
|
|
12
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
|
14
13
|
/**
|
|
15
14
|
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
16
15
|
*
|
|
17
|
-
* @see {@link https://orpc.
|
|
16
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
|
|
18
17
|
*/
|
|
19
18
|
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
20
19
|
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
21
|
-
declare function applyCustomOpenAPIOperation(operation:
|
|
20
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* @internal
|
|
@@ -49,15 +48,15 @@ declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
|
49
48
|
/**
|
|
50
49
|
* @internal
|
|
51
50
|
*/
|
|
52
|
-
declare function toOpenAPIContent(schema: JSONSchema): Record<string,
|
|
51
|
+
declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
|
|
53
52
|
/**
|
|
54
53
|
* @internal
|
|
55
54
|
*/
|
|
56
|
-
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string,
|
|
55
|
+
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
|
|
57
56
|
/**
|
|
58
57
|
* @internal
|
|
59
58
|
*/
|
|
60
|
-
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'):
|
|
59
|
+
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
|
|
61
60
|
/**
|
|
62
61
|
* @internal
|
|
63
62
|
*/
|
|
@@ -65,7 +64,14 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
|
|
|
65
64
|
/**
|
|
66
65
|
* @internal
|
|
67
66
|
*/
|
|
68
|
-
declare function toOpenAPISchema(schema: JSONSchema):
|
|
67
|
+
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
68
|
+
declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
|
|
69
|
+
/**
|
|
70
|
+
* Simplifies composed object JSON Schemas (using anyOf, oneOf, allOf) by flattening nested compositions
|
|
71
|
+
*
|
|
72
|
+
* @warning The result is looser than the original schema and may not fully validate the same data.
|
|
73
|
+
*/
|
|
74
|
+
declare function simplifyComposedObjectJsonSchemasAndRefs(schema: JSONSchema, doc?: OpenAPI.Document): JSONSchema;
|
|
69
75
|
|
|
70
76
|
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
71
77
|
|
|
@@ -81,6 +87,7 @@ declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
|
|
|
81
87
|
* @internal
|
|
82
88
|
*/
|
|
83
89
|
declare function isAnySchema(schema: JSONSchema): boolean;
|
|
90
|
+
declare function isNeverSchema(schema: JSONSchema): boolean;
|
|
84
91
|
/**
|
|
85
92
|
* @internal
|
|
86
93
|
*/
|
|
@@ -96,10 +103,15 @@ declare function applySchemaOptionality(required: boolean, schema: JSONSchema):
|
|
|
96
103
|
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
|
97
104
|
*/
|
|
98
105
|
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
|
106
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
|
107
|
+
type: 'array';
|
|
108
|
+
items?: JSONSchema;
|
|
109
|
+
}];
|
|
110
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
|
99
111
|
|
|
100
112
|
declare const oo: {
|
|
101
113
|
spec: typeof customOpenAPIOperation;
|
|
102
114
|
};
|
|
103
115
|
|
|
104
|
-
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
116
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isNeverSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, simplifyComposedObjectJsonSchemasAndRefs, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
105
117
|
export type { FileSchema, ObjectSchema, OverrideOperationValue };
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { c as customOpenAPIOperation } from './shared/openapi.
|
|
2
|
-
export { C as CompositeSchemaConverter, L as LOGIC_KEYWORDS, O as OpenAPIGenerator, a as applyCustomOpenAPIOperation,
|
|
1
|
+
import { c as customOpenAPIOperation } from './shared/openapi.BwdtJjDu.mjs';
|
|
2
|
+
export { C as CompositeSchemaConverter, L as LOGIC_KEYWORDS, O as OpenAPIGenerator, a as applyCustomOpenAPIOperation, p as applySchemaOptionality, h as checkParamsSchema, u as expandArrayableSchema, q as expandUnionSchema, o as filterSchemaBranches, g as getCustomOpenAPIOperation, l as isAnySchema, j as isFileSchema, m as isNeverSchema, k as isObjectSchema, v as isPrimitiveSchema, r as resolveOpenAPIJsonSchemaRef, n as separateObjectSchema, s as simplifyComposedObjectJsonSchemasAndRefs, d as toOpenAPIContent, e as toOpenAPIEventIteratorContent, b as toOpenAPIMethod, f as toOpenAPIParameters, t as toOpenAPIPath, i as toOpenAPISchema } from './shared/openapi.BwdtJjDu.mjs';
|
|
3
3
|
import { createORPCErrorFromJson } from '@orpc/client';
|
|
4
4
|
import { StandardOpenAPISerializer, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer } from '@orpc/openapi-client/standard';
|
|
5
5
|
import { ORPCError, createRouterClient } from '@orpc/server';
|
|
6
6
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
7
|
-
export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
|
7
|
+
export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from 'json-schema-typed/draft-2020-12';
|
|
8
8
|
import '@orpc/client/standard';
|
|
9
9
|
import '@orpc/contract';
|
|
10
10
|
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { OpenAPI } from '@orpc/contract';
|
|
1
2
|
import { Context, HTTPPath, Router } from '@orpc/server';
|
|
2
3
|
import { StandardHandlerInterceptorOptions, StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
3
4
|
import { Value, Promisable } from '@orpc/shared';
|
|
4
|
-
import {
|
|
5
|
-
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.CwdCLgSU.mjs';
|
|
6
|
-
import '@orpc/contract';
|
|
5
|
+
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.BGy4N6eR.mjs';
|
|
7
6
|
import '@orpc/openapi-client/standard';
|
|
8
7
|
import 'json-schema-typed/draft-2020-12';
|
|
9
8
|
|
|
@@ -31,6 +30,12 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
|
31
30
|
* @default 'API Reference'
|
|
32
31
|
*/
|
|
33
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';
|
|
34
39
|
/**
|
|
35
40
|
* Arbitrary configuration object for the UI.
|
|
36
41
|
*/
|
|
@@ -38,19 +43,28 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
|
38
43
|
/**
|
|
39
44
|
* HTML to inject into the <head> of the docs page.
|
|
40
45
|
*
|
|
46
|
+
* @warning This is not escaped special characters, so must be used with caution to avoid XSS vulnerabilities.
|
|
47
|
+
*
|
|
41
48
|
* @default ''
|
|
42
49
|
*/
|
|
43
50
|
docsHead?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
44
51
|
/**
|
|
45
52
|
* URL of the external script bundle for the reference UI.
|
|
46
53
|
*
|
|
47
|
-
*
|
|
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'
|
|
48
56
|
*/
|
|
49
57
|
docsScriptUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
58
|
+
/**
|
|
59
|
+
* URL of the external CSS bundle for the reference UI (used by Swagger UI).
|
|
60
|
+
*
|
|
61
|
+
* @default 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui.css' (if swagger)
|
|
62
|
+
*/
|
|
63
|
+
docsCssUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
50
64
|
/**
|
|
51
65
|
* Override function to generate the full HTML for the docs page.
|
|
52
66
|
*/
|
|
53
|
-
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec:
|
|
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;
|
|
54
68
|
}
|
|
55
69
|
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
56
70
|
private readonly generator;
|
|
@@ -59,7 +73,9 @@ declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandl
|
|
|
59
73
|
private readonly docsPath;
|
|
60
74
|
private readonly docsTitle;
|
|
61
75
|
private readonly docsHead;
|
|
76
|
+
private readonly docsProvider;
|
|
62
77
|
private readonly docsScriptUrl;
|
|
78
|
+
private readonly docsCssUrl;
|
|
63
79
|
private readonly docsConfig;
|
|
64
80
|
private readonly renderDocsHtml;
|
|
65
81
|
constructor(options?: OpenAPIReferencePluginOptions<T>);
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { OpenAPI } from '@orpc/contract';
|
|
1
2
|
import { Context, HTTPPath, Router } from '@orpc/server';
|
|
2
3
|
import { StandardHandlerInterceptorOptions, StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
3
4
|
import { Value, Promisable } from '@orpc/shared';
|
|
4
|
-
import {
|
|
5
|
-
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.CwdCLgSU.js';
|
|
6
|
-
import '@orpc/contract';
|
|
5
|
+
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.BGy4N6eR.js';
|
|
7
6
|
import '@orpc/openapi-client/standard';
|
|
8
7
|
import 'json-schema-typed/draft-2020-12';
|
|
9
8
|
|
|
@@ -31,6 +30,12 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
|
31
30
|
* @default 'API Reference'
|
|
32
31
|
*/
|
|
33
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';
|
|
34
39
|
/**
|
|
35
40
|
* Arbitrary configuration object for the UI.
|
|
36
41
|
*/
|
|
@@ -38,19 +43,28 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
|
38
43
|
/**
|
|
39
44
|
* HTML to inject into the <head> of the docs page.
|
|
40
45
|
*
|
|
46
|
+
* @warning This is not escaped special characters, so must be used with caution to avoid XSS vulnerabilities.
|
|
47
|
+
*
|
|
41
48
|
* @default ''
|
|
42
49
|
*/
|
|
43
50
|
docsHead?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
44
51
|
/**
|
|
45
52
|
* URL of the external script bundle for the reference UI.
|
|
46
53
|
*
|
|
47
|
-
*
|
|
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'
|
|
48
56
|
*/
|
|
49
57
|
docsScriptUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
58
|
+
/**
|
|
59
|
+
* URL of the external CSS bundle for the reference UI (used by Swagger UI).
|
|
60
|
+
*
|
|
61
|
+
* @default 'https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui.css' (if swagger)
|
|
62
|
+
*/
|
|
63
|
+
docsCssUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
50
64
|
/**
|
|
51
65
|
* Override function to generate the full HTML for the docs page.
|
|
52
66
|
*/
|
|
53
|
-
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec:
|
|
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;
|
|
54
68
|
}
|
|
55
69
|
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
56
70
|
private readonly generator;
|
|
@@ -59,7 +73,9 @@ declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandl
|
|
|
59
73
|
private readonly docsPath;
|
|
60
74
|
private readonly docsTitle;
|
|
61
75
|
private readonly docsHead;
|
|
76
|
+
private readonly docsProvider;
|
|
62
77
|
private readonly docsScriptUrl;
|
|
78
|
+
private readonly docsCssUrl;
|
|
63
79
|
private readonly docsConfig;
|
|
64
80
|
private readonly renderDocsHtml;
|
|
65
81
|
constructor(options?: OpenAPIReferencePluginOptions<T>);
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { stringifyJSON, once, value } from '@orpc/shared';
|
|
2
|
-
import { O as OpenAPIGenerator } from '../shared/openapi.
|
|
2
|
+
import { O as OpenAPIGenerator } from '../shared/openapi.BwdtJjDu.mjs';
|
|
3
3
|
import '@orpc/client';
|
|
4
4
|
import '@orpc/client/standard';
|
|
5
5
|
import '@orpc/contract';
|
|
@@ -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,36 +24,81 @@ 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
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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>
|
|
54
|
+
|
|
55
|
+
<script src="${escapeHtmlEntities(scriptUrl)}"><\/script>
|
|
56
|
+
|
|
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")}
|
|
61
|
+
|
|
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)}
|
|
83
|
+
|
|
84
|
+
Scalar.createApiReference('#app', scalarConfig)
|
|
85
|
+
<\/script>
|
|
86
|
+
</body>
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
35
89
|
return `
|
|
36
90
|
<!doctype html>
|
|
37
91
|
<html>
|
|
38
92
|
<head>
|
|
39
93
|
<meta charset="utf-8" />
|
|
40
94
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
41
|
-
<title>${
|
|
95
|
+
<title>${escapeHtmlEntities(title)}</title>
|
|
96
|
+
${cssUrl ? `<link rel="stylesheet" type="text/css" href="${escapeHtmlEntities(cssUrl)}" />` : ""}
|
|
42
97
|
${head}
|
|
43
98
|
</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>
|
|
99
|
+
${body}
|
|
53
100
|
</html>
|
|
54
|
-
|
|
101
|
+
`;
|
|
55
102
|
});
|
|
56
103
|
}
|
|
57
104
|
init(options, router) {
|
|
@@ -89,7 +136,9 @@ class OpenAPIReferencePlugin {
|
|
|
89
136
|
await value(this.docsHead, options2),
|
|
90
137
|
await value(this.docsScriptUrl, options2),
|
|
91
138
|
await value(this.docsConfig, options2),
|
|
92
|
-
await generateSpec()
|
|
139
|
+
await generateSpec(),
|
|
140
|
+
this.docsProvider,
|
|
141
|
+
await value(this.docsCssUrl, options2)
|
|
93
142
|
);
|
|
94
143
|
return {
|
|
95
144
|
matched: true,
|
|
@@ -2,15 +2,17 @@ import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, StandardBracketNota
|
|
|
2
2
|
import { StandardHandler } from '@orpc/server/standard';
|
|
3
3
|
import { isORPCErrorStatus } from '@orpc/client';
|
|
4
4
|
import { fallbackContractConfig } from '@orpc/contract';
|
|
5
|
-
import { isObject, stringifyJSON } from '@orpc/shared';
|
|
5
|
+
import { isObject, stringifyJSON, tryDecodeURIComponent, value } from '@orpc/shared';
|
|
6
6
|
import { toHttpPath } from '@orpc/client/standard';
|
|
7
7
|
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
|
8
8
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
9
9
|
|
|
10
10
|
class StandardOpenAPICodec {
|
|
11
|
-
constructor(serializer) {
|
|
11
|
+
constructor(serializer, options = {}) {
|
|
12
12
|
this.serializer = serializer;
|
|
13
|
+
this.customErrorResponseBodyEncoder = options.customErrorResponseBodyEncoder;
|
|
13
14
|
}
|
|
15
|
+
customErrorResponseBodyEncoder;
|
|
14
16
|
async decode(request, params, procedure) {
|
|
15
17
|
const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
|
|
16
18
|
if (inputStructure === "compact") {
|
|
@@ -47,6 +49,13 @@ class StandardOpenAPICodec {
|
|
|
47
49
|
const successStatus = fallbackContractConfig("defaultSuccessStatus", procedure["~orpc"].route.successStatus);
|
|
48
50
|
const outputStructure = fallbackContractConfig("defaultOutputStructure", procedure["~orpc"].route.outputStructure);
|
|
49
51
|
if (outputStructure === "compact") {
|
|
52
|
+
if (output instanceof ReadableStream) {
|
|
53
|
+
return {
|
|
54
|
+
status: successStatus,
|
|
55
|
+
headers: {},
|
|
56
|
+
body: output
|
|
57
|
+
};
|
|
58
|
+
}
|
|
50
59
|
return {
|
|
51
60
|
status: successStatus,
|
|
52
61
|
headers: {},
|
|
@@ -66,6 +75,13 @@ class StandardOpenAPICodec {
|
|
|
66
75
|
${stringifyJSON(output)}
|
|
67
76
|
`);
|
|
68
77
|
}
|
|
78
|
+
if (output.body instanceof ReadableStream) {
|
|
79
|
+
return {
|
|
80
|
+
status: output.status ?? successStatus,
|
|
81
|
+
headers: output.headers ?? {},
|
|
82
|
+
body: output.body
|
|
83
|
+
};
|
|
84
|
+
}
|
|
69
85
|
return {
|
|
70
86
|
status: output.status ?? successStatus,
|
|
71
87
|
headers: output.headers ?? {},
|
|
@@ -73,10 +89,11 @@ class StandardOpenAPICodec {
|
|
|
73
89
|
};
|
|
74
90
|
}
|
|
75
91
|
encodeError(error) {
|
|
92
|
+
const body = this.customErrorResponseBodyEncoder?.(error) ?? error.toJSON();
|
|
76
93
|
return {
|
|
77
94
|
status: error.status,
|
|
78
95
|
headers: {},
|
|
79
|
-
body: this.serializer.serialize(
|
|
96
|
+
body: this.serializer.serialize(body, { outputFormat: "plain" })
|
|
80
97
|
};
|
|
81
98
|
}
|
|
82
99
|
#isDetailedOutput(output) {
|
|
@@ -97,14 +114,22 @@ function toRou3Pattern(path) {
|
|
|
97
114
|
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
|
98
115
|
}
|
|
99
116
|
function decodeParams(params) {
|
|
100
|
-
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key,
|
|
117
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, tryDecodeURIComponent(value)]));
|
|
101
118
|
}
|
|
102
119
|
|
|
103
120
|
class StandardOpenAPIMatcher {
|
|
121
|
+
filter;
|
|
104
122
|
tree = createRouter();
|
|
105
123
|
pendingRouters = [];
|
|
124
|
+
constructor(options = {}) {
|
|
125
|
+
this.filter = options.filter ?? true;
|
|
126
|
+
}
|
|
106
127
|
init(router, path = []) {
|
|
107
|
-
const laziedOptions = traverseContractProcedures({ router, path }, (
|
|
128
|
+
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
|
|
129
|
+
if (!value(this.filter, traverseOptions)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const { path: path2, contract } = traverseOptions;
|
|
108
133
|
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
|
109
134
|
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
|
110
135
|
if (isProcedure(contract)) {
|
|
@@ -168,10 +193,10 @@ class StandardOpenAPIMatcher {
|
|
|
168
193
|
class StandardOpenAPIHandler extends StandardHandler {
|
|
169
194
|
constructor(router, options) {
|
|
170
195
|
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
171
|
-
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
|
196
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer(options);
|
|
172
197
|
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
173
|
-
const matcher = new StandardOpenAPIMatcher();
|
|
174
|
-
const codec = new StandardOpenAPICodec(serializer);
|
|
198
|
+
const matcher = new StandardOpenAPIMatcher(options);
|
|
199
|
+
const codec = new StandardOpenAPICodec(serializer, options);
|
|
175
200
|
super(router, matcher, codec, options);
|
|
176
201
|
}
|
|
177
202
|
}
|