@orpc/openapi 0.0.0-next.09ec5b4 → 0.0.0-next.0a9a32d
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 +29 -20
- package/dist/adapters/aws-lambda/index.d.mts +19 -0
- package/dist/adapters/aws-lambda/index.d.ts +19 -0
- package/dist/adapters/aws-lambda/index.mjs +18 -0
- package/dist/adapters/fetch/index.d.mts +14 -9
- package/dist/adapters/fetch/index.d.ts +14 -9
- package/dist/adapters/fetch/index.mjs +14 -6
- package/dist/adapters/node/index.d.mts +14 -9
- package/dist/adapters/node/index.d.ts +14 -9
- package/dist/adapters/node/index.mjs +9 -20
- package/dist/adapters/standard/index.d.mts +22 -17
- package/dist/adapters/standard/index.d.ts +22 -17
- package/dist/adapters/standard/index.mjs +5 -3
- package/dist/index.d.mts +96 -155
- package/dist/index.d.ts +96 -155
- package/dist/index.mjs +34 -654
- package/dist/plugins/index.d.mts +69 -0
- package/dist/plugins/index.d.ts +69 -0
- package/dist/plugins/index.mjs +108 -0
- package/dist/shared/openapi.1iT1iSZi.mjs +750 -0
- package/dist/shared/{openapi.CDsfPHgw.mjs → openapi.BVXcB0u4.mjs} +69 -30
- package/dist/shared/openapi.CQmjvnb0.d.mts +31 -0
- package/dist/shared/openapi.CQmjvnb0.d.ts +31 -0
- package/dist/shared/openapi.CfjfVeBJ.d.mts +108 -0
- package/dist/shared/openapi.CfjfVeBJ.d.ts +108 -0
- package/package.json +20 -23
- package/dist/adapters/hono/index.d.mts +0 -7
- package/dist/adapters/hono/index.d.ts +0 -7
- package/dist/adapters/hono/index.mjs +0 -10
- package/dist/adapters/next/index.d.mts +0 -7
- package/dist/adapters/next/index.d.ts +0 -7
- package/dist/adapters/next/index.mjs +0 -10
- package/dist/shared/openapi.BHG_gu5Z.mjs +0 -8
- package/dist/shared/openapi.D0VMNR6V.mjs +0 -25
- package/dist/shared/openapi.Dz_6xooR.d.mts +0 -7
- package/dist/shared/openapi.Dz_6xooR.d.ts +0 -7
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
+
import { isORPCErrorStatus } from '@orpc/client';
|
|
1
4
|
import { fallbackContractConfig } from '@orpc/contract';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
+
import { isObject, stringifyJSON, tryDecodeURIComponent, value } from '@orpc/shared';
|
|
6
|
+
import { toHttpPath } from '@orpc/client/standard';
|
|
7
|
+
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
|
5
8
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
6
|
-
import { s as standardizeHTTPPath } from './openapi.BHG_gu5Z.mjs';
|
|
7
9
|
|
|
8
|
-
class
|
|
9
|
-
constructor(serializer
|
|
10
|
+
class StandardOpenAPICodec {
|
|
11
|
+
constructor(serializer) {
|
|
10
12
|
this.serializer = serializer;
|
|
11
13
|
}
|
|
12
14
|
async decode(request, params, procedure) {
|
|
@@ -51,13 +53,21 @@ class OpenAPICodec {
|
|
|
51
53
|
body: this.serializer.serialize(output)
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
|
-
if (!
|
|
55
|
-
throw new Error(
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
if (!this.#isDetailedOutput(output)) {
|
|
57
|
+
throw new Error(`
|
|
58
|
+
Invalid "detailed" output structure:
|
|
59
|
+
\u2022 Expected an object with optional properties:
|
|
60
|
+
- status (number 200-399)
|
|
61
|
+
- headers (Record<string, string | string[]>)
|
|
62
|
+
- body (any)
|
|
63
|
+
\u2022 No extra keys allowed.
|
|
64
|
+
|
|
65
|
+
Actual value:
|
|
66
|
+
${stringifyJSON(output)}
|
|
67
|
+
`);
|
|
58
68
|
}
|
|
59
69
|
return {
|
|
60
|
-
status: successStatus,
|
|
70
|
+
status: output.status ?? successStatus,
|
|
61
71
|
headers: output.headers ?? {},
|
|
62
72
|
body: this.serializer.serialize(output.body)
|
|
63
73
|
};
|
|
@@ -66,21 +76,45 @@ class OpenAPICodec {
|
|
|
66
76
|
return {
|
|
67
77
|
status: error.status,
|
|
68
78
|
headers: {},
|
|
69
|
-
body: this.serializer.serialize(error.toJSON())
|
|
79
|
+
body: this.serializer.serialize(error.toJSON(), { outputFormat: "plain" })
|
|
70
80
|
};
|
|
71
81
|
}
|
|
82
|
+
#isDetailedOutput(output) {
|
|
83
|
+
if (!isObject(output)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (output.headers && !isObject(output.headers)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
72
94
|
}
|
|
73
95
|
|
|
74
|
-
|
|
96
|
+
function toRou3Pattern(path) {
|
|
97
|
+
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
|
98
|
+
}
|
|
99
|
+
function decodeParams(params) {
|
|
100
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, tryDecodeURIComponent(value)]));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class StandardOpenAPIMatcher {
|
|
104
|
+
filter;
|
|
75
105
|
tree = createRouter();
|
|
76
106
|
pendingRouters = [];
|
|
107
|
+
constructor(options = {}) {
|
|
108
|
+
this.filter = options.filter ?? true;
|
|
109
|
+
}
|
|
77
110
|
init(router, path = []) {
|
|
78
|
-
const laziedOptions =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
111
|
+
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
|
|
112
|
+
if (!value(this.filter, traverseOptions)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const { path: path2, contract } = traverseOptions;
|
|
82
116
|
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
|
83
|
-
const httpPath =
|
|
117
|
+
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
|
84
118
|
if (isProcedure(contract)) {
|
|
85
119
|
addRoute(this.tree, method, httpPath, {
|
|
86
120
|
path: path2,
|
|
@@ -100,8 +134,8 @@ class OpenAPIMatcher {
|
|
|
100
134
|
});
|
|
101
135
|
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
|
102
136
|
...option,
|
|
103
|
-
httpPathPrefix:
|
|
104
|
-
laziedPrefix:
|
|
137
|
+
httpPathPrefix: toHttpPath(option.path),
|
|
138
|
+
laziedPrefix: getLazyMeta(option.router).prefix
|
|
105
139
|
})));
|
|
106
140
|
}
|
|
107
141
|
async match(method, pathname) {
|
|
@@ -109,7 +143,7 @@ class OpenAPIMatcher {
|
|
|
109
143
|
const newPendingRouters = [];
|
|
110
144
|
for (const pendingRouter of this.pendingRouters) {
|
|
111
145
|
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
|
112
|
-
const { default: router } = await unlazy(pendingRouter.
|
|
146
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
|
113
147
|
this.init(router, pendingRouter.path);
|
|
114
148
|
} else {
|
|
115
149
|
newPendingRouters.push(pendingRouter);
|
|
@@ -122,14 +156,14 @@ class OpenAPIMatcher {
|
|
|
122
156
|
return void 0;
|
|
123
157
|
}
|
|
124
158
|
if (!match.data.procedure) {
|
|
125
|
-
const { default: maybeProcedure } = await unlazy(
|
|
159
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
|
|
126
160
|
if (!isProcedure(maybeProcedure)) {
|
|
127
161
|
throw new Error(`
|
|
128
|
-
[Contract-First] Missing or invalid implementation for procedure at path: ${
|
|
162
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
|
|
129
163
|
Ensure that the procedure is correctly defined and matches the expected contract.
|
|
130
164
|
`);
|
|
131
165
|
}
|
|
132
|
-
match.data.procedure = createContractedProcedure(match.data.contract
|
|
166
|
+
match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
|
|
133
167
|
}
|
|
134
168
|
return {
|
|
135
169
|
path: match.data.path,
|
|
@@ -138,11 +172,16 @@ class OpenAPIMatcher {
|
|
|
138
172
|
};
|
|
139
173
|
}
|
|
140
174
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
175
|
+
|
|
176
|
+
class StandardOpenAPIHandler extends StandardHandler {
|
|
177
|
+
constructor(router, options) {
|
|
178
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
|
179
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer(options);
|
|
180
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
|
181
|
+
const matcher = new StandardOpenAPIMatcher(options);
|
|
182
|
+
const codec = new StandardOpenAPICodec(serializer);
|
|
183
|
+
super(router, matcher, codec, options);
|
|
184
|
+
}
|
|
146
185
|
}
|
|
147
186
|
|
|
148
|
-
export {
|
|
187
|
+
export { StandardOpenAPICodec as S, StandardOpenAPIHandler as a, StandardOpenAPIMatcher as b, decodeParams as d, toRou3Pattern as t };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { TraverseContractProcedureCallbackOptions, AnyRouter, Context, Router } from '@orpc/server';
|
|
3
|
+
import { StandardMatcher, StandardMatchResult, StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
|
|
4
|
+
import { HTTPPath } from '@orpc/client';
|
|
5
|
+
import { Value } from '@orpc/shared';
|
|
6
|
+
|
|
7
|
+
interface StandardOpenAPIMatcherOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Filter procedures. Return `false` to exclude a procedure from matching.
|
|
10
|
+
*
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
|
14
|
+
}
|
|
15
|
+
declare class StandardOpenAPIMatcher implements StandardMatcher {
|
|
16
|
+
private readonly filter;
|
|
17
|
+
private readonly tree;
|
|
18
|
+
private pendingRouters;
|
|
19
|
+
constructor(options?: StandardOpenAPIMatcherOptions);
|
|
20
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
|
21
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions, StandardOpenAPIMatcherOptions {
|
|
25
|
+
}
|
|
26
|
+
declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
|
|
27
|
+
constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { StandardOpenAPIHandler as a, StandardOpenAPIMatcher as c };
|
|
31
|
+
export type { StandardOpenAPIHandlerOptions as S, StandardOpenAPIMatcherOptions as b };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { TraverseContractProcedureCallbackOptions, AnyRouter, Context, Router } from '@orpc/server';
|
|
3
|
+
import { StandardMatcher, StandardMatchResult, StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
|
|
4
|
+
import { HTTPPath } from '@orpc/client';
|
|
5
|
+
import { Value } from '@orpc/shared';
|
|
6
|
+
|
|
7
|
+
interface StandardOpenAPIMatcherOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Filter procedures. Return `false` to exclude a procedure from matching.
|
|
10
|
+
*
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
|
14
|
+
}
|
|
15
|
+
declare class StandardOpenAPIMatcher implements StandardMatcher {
|
|
16
|
+
private readonly filter;
|
|
17
|
+
private readonly tree;
|
|
18
|
+
private pendingRouters;
|
|
19
|
+
constructor(options?: StandardOpenAPIMatcherOptions);
|
|
20
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
|
21
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions, StandardOpenAPIMatcherOptions {
|
|
25
|
+
}
|
|
26
|
+
declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
|
|
27
|
+
constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { StandardOpenAPIHandler as a, StandardOpenAPIMatcher as c };
|
|
31
|
+
export type { StandardOpenAPIHandlerOptions as S, StandardOpenAPIMatcherOptions as b };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { AnySchema, OpenAPI, AnyContractProcedure, AnyContractRouter } from '@orpc/contract';
|
|
2
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
3
|
+
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter } from '@orpc/server';
|
|
4
|
+
import { Promisable, Value } from '@orpc/shared';
|
|
5
|
+
import { JSONSchema } from '@orpc/interop/json-schema-typed/draft-2020-12';
|
|
6
|
+
|
|
7
|
+
interface SchemaConverterComponent {
|
|
8
|
+
allowedStrategies: readonly SchemaConvertOptions['strategy'][];
|
|
9
|
+
schema: AnySchema;
|
|
10
|
+
required: boolean;
|
|
11
|
+
ref: string;
|
|
12
|
+
}
|
|
13
|
+
interface SchemaConvertOptions {
|
|
14
|
+
strategy: 'input' | 'output';
|
|
15
|
+
/**
|
|
16
|
+
* Common components should use `$ref` to represent themselves if matched.
|
|
17
|
+
*/
|
|
18
|
+
components?: readonly SchemaConverterComponent[];
|
|
19
|
+
/**
|
|
20
|
+
* Minimum schema structure depth required before using `$ref` for components.
|
|
21
|
+
*
|
|
22
|
+
* For example, if set to 2, `$ref` will only be used for schemas nested at depth 2 or greater.
|
|
23
|
+
*
|
|
24
|
+
* @default 0 - No depth limit;
|
|
25
|
+
*/
|
|
26
|
+
minStructureDepthForRef?: number;
|
|
27
|
+
}
|
|
28
|
+
interface SchemaConverter {
|
|
29
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
30
|
+
}
|
|
31
|
+
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
32
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
33
|
+
}
|
|
34
|
+
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
35
|
+
private readonly converters;
|
|
36
|
+
constructor(converters: readonly ConditionalSchemaConverter[]);
|
|
37
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
|
41
|
+
schemaConverters?: ConditionalSchemaConverter[];
|
|
42
|
+
}
|
|
43
|
+
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
|
|
44
|
+
/**
|
|
45
|
+
* Exclude procedures from the OpenAPI specification.
|
|
46
|
+
*
|
|
47
|
+
* @deprecated Use `filter` option instead.
|
|
48
|
+
* @default () => false
|
|
49
|
+
*/
|
|
50
|
+
exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
53
|
+
*
|
|
54
|
+
* @default true
|
|
55
|
+
*/
|
|
56
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
|
57
|
+
/**
|
|
58
|
+
* Common schemas to be used for $ref resolution.
|
|
59
|
+
*/
|
|
60
|
+
commonSchemas?: Record<string, {
|
|
61
|
+
/**
|
|
62
|
+
* Determines which schema definition to use when input and output schemas differ.
|
|
63
|
+
* This is needed because some schemas transform data differently between input and output,
|
|
64
|
+
* making it impossible to use a single $ref for both cases.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* // This schema transforms a string input into a number output
|
|
69
|
+
* const Schema = z.string()
|
|
70
|
+
* .transform(v => Number(v))
|
|
71
|
+
* .pipe(z.number())
|
|
72
|
+
*
|
|
73
|
+
* // Input schema: { type: 'string' }
|
|
74
|
+
* // Output schema: { type: 'number' }
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* When schemas differ between input and output, you must explicitly choose
|
|
78
|
+
* which version to use for the OpenAPI specification.
|
|
79
|
+
*
|
|
80
|
+
* @default 'input' - Uses the input schema definition by default
|
|
81
|
+
*/
|
|
82
|
+
strategy?: SchemaConvertOptions['strategy'];
|
|
83
|
+
schema: AnySchema;
|
|
84
|
+
} | {
|
|
85
|
+
error: 'UndefinedError';
|
|
86
|
+
schema?: never;
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
93
|
+
*/
|
|
94
|
+
declare class OpenAPIGenerator {
|
|
95
|
+
#private;
|
|
96
|
+
private readonly serializer;
|
|
97
|
+
private readonly converter;
|
|
98
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
|
99
|
+
/**
|
|
100
|
+
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
101
|
+
*
|
|
102
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
103
|
+
*/
|
|
104
|
+
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { OpenAPIGenerator as b, CompositeSchemaConverter as e };
|
|
108
|
+
export type { ConditionalSchemaConverter as C, OpenAPIGeneratorOptions as O, SchemaConverterComponent as S, OpenAPIGeneratorGenerateOptions as a, SchemaConvertOptions as c, SchemaConverter as d };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { AnySchema, OpenAPI, AnyContractProcedure, AnyContractRouter } from '@orpc/contract';
|
|
2
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
|
3
|
+
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter } from '@orpc/server';
|
|
4
|
+
import { Promisable, Value } from '@orpc/shared';
|
|
5
|
+
import { JSONSchema } from '@orpc/interop/json-schema-typed/draft-2020-12';
|
|
6
|
+
|
|
7
|
+
interface SchemaConverterComponent {
|
|
8
|
+
allowedStrategies: readonly SchemaConvertOptions['strategy'][];
|
|
9
|
+
schema: AnySchema;
|
|
10
|
+
required: boolean;
|
|
11
|
+
ref: string;
|
|
12
|
+
}
|
|
13
|
+
interface SchemaConvertOptions {
|
|
14
|
+
strategy: 'input' | 'output';
|
|
15
|
+
/**
|
|
16
|
+
* Common components should use `$ref` to represent themselves if matched.
|
|
17
|
+
*/
|
|
18
|
+
components?: readonly SchemaConverterComponent[];
|
|
19
|
+
/**
|
|
20
|
+
* Minimum schema structure depth required before using `$ref` for components.
|
|
21
|
+
*
|
|
22
|
+
* For example, if set to 2, `$ref` will only be used for schemas nested at depth 2 or greater.
|
|
23
|
+
*
|
|
24
|
+
* @default 0 - No depth limit;
|
|
25
|
+
*/
|
|
26
|
+
minStructureDepthForRef?: number;
|
|
27
|
+
}
|
|
28
|
+
interface SchemaConverter {
|
|
29
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
30
|
+
}
|
|
31
|
+
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
32
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
33
|
+
}
|
|
34
|
+
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
35
|
+
private readonly converters;
|
|
36
|
+
constructor(converters: readonly ConditionalSchemaConverter[]);
|
|
37
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
|
41
|
+
schemaConverters?: ConditionalSchemaConverter[];
|
|
42
|
+
}
|
|
43
|
+
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
|
|
44
|
+
/**
|
|
45
|
+
* Exclude procedures from the OpenAPI specification.
|
|
46
|
+
*
|
|
47
|
+
* @deprecated Use `filter` option instead.
|
|
48
|
+
* @default () => false
|
|
49
|
+
*/
|
|
50
|
+
exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
53
|
+
*
|
|
54
|
+
* @default true
|
|
55
|
+
*/
|
|
56
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
|
57
|
+
/**
|
|
58
|
+
* Common schemas to be used for $ref resolution.
|
|
59
|
+
*/
|
|
60
|
+
commonSchemas?: Record<string, {
|
|
61
|
+
/**
|
|
62
|
+
* Determines which schema definition to use when input and output schemas differ.
|
|
63
|
+
* This is needed because some schemas transform data differently between input and output,
|
|
64
|
+
* making it impossible to use a single $ref for both cases.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* // This schema transforms a string input into a number output
|
|
69
|
+
* const Schema = z.string()
|
|
70
|
+
* .transform(v => Number(v))
|
|
71
|
+
* .pipe(z.number())
|
|
72
|
+
*
|
|
73
|
+
* // Input schema: { type: 'string' }
|
|
74
|
+
* // Output schema: { type: 'number' }
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* When schemas differ between input and output, you must explicitly choose
|
|
78
|
+
* which version to use for the OpenAPI specification.
|
|
79
|
+
*
|
|
80
|
+
* @default 'input' - Uses the input schema definition by default
|
|
81
|
+
*/
|
|
82
|
+
strategy?: SchemaConvertOptions['strategy'];
|
|
83
|
+
schema: AnySchema;
|
|
84
|
+
} | {
|
|
85
|
+
error: 'UndefinedError';
|
|
86
|
+
schema?: never;
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
93
|
+
*/
|
|
94
|
+
declare class OpenAPIGenerator {
|
|
95
|
+
#private;
|
|
96
|
+
private readonly serializer;
|
|
97
|
+
private readonly converter;
|
|
98
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
|
99
|
+
/**
|
|
100
|
+
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
101
|
+
*
|
|
102
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
103
|
+
*/
|
|
104
|
+
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { OpenAPIGenerator as b, CompositeSchemaConverter as e };
|
|
108
|
+
export type { ConditionalSchemaConverter as C, OpenAPIGeneratorOptions as O, SchemaConverterComponent as S, OpenAPIGeneratorGenerateOptions as a, SchemaConvertOptions as c, SchemaConverter as d };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.0a9a32d",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"import": "./dist/index.mjs",
|
|
20
20
|
"default": "./dist/index.mjs"
|
|
21
21
|
},
|
|
22
|
+
"./plugins": {
|
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
|
26
|
+
},
|
|
22
27
|
"./standard": {
|
|
23
28
|
"types": "./dist/adapters/standard/index.d.mts",
|
|
24
29
|
"import": "./dist/adapters/standard/index.mjs",
|
|
@@ -29,40 +34,32 @@
|
|
|
29
34
|
"import": "./dist/adapters/fetch/index.mjs",
|
|
30
35
|
"default": "./dist/adapters/fetch/index.mjs"
|
|
31
36
|
},
|
|
32
|
-
"./hono": {
|
|
33
|
-
"types": "./dist/adapters/hono/index.d.mts",
|
|
34
|
-
"import": "./dist/adapters/hono/index.mjs",
|
|
35
|
-
"default": "./dist/adapters/hono/index.mjs"
|
|
36
|
-
},
|
|
37
|
-
"./next": {
|
|
38
|
-
"types": "./dist/adapters/next/index.d.mts",
|
|
39
|
-
"import": "./dist/adapters/next/index.mjs",
|
|
40
|
-
"default": "./dist/adapters/next/index.mjs"
|
|
41
|
-
},
|
|
42
37
|
"./node": {
|
|
43
38
|
"types": "./dist/adapters/node/index.d.mts",
|
|
44
39
|
"import": "./dist/adapters/node/index.mjs",
|
|
45
40
|
"default": "./dist/adapters/node/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./aws-lambda": {
|
|
43
|
+
"types": "./dist/adapters/aws-lambda/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/aws-lambda/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/aws-lambda/index.mjs"
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"files": [
|
|
49
49
|
"dist"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"@orpc/
|
|
56
|
-
"@orpc/
|
|
57
|
-
"@orpc/
|
|
58
|
-
"@orpc/server": "0.0.0-next.
|
|
59
|
-
"@orpc/
|
|
60
|
-
"@orpc/standard-server": "0.0.0-next.09ec5b4",
|
|
61
|
-
"@orpc/standard-server-node": "0.0.0-next.09ec5b4",
|
|
62
|
-
"@orpc/standard-server-fetch": "0.0.0-next.09ec5b4"
|
|
52
|
+
"rou3": "^0.7.3",
|
|
53
|
+
"@orpc/client": "0.0.0-next.0a9a32d",
|
|
54
|
+
"@orpc/contract": "0.0.0-next.0a9a32d",
|
|
55
|
+
"@orpc/interop": "0.0.0-next.0a9a32d",
|
|
56
|
+
"@orpc/server": "0.0.0-next.0a9a32d",
|
|
57
|
+
"@orpc/shared": "0.0.0-next.0a9a32d",
|
|
58
|
+
"@orpc/standard-server": "0.0.0-next.0a9a32d",
|
|
59
|
+
"@orpc/openapi-client": "0.0.0-next.0a9a32d"
|
|
63
60
|
},
|
|
64
61
|
"devDependencies": {
|
|
65
|
-
"zod": "^
|
|
62
|
+
"zod": "^4.0.17"
|
|
66
63
|
},
|
|
67
64
|
"scripts": {
|
|
68
65
|
"build": "unbuild",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { O as OpenAPIHandler } from '../../shared/openapi.D0VMNR6V.mjs';
|
|
2
|
-
import '@orpc/server/standard';
|
|
3
|
-
import '@orpc/standard-server-fetch';
|
|
4
|
-
import '../../shared/openapi.CDsfPHgw.mjs';
|
|
5
|
-
import '@orpc/contract';
|
|
6
|
-
import '@orpc/openapi-client/standard';
|
|
7
|
-
import '@orpc/shared';
|
|
8
|
-
import '@orpc/server';
|
|
9
|
-
import 'rou3';
|
|
10
|
-
import '../../shared/openapi.BHG_gu5Z.mjs';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { O as OpenAPIHandler } from '../../shared/openapi.D0VMNR6V.mjs';
|
|
2
|
-
import '@orpc/server/standard';
|
|
3
|
-
import '@orpc/standard-server-fetch';
|
|
4
|
-
import '../../shared/openapi.CDsfPHgw.mjs';
|
|
5
|
-
import '@orpc/contract';
|
|
6
|
-
import '@orpc/openapi-client/standard';
|
|
7
|
-
import '@orpc/shared';
|
|
8
|
-
import '@orpc/server';
|
|
9
|
-
import 'rou3';
|
|
10
|
-
import '../../shared/openapi.BHG_gu5Z.mjs';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
function standardizeHTTPPath(path) {
|
|
2
|
-
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
3
|
-
}
|
|
4
|
-
function toOpenAPI31RoutePattern(path) {
|
|
5
|
-
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "{$1}");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { standardizeHTTPPath as s, toOpenAPI31RoutePattern as t };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { StandardHandler } from '@orpc/server/standard';
|
|
2
|
-
import { toStandardRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
|
3
|
-
import { a as OpenAPIMatcher, O as OpenAPICodec } from './openapi.CDsfPHgw.mjs';
|
|
4
|
-
|
|
5
|
-
class OpenAPIHandler {
|
|
6
|
-
standardHandler;
|
|
7
|
-
constructor(router, options) {
|
|
8
|
-
const matcher = options?.matcher ?? new OpenAPIMatcher();
|
|
9
|
-
const codec = options?.codec ?? new OpenAPICodec();
|
|
10
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
|
11
|
-
}
|
|
12
|
-
async handle(request, ...[options]) {
|
|
13
|
-
const standardRequest = toStandardRequest(request);
|
|
14
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
|
15
|
-
if (!result.matched) {
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
matched: true,
|
|
20
|
-
response: toFetchResponse(result.response, options)
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export { OpenAPIHandler as O };
|