@orpc/openapi 0.0.0-next.b4e6d3a → 0.0.0-next.b50e4fc
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 +214 -0
- 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 +23 -0
- package/dist/adapters/fetch/index.d.ts +23 -0
- package/dist/adapters/fetch/index.mjs +18 -0
- package/dist/adapters/node/index.d.mts +23 -0
- package/dist/adapters/node/index.d.ts +23 -0
- package/dist/adapters/node/index.mjs +18 -0
- package/dist/adapters/standard/index.d.mts +20 -0
- package/dist/adapters/standard/index.d.ts +20 -0
- package/dist/adapters/standard/index.mjs +9 -0
- package/dist/index.d.mts +116 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.mjs +41 -0
- package/dist/plugins/index.d.mts +86 -0
- package/dist/plugins/index.d.ts +86 -0
- package/dist/plugins/index.mjs +157 -0
- package/dist/shared/openapi.BGy4N6eR.d.mts +120 -0
- package/dist/shared/openapi.BGy4N6eR.d.ts +120 -0
- package/dist/shared/openapi.CoREqFh3.mjs +853 -0
- package/dist/shared/openapi.DIt-Z9W1.mjs +190 -0
- package/dist/shared/openapi.DwaweYRb.d.mts +54 -0
- package/dist/shared/openapi.DwaweYRb.d.ts +54 -0
- package/package.json +41 -42
- package/dist/chunk-DRV7KYES.js +0 -420
- package/dist/chunk-HC5PVG4R.js +0 -52
- package/dist/chunk-NHYWV7BW.js +0 -32
- package/dist/fetch.js +0 -9
- package/dist/hono.js +0 -9
- package/dist/index.js +0 -602
- package/dist/next.js +0 -9
- package/dist/node.js +0 -30
- package/dist/src/adapters/fetch/index.d.ts +0 -2
- package/dist/src/adapters/fetch/openapi-handler.d.ts +0 -11
- package/dist/src/adapters/hono/index.d.ts +0 -2
- package/dist/src/adapters/next/index.d.ts +0 -2
- package/dist/src/adapters/node/index.d.ts +0 -2
- package/dist/src/adapters/node/openapi-handler.d.ts +0 -11
- package/dist/src/adapters/standard/bracket-notation.d.ts +0 -84
- package/dist/src/adapters/standard/index.d.ts +0 -6
- package/dist/src/adapters/standard/openapi-codec.d.ts +0 -15
- package/dist/src/adapters/standard/openapi-handler.d.ts +0 -7
- package/dist/src/adapters/standard/openapi-matcher.d.ts +0 -20
- package/dist/src/adapters/standard/openapi-serializer.d.ts +0 -11
- package/dist/src/index.d.ts +0 -17
- package/dist/src/json-serializer.d.ts +0 -5
- package/dist/src/openapi-content-builder.d.ts +0 -10
- package/dist/src/openapi-error.d.ts +0 -3
- package/dist/src/openapi-generator.d.ts +0 -67
- package/dist/src/openapi-input-structure-parser.d.ts +0 -22
- package/dist/src/openapi-operation-extender.d.ts +0 -7
- package/dist/src/openapi-output-structure-parser.d.ts +0 -18
- package/dist/src/openapi-parameters-builder.d.ts +0 -12
- package/dist/src/openapi-path-parser.d.ts +0 -8
- package/dist/src/openapi.d.ts +0 -3
- package/dist/src/schema-converter.d.ts +0 -16
- package/dist/src/schema-utils.d.ts +0 -11
- package/dist/src/schema.d.ts +0 -12
- package/dist/src/utils.d.ts +0 -3
- package/dist/standard.js +0 -14
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
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';
|
|
4
|
+
import { HTTPPath, HTTPMethod } from '@orpc/client';
|
|
5
|
+
import { JSONSchema } 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';
|
|
7
|
+
import { JsonifiedClient } from '@orpc/openapi-client';
|
|
8
|
+
import { AnyRouter, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@orpc/server';
|
|
9
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
10
|
+
import '@orpc/openapi-client/standard';
|
|
11
|
+
|
|
12
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
|
13
|
+
/**
|
|
14
|
+
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
|
|
17
|
+
*/
|
|
18
|
+
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
19
|
+
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
20
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
type ObjectSchema = JSONSchema & {
|
|
26
|
+
type: 'object';
|
|
27
|
+
} & object;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
type FileSchema = JSONSchema & {
|
|
32
|
+
type: 'string';
|
|
33
|
+
contentMediaType: string;
|
|
34
|
+
} & object;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
declare const LOGIC_KEYWORDS: string[];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
declare function toOpenAPIPath(path: HTTPPath): string;
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
|
|
56
|
+
/**
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
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;
|
|
75
|
+
|
|
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>>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
*@internal
|
|
80
|
+
*/
|
|
81
|
+
declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
|
|
86
|
+
/**
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
declare function isAnySchema(schema: JSONSchema): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
|
94
|
+
/**
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
|
|
98
|
+
declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
|
|
99
|
+
/**
|
|
100
|
+
* Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
|
|
101
|
+
* recursively expands it into an array of its constituent, non-union base schemas.
|
|
102
|
+
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
|
103
|
+
*/
|
|
104
|
+
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
|
105
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
|
106
|
+
type: 'array';
|
|
107
|
+
items?: JSONSchema;
|
|
108
|
+
}];
|
|
109
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
|
110
|
+
|
|
111
|
+
declare const oo: {
|
|
112
|
+
spec: typeof customOpenAPIOperation;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, simplifyComposedObjectJsonSchemasAndRefs, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
116
|
+
export type { FileSchema, ObjectSchema, OverrideOperationValue };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
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';
|
|
4
|
+
import { HTTPPath, HTTPMethod } from '@orpc/client';
|
|
5
|
+
import { JSONSchema } 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';
|
|
7
|
+
import { JsonifiedClient } from '@orpc/openapi-client';
|
|
8
|
+
import { AnyRouter, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@orpc/server';
|
|
9
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
10
|
+
import '@orpc/openapi-client/standard';
|
|
11
|
+
|
|
12
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
|
13
|
+
/**
|
|
14
|
+
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
|
|
17
|
+
*/
|
|
18
|
+
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
19
|
+
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
20
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
type ObjectSchema = JSONSchema & {
|
|
26
|
+
type: 'object';
|
|
27
|
+
} & object;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
type FileSchema = JSONSchema & {
|
|
32
|
+
type: 'string';
|
|
33
|
+
contentMediaType: string;
|
|
34
|
+
} & object;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
declare const LOGIC_KEYWORDS: string[];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
declare function toOpenAPIPath(path: HTTPPath): string;
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
|
|
56
|
+
/**
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
|
|
60
|
+
/**
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
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;
|
|
75
|
+
|
|
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>>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
*@internal
|
|
80
|
+
*/
|
|
81
|
+
declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
|
|
86
|
+
/**
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
declare function isAnySchema(schema: JSONSchema): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
|
94
|
+
/**
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
|
|
98
|
+
declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
|
|
99
|
+
/**
|
|
100
|
+
* Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
|
|
101
|
+
* recursively expands it into an array of its constituent, non-union base schemas.
|
|
102
|
+
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
|
103
|
+
*/
|
|
104
|
+
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
|
105
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
|
106
|
+
type: 'array';
|
|
107
|
+
items?: JSONSchema;
|
|
108
|
+
}];
|
|
109
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
|
110
|
+
|
|
111
|
+
declare const oo: {
|
|
112
|
+
spec: typeof customOpenAPIOperation;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, simplifyComposedObjectJsonSchemasAndRefs, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
116
|
+
export type { FileSchema, ObjectSchema, OverrideOperationValue };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { c as customOpenAPIOperation } from './shared/openapi.CoREqFh3.mjs';
|
|
2
|
+
export { C as CompositeSchemaConverter, L as LOGIC_KEYWORDS, O as OpenAPIGenerator, a as applyCustomOpenAPIOperation, o as applySchemaOptionality, h as checkParamsSchema, q as expandArrayableSchema, p as expandUnionSchema, n as filterSchemaBranches, g as getCustomOpenAPIOperation, l as isAnySchema, j as isFileSchema, k as isObjectSchema, u as isPrimitiveSchema, r as resolveOpenAPIJsonSchemaRef, m 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.CoREqFh3.mjs';
|
|
3
|
+
import { createORPCErrorFromJson } from '@orpc/client';
|
|
4
|
+
import { StandardOpenAPISerializer, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer } from '@orpc/openapi-client/standard';
|
|
5
|
+
import { ORPCError, createRouterClient } from '@orpc/server';
|
|
6
|
+
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
7
|
+
export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from 'json-schema-typed/draft-2020-12';
|
|
8
|
+
import '@orpc/client/standard';
|
|
9
|
+
import '@orpc/contract';
|
|
10
|
+
|
|
11
|
+
function createJsonifiedRouterClient(router, ...rest) {
|
|
12
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
13
|
+
const serializer = new StandardOpenAPISerializer(new StandardOpenAPIJsonSerializer(), new StandardBracketNotationSerializer());
|
|
14
|
+
options.interceptors ??= [];
|
|
15
|
+
options.interceptors.unshift(async (options2) => {
|
|
16
|
+
try {
|
|
17
|
+
return serializer.deserialize(
|
|
18
|
+
serializer.serialize(
|
|
19
|
+
await options2.next()
|
|
20
|
+
)
|
|
21
|
+
);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
if (e instanceof ORPCError) {
|
|
24
|
+
throw createORPCErrorFromJson(serializer.deserialize(
|
|
25
|
+
serializer.serialize(
|
|
26
|
+
e.toJSON(),
|
|
27
|
+
{ outputFormat: "plain" }
|
|
28
|
+
)
|
|
29
|
+
));
|
|
30
|
+
}
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return createRouterClient(router, options);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const oo = {
|
|
38
|
+
spec: customOpenAPIOperation
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { createJsonifiedRouterClient, customOpenAPIOperation, oo };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { OpenAPI } from '@orpc/contract';
|
|
2
|
+
import { Context, HTTPPath, Router } from '@orpc/server';
|
|
3
|
+
import { StandardHandlerInterceptorOptions, StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
4
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
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';
|
|
8
|
+
|
|
9
|
+
interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGeneratorOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Options to pass to the OpenAPI generate.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
specGenerateOptions?: Value<Promisable<OpenAPIGeneratorGenerateOptions>, [StandardHandlerInterceptorOptions<T>]>;
|
|
15
|
+
/**
|
|
16
|
+
* The URL path at which to serve the OpenAPI JSON.
|
|
17
|
+
*
|
|
18
|
+
* @default '/spec.json'
|
|
19
|
+
*/
|
|
20
|
+
specPath?: HTTPPath;
|
|
21
|
+
/**
|
|
22
|
+
* The URL path at which to serve the API reference UI.
|
|
23
|
+
*
|
|
24
|
+
* @default '/'
|
|
25
|
+
*/
|
|
26
|
+
docsPath?: HTTPPath;
|
|
27
|
+
/**
|
|
28
|
+
* The document title for the API reference UI.
|
|
29
|
+
*
|
|
30
|
+
* @default 'API Reference'
|
|
31
|
+
*/
|
|
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';
|
|
39
|
+
/**
|
|
40
|
+
* Arbitrary configuration object for the UI.
|
|
41
|
+
*/
|
|
42
|
+
docsConfig?: Value<Promisable<Record<string, unknown>>, [StandardHandlerInterceptorOptions<T>]>;
|
|
43
|
+
/**
|
|
44
|
+
* HTML to inject into the <head> of the docs page.
|
|
45
|
+
*
|
|
46
|
+
* @warning This is not escaped special characters, so must be used with caution to avoid XSS vulnerabilities.
|
|
47
|
+
*
|
|
48
|
+
* @default ''
|
|
49
|
+
*/
|
|
50
|
+
docsHead?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
51
|
+
/**
|
|
52
|
+
* URL of the external script bundle for the reference UI.
|
|
53
|
+
*
|
|
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'
|
|
56
|
+
*/
|
|
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>]>;
|
|
64
|
+
/**
|
|
65
|
+
* Override function to generate the full HTML for the docs page.
|
|
66
|
+
*/
|
|
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;
|
|
68
|
+
}
|
|
69
|
+
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
70
|
+
private readonly generator;
|
|
71
|
+
private readonly specGenerateOptions;
|
|
72
|
+
private readonly specPath;
|
|
73
|
+
private readonly docsPath;
|
|
74
|
+
private readonly docsTitle;
|
|
75
|
+
private readonly docsHead;
|
|
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;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { OpenAPIReferencePlugin };
|
|
86
|
+
export type { OpenAPIReferencePluginOptions };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { OpenAPI } from '@orpc/contract';
|
|
2
|
+
import { Context, HTTPPath, Router } from '@orpc/server';
|
|
3
|
+
import { StandardHandlerInterceptorOptions, StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
|
|
4
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
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';
|
|
8
|
+
|
|
9
|
+
interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGeneratorOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Options to pass to the OpenAPI generate.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
specGenerateOptions?: Value<Promisable<OpenAPIGeneratorGenerateOptions>, [StandardHandlerInterceptorOptions<T>]>;
|
|
15
|
+
/**
|
|
16
|
+
* The URL path at which to serve the OpenAPI JSON.
|
|
17
|
+
*
|
|
18
|
+
* @default '/spec.json'
|
|
19
|
+
*/
|
|
20
|
+
specPath?: HTTPPath;
|
|
21
|
+
/**
|
|
22
|
+
* The URL path at which to serve the API reference UI.
|
|
23
|
+
*
|
|
24
|
+
* @default '/'
|
|
25
|
+
*/
|
|
26
|
+
docsPath?: HTTPPath;
|
|
27
|
+
/**
|
|
28
|
+
* The document title for the API reference UI.
|
|
29
|
+
*
|
|
30
|
+
* @default 'API Reference'
|
|
31
|
+
*/
|
|
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';
|
|
39
|
+
/**
|
|
40
|
+
* Arbitrary configuration object for the UI.
|
|
41
|
+
*/
|
|
42
|
+
docsConfig?: Value<Promisable<Record<string, unknown>>, [StandardHandlerInterceptorOptions<T>]>;
|
|
43
|
+
/**
|
|
44
|
+
* HTML to inject into the <head> of the docs page.
|
|
45
|
+
*
|
|
46
|
+
* @warning This is not escaped special characters, so must be used with caution to avoid XSS vulnerabilities.
|
|
47
|
+
*
|
|
48
|
+
* @default ''
|
|
49
|
+
*/
|
|
50
|
+
docsHead?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
|
51
|
+
/**
|
|
52
|
+
* URL of the external script bundle for the reference UI.
|
|
53
|
+
*
|
|
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'
|
|
56
|
+
*/
|
|
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>]>;
|
|
64
|
+
/**
|
|
65
|
+
* Override function to generate the full HTML for the docs page.
|
|
66
|
+
*/
|
|
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;
|
|
68
|
+
}
|
|
69
|
+
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
70
|
+
private readonly generator;
|
|
71
|
+
private readonly specGenerateOptions;
|
|
72
|
+
private readonly specPath;
|
|
73
|
+
private readonly docsPath;
|
|
74
|
+
private readonly docsTitle;
|
|
75
|
+
private readonly docsHead;
|
|
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;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { OpenAPIReferencePlugin };
|
|
86
|
+
export type { OpenAPIReferencePluginOptions };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { stringifyJSON, once, value } from '@orpc/shared';
|
|
2
|
+
import { O as OpenAPIGenerator } from '../shared/openapi.CoREqFh3.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
|
+
docsProvider;
|
|
18
|
+
docsScriptUrl;
|
|
19
|
+
docsCssUrl;
|
|
20
|
+
docsConfig;
|
|
21
|
+
renderDocsHtml;
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
this.specGenerateOptions = options.specGenerateOptions;
|
|
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);
|
|
30
|
+
this.docsHead = options.docsHead ?? "";
|
|
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>
|
|
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
|
+
}
|
|
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" })
|
|
129
|
+
}
|
|
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
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { OpenAPIReferencePlugin };
|