@orpc/openapi 0.47.0 → 0.49.0
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 +5 -1
- package/dist/adapters/fetch/index.d.mts +4 -2
- package/dist/adapters/fetch/index.d.ts +4 -2
- package/dist/adapters/fetch/index.mjs +2 -2
- package/dist/adapters/hono/index.d.mts +2 -0
- package/dist/adapters/hono/index.d.ts +2 -0
- package/dist/adapters/hono/index.mjs +2 -2
- package/dist/adapters/next/index.d.mts +2 -0
- package/dist/adapters/next/index.d.ts +2 -0
- package/dist/adapters/next/index.mjs +2 -2
- package/dist/adapters/node/index.d.mts +4 -2
- package/dist/adapters/node/index.d.ts +4 -2
- package/dist/adapters/node/index.mjs +7 -5
- package/dist/adapters/standard/index.d.mts +7 -6
- package/dist/adapters/standard/index.d.ts +7 -6
- package/dist/adapters/standard/index.mjs +1 -1
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +6 -6
- package/dist/shared/{openapi.DFXD6scT.mjs → openapi.BNHmrMe2.mjs} +12 -15
- package/dist/shared/{openapi.C015V43J.mjs → openapi.Dv-KT_Bx.mjs} +7 -5
- package/dist/shared/openapi.IfmmOyba.d.mts +8 -0
- package/dist/shared/openapi.IfmmOyba.d.ts +8 -0
- package/package.json +9 -9
package/README.md
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
- **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
|
33
33
|
- **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
|
34
34
|
- **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
|
35
|
-
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
|
35
|
+
- **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
36
36
|
- **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
|
37
37
|
- **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
|
38
38
|
- **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
|
@@ -55,9 +55,13 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
55
55
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
56
56
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
57
57
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
58
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
59
|
+
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
58
60
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
59
61
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
60
62
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
63
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
64
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
61
65
|
|
62
66
|
## `@orpc/openapi`
|
63
67
|
|
@@ -1,12 +1,14 @@
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
2
2
|
import { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
|
3
|
-
import {
|
3
|
+
import { StandardHandleOptions } from '@orpc/server/standard';
|
4
4
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
5
5
|
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
6
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
|
7
|
+
import '@orpc/openapi-client/standard';
|
6
8
|
|
7
9
|
declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
8
10
|
private readonly standardHandler;
|
9
|
-
constructor(router: Router<
|
11
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
10
12
|
handle(request: Request, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
11
13
|
}
|
12
14
|
|
@@ -1,12 +1,14 @@
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
2
2
|
import { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
|
3
|
-
import {
|
3
|
+
import { StandardHandleOptions } from '@orpc/server/standard';
|
4
4
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
5
5
|
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
6
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
|
7
|
+
import '@orpc/openapi-client/standard';
|
6
8
|
|
7
9
|
declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
8
10
|
private readonly standardHandler;
|
9
|
-
constructor(router: Router<
|
11
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
10
12
|
handle(request: Request, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
11
13
|
}
|
12
14
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
export { O as OpenAPIHandler } from '../../shared/openapi.
|
1
|
+
export { O as OpenAPIHandler } from '../../shared/openapi.Dv-KT_Bx.mjs';
|
2
2
|
import '@orpc/openapi-client/standard';
|
3
3
|
import '@orpc/server/standard';
|
4
4
|
import '@orpc/standard-server-fetch';
|
5
|
-
import '../../shared/openapi.
|
5
|
+
import '../../shared/openapi.BNHmrMe2.mjs';
|
6
6
|
import '@orpc/contract';
|
7
7
|
import '@orpc/shared';
|
8
8
|
import '@orpc/server';
|
@@ -1,8 +1,8 @@
|
|
1
|
-
export { O as OpenAPIHandler } from '../../shared/openapi.
|
1
|
+
export { O as OpenAPIHandler } from '../../shared/openapi.Dv-KT_Bx.mjs';
|
2
2
|
import '@orpc/openapi-client/standard';
|
3
3
|
import '@orpc/server/standard';
|
4
4
|
import '@orpc/standard-server-fetch';
|
5
|
-
import '../../shared/openapi.
|
5
|
+
import '../../shared/openapi.BNHmrMe2.mjs';
|
6
6
|
import '@orpc/contract';
|
7
7
|
import '@orpc/shared';
|
8
8
|
import '@orpc/server';
|
@@ -1,8 +1,8 @@
|
|
1
|
-
export { O as OpenAPIHandler } from '../../shared/openapi.
|
1
|
+
export { O as OpenAPIHandler } from '../../shared/openapi.Dv-KT_Bx.mjs';
|
2
2
|
import '@orpc/openapi-client/standard';
|
3
3
|
import '@orpc/server/standard';
|
4
4
|
import '@orpc/standard-server-fetch';
|
5
|
-
import '../../shared/openapi.
|
5
|
+
import '../../shared/openapi.BNHmrMe2.mjs';
|
6
6
|
import '@orpc/contract';
|
7
7
|
import '@orpc/shared';
|
8
8
|
import '@orpc/server';
|
@@ -1,12 +1,14 @@
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
2
2
|
import { NodeHttpHandler, NodeHttpRequest, NodeHttpResponse, NodeHttpHandleResult } from '@orpc/server/node';
|
3
|
-
import {
|
3
|
+
import { StandardHandleOptions } from '@orpc/server/standard';
|
4
4
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
5
5
|
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
6
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
|
7
|
+
import '@orpc/openapi-client/standard';
|
6
8
|
|
7
9
|
declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
|
8
10
|
private readonly standardHandler;
|
9
|
-
constructor(router: Router<
|
11
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
10
12
|
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
11
13
|
}
|
12
14
|
|
@@ -1,12 +1,14 @@
|
|
1
1
|
import { Context, Router } from '@orpc/server';
|
2
2
|
import { NodeHttpHandler, NodeHttpRequest, NodeHttpResponse, NodeHttpHandleResult } from '@orpc/server/node';
|
3
|
-
import {
|
3
|
+
import { StandardHandleOptions } from '@orpc/server/standard';
|
4
4
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
5
5
|
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
6
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
|
7
|
+
import '@orpc/openapi-client/standard';
|
6
8
|
|
7
9
|
declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
|
8
10
|
private readonly standardHandler;
|
9
|
-
constructor(router: Router<
|
11
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T>>);
|
10
12
|
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options,]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
11
13
|
}
|
12
14
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import { StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
2
2
|
import { StandardHandler } from '@orpc/server/standard';
|
3
3
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
4
|
-
import { a as
|
4
|
+
import { a as StandardOpenAPIMatcher, S as StandardOpenAPICodec } from '../../shared/openapi.BNHmrMe2.mjs';
|
5
5
|
import '@orpc/shared';
|
6
6
|
import 'json-schema-typed/draft-2020-12';
|
7
7
|
import '@orpc/contract';
|
@@ -12,9 +12,11 @@ import '../../shared/openapi.DZzpQAb-.mjs';
|
|
12
12
|
class OpenAPIHandler {
|
13
13
|
standardHandler;
|
14
14
|
constructor(router, options = {}) {
|
15
|
-
const
|
16
|
-
const
|
17
|
-
const
|
15
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
16
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
17
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
18
|
+
const matcher = new StandardOpenAPIMatcher();
|
19
|
+
const codec = new StandardOpenAPICodec(serializer);
|
18
20
|
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
19
21
|
}
|
20
22
|
async handle(req, res, ...[
|
@@ -1,22 +1,23 @@
|
|
1
1
|
import { ORPCError } from '@orpc/client';
|
2
|
-
import {
|
2
|
+
import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
3
3
|
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
4
4
|
import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
|
+
export { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
|
6
7
|
import { HTTPPath } from '@orpc/contract';
|
7
8
|
|
8
|
-
declare class
|
9
|
+
declare class StandardOpenAPICodec implements StandardCodec {
|
9
10
|
private readonly serializer;
|
10
|
-
constructor(serializer:
|
11
|
+
constructor(serializer: StandardOpenAPISerializer);
|
11
12
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
12
13
|
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
13
14
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
14
15
|
}
|
15
16
|
|
16
|
-
declare class
|
17
|
+
declare class StandardOpenAPIMatcher implements StandardMatcher {
|
17
18
|
private readonly tree;
|
18
19
|
private pendingRouters;
|
19
|
-
init(router: AnyRouter, path?: string[]): void;
|
20
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
20
21
|
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
21
22
|
}
|
22
23
|
|
@@ -31,4 +32,4 @@ declare function toRou3Pattern(path: HTTPPath): string;
|
|
31
32
|
*/
|
32
33
|
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
33
34
|
|
34
|
-
export {
|
35
|
+
export { StandardOpenAPICodec, StandardOpenAPIMatcher, decodeParams, toRou3Pattern };
|
@@ -1,22 +1,23 @@
|
|
1
1
|
import { ORPCError } from '@orpc/client';
|
2
|
-
import {
|
2
|
+
import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
3
3
|
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
4
4
|
import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
|
+
export { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
|
6
7
|
import { HTTPPath } from '@orpc/contract';
|
7
8
|
|
8
|
-
declare class
|
9
|
+
declare class StandardOpenAPICodec implements StandardCodec {
|
9
10
|
private readonly serializer;
|
10
|
-
constructor(serializer:
|
11
|
+
constructor(serializer: StandardOpenAPISerializer);
|
11
12
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
12
13
|
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
13
14
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
14
15
|
}
|
15
16
|
|
16
|
-
declare class
|
17
|
+
declare class StandardOpenAPIMatcher implements StandardMatcher {
|
17
18
|
private readonly tree;
|
18
19
|
private pendingRouters;
|
19
|
-
init(router: AnyRouter, path?: string[]): void;
|
20
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
20
21
|
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
21
22
|
}
|
22
23
|
|
@@ -31,4 +32,4 @@ declare function toRou3Pattern(path: HTTPPath): string;
|
|
31
32
|
*/
|
32
33
|
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
33
34
|
|
34
|
-
export {
|
35
|
+
export { StandardOpenAPICodec, StandardOpenAPIMatcher, decodeParams, toRou3Pattern };
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export {
|
1
|
+
export { S as StandardOpenAPICodec, a as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.BNHmrMe2.mjs';
|
2
2
|
import '@orpc/contract';
|
3
3
|
import '@orpc/shared';
|
4
4
|
import '@orpc/server';
|
package/dist/index.d.mts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import { AnyContractProcedure,
|
1
|
+
import { AnyContractProcedure, AnySchema, AnyContractRouter, HTTPPath, HTTPMethod } from '@orpc/contract';
|
2
2
|
import { OpenAPIV3_1 } from 'openapi-types';
|
3
3
|
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
4
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
4
5
|
import { AnyRouter } from '@orpc/server';
|
5
6
|
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
6
7
|
export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
@@ -32,18 +33,18 @@ interface SchemaConvertOptions {
|
|
32
33
|
strategy: 'input' | 'output';
|
33
34
|
}
|
34
35
|
interface SchemaConverter {
|
35
|
-
convert(schema:
|
36
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
|
36
37
|
}
|
37
38
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
38
|
-
condition(schema:
|
39
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): boolean;
|
39
40
|
}
|
40
41
|
declare class CompositeSchemaConverter implements SchemaConverter {
|
41
42
|
private readonly converters;
|
42
43
|
constructor(converters: ConditionalSchemaConverter[]);
|
43
|
-
convert(schema:
|
44
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
|
44
45
|
}
|
45
46
|
|
46
|
-
interface OpenAPIGeneratorOptions {
|
47
|
+
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
47
48
|
schemaConverters?: ConditionalSchemaConverter[];
|
48
49
|
}
|
49
50
|
declare class OpenAPIGenerator {
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
import { AnyContractProcedure,
|
1
|
+
import { AnyContractProcedure, AnySchema, AnyContractRouter, HTTPPath, HTTPMethod } from '@orpc/contract';
|
2
2
|
import { OpenAPIV3_1 } from 'openapi-types';
|
3
3
|
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
4
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
4
5
|
import { AnyRouter } from '@orpc/server';
|
5
6
|
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
6
7
|
export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
@@ -32,18 +33,18 @@ interface SchemaConvertOptions {
|
|
32
33
|
strategy: 'input' | 'output';
|
33
34
|
}
|
34
35
|
interface SchemaConverter {
|
35
|
-
convert(schema:
|
36
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
|
36
37
|
}
|
37
38
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
38
|
-
condition(schema:
|
39
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): boolean;
|
39
40
|
}
|
40
41
|
declare class CompositeSchemaConverter implements SchemaConverter {
|
41
42
|
private readonly converters;
|
42
43
|
constructor(converters: ConditionalSchemaConverter[]);
|
43
|
-
convert(schema:
|
44
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
|
44
45
|
}
|
45
46
|
|
46
|
-
interface OpenAPIGeneratorOptions {
|
47
|
+
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
47
48
|
schemaConverters?: ConditionalSchemaConverter[];
|
48
49
|
}
|
49
50
|
declare class OpenAPIGenerator {
|
package/dist/index.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { isProcedure,
|
1
|
+
import { isProcedure, resolveContractProcedures, toHttpPath } from '@orpc/server';
|
2
2
|
import { fallbackORPCErrorStatus, fallbackORPCErrorMessage } from '@orpc/client';
|
3
3
|
import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@orpc/contract';
|
4
|
-
import {
|
4
|
+
import { StandardOpenAPIJsonSerializer } from '@orpc/openapi-client/standard';
|
5
5
|
import { clone } from '@orpc/shared';
|
6
6
|
import { t as toOpenAPIMethod, a as toOpenAPIPath, b as toOpenAPIEventIteratorContent, g as getDynamicParams, i as isAnySchema, c as isObjectSchema, d as separateObjectSchema, e as checkParamsSchema, f as toOpenAPIParameters, h as toOpenAPIContent, j as toOpenAPISchema } from './shared/openapi.DZzpQAb-.mjs';
|
7
7
|
export { L as LOGIC_KEYWORDS, l as filterSchemaBranches, k as isFileSchema, s as standardizeHTTPPath } from './shared/openapi.DZzpQAb-.mjs';
|
@@ -72,19 +72,19 @@ class OpenAPIGenerator {
|
|
72
72
|
serializer;
|
73
73
|
converter;
|
74
74
|
constructor(options = {}) {
|
75
|
-
this.serializer = new
|
75
|
+
this.serializer = new StandardOpenAPIJsonSerializer(options);
|
76
76
|
this.converter = new CompositeSchemaConverter(options.schemaConverters ?? []);
|
77
77
|
}
|
78
78
|
async generate(router, base) {
|
79
79
|
const doc = clone(base);
|
80
80
|
doc.openapi = "3.1.1";
|
81
81
|
const errors = [];
|
82
|
-
await
|
82
|
+
await resolveContractProcedures({ path: [], router }, ({ contract, path }) => {
|
83
83
|
const operationId = path.join(".");
|
84
84
|
try {
|
85
85
|
const def = contract["~orpc"];
|
86
86
|
const method = toOpenAPIMethod(fallbackContractConfig("defaultMethod", def.route.method));
|
87
|
-
const httpPath = toOpenAPIPath(def.route.path ??
|
87
|
+
const httpPath = toOpenAPIPath(def.route.path ?? toHttpPath(path));
|
88
88
|
const operationObjectRef = {
|
89
89
|
operationId,
|
90
90
|
summary: def.route.summary,
|
@@ -115,7 +115,7 @@ ${e.message}`
|
|
115
115
|
${errors.join("\n\n")}`
|
116
116
|
);
|
117
117
|
}
|
118
|
-
return this.serializer.serialize(doc);
|
118
|
+
return this.serializer.serialize(doc)[0];
|
119
119
|
}
|
120
120
|
#request(ref, def) {
|
121
121
|
const method = fallbackContractConfig("defaultMethod", def.route.method);
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { fallbackContractConfig } from '@orpc/contract';
|
2
2
|
import { isObject } from '@orpc/shared';
|
3
|
-
import {
|
3
|
+
import { traverseContractProcedures, toHttpPath, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
4
4
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
5
5
|
import { s as standardizeHTTPPath } from './openapi.DZzpQAb-.mjs';
|
6
6
|
|
7
|
-
class
|
7
|
+
class StandardOpenAPICodec {
|
8
8
|
constructor(serializer) {
|
9
9
|
this.serializer = serializer;
|
10
10
|
}
|
@@ -77,16 +77,13 @@ function decodeParams(params) {
|
|
77
77
|
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
|
78
78
|
}
|
79
79
|
|
80
|
-
class
|
80
|
+
class StandardOpenAPIMatcher {
|
81
81
|
tree = createRouter();
|
82
82
|
pendingRouters = [];
|
83
83
|
init(router, path = []) {
|
84
|
-
const laziedOptions =
|
85
|
-
router,
|
86
|
-
path
|
87
|
-
}, ({ path: path2, contract }) => {
|
84
|
+
const laziedOptions = traverseContractProcedures({ router, path }, ({ path: path2, contract }) => {
|
88
85
|
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
89
|
-
const httpPath =
|
86
|
+
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
90
87
|
if (isProcedure(contract)) {
|
91
88
|
addRoute(this.tree, method, httpPath, {
|
92
89
|
path: path2,
|
@@ -106,8 +103,8 @@ class OpenAPIMatcher {
|
|
106
103
|
});
|
107
104
|
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
108
105
|
...option,
|
109
|
-
httpPathPrefix:
|
110
|
-
laziedPrefix:
|
106
|
+
httpPathPrefix: toHttpPath(option.path),
|
107
|
+
laziedPrefix: getLazyMeta(option.router).prefix
|
111
108
|
})));
|
112
109
|
}
|
113
110
|
async match(method, pathname) {
|
@@ -115,7 +112,7 @@ class OpenAPIMatcher {
|
|
115
112
|
const newPendingRouters = [];
|
116
113
|
for (const pendingRouter of this.pendingRouters) {
|
117
114
|
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
118
|
-
const { default: router } = await unlazy(pendingRouter.
|
115
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
119
116
|
this.init(router, pendingRouter.path);
|
120
117
|
} else {
|
121
118
|
newPendingRouters.push(pendingRouter);
|
@@ -128,14 +125,14 @@ class OpenAPIMatcher {
|
|
128
125
|
return void 0;
|
129
126
|
}
|
130
127
|
if (!match.data.procedure) {
|
131
|
-
const { default: maybeProcedure } = await unlazy(
|
128
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
|
132
129
|
if (!isProcedure(maybeProcedure)) {
|
133
130
|
throw new Error(`
|
134
|
-
[Contract-First] Missing or invalid implementation for procedure at path: ${
|
131
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
|
135
132
|
Ensure that the procedure is correctly defined and matches the expected contract.
|
136
133
|
`);
|
137
134
|
}
|
138
|
-
match.data.procedure = createContractedProcedure(match.data.contract
|
135
|
+
match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
|
139
136
|
}
|
140
137
|
return {
|
141
138
|
path: match.data.path,
|
@@ -145,4 +142,4 @@ class OpenAPIMatcher {
|
|
145
142
|
}
|
146
143
|
}
|
147
144
|
|
148
|
-
export {
|
145
|
+
export { StandardOpenAPICodec as S, StandardOpenAPIMatcher as a, decodeParams as d, toRou3Pattern as t };
|
@@ -1,16 +1,18 @@
|
|
1
|
-
import {
|
1
|
+
import { StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
2
2
|
import { StandardHandler } from '@orpc/server/standard';
|
3
3
|
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
4
|
-
import { a as
|
4
|
+
import { a as StandardOpenAPIMatcher, S as StandardOpenAPICodec } from './openapi.BNHmrMe2.mjs';
|
5
5
|
import '@orpc/shared';
|
6
6
|
import 'json-schema-typed/draft-2020-12';
|
7
7
|
|
8
8
|
class OpenAPIHandler {
|
9
9
|
standardHandler;
|
10
10
|
constructor(router, options = {}) {
|
11
|
-
const
|
12
|
-
const
|
13
|
-
const
|
11
|
+
const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
|
12
|
+
const bracketNotationSerializer = new StandardBracketNotationSerializer();
|
13
|
+
const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
|
14
|
+
const matcher = new StandardOpenAPIMatcher();
|
15
|
+
const codec = new StandardOpenAPICodec(serializer);
|
14
16
|
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
15
17
|
}
|
16
18
|
async handle(request, ...[
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
2
|
+
import { Context } from '@orpc/server';
|
3
|
+
import { StandardHandlerOptions } from '@orpc/server/standard';
|
4
|
+
|
5
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardOpenAPIHandlerOptions as S };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
2
|
+
import { Context } from '@orpc/server';
|
3
|
+
import { StandardHandlerOptions } from '@orpc/server/standard';
|
4
|
+
|
5
|
+
interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardOpenAPIHandlerOptions as S };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/openapi",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.49.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -52,14 +52,14 @@
|
|
52
52
|
"json-schema-typed": "^8.0.1",
|
53
53
|
"openapi-types": "^12.1.3",
|
54
54
|
"rou3": "^0.5.1",
|
55
|
-
"@orpc/client": "0.
|
56
|
-
"@orpc/
|
57
|
-
"@orpc/
|
58
|
-
"@orpc/
|
59
|
-
"@orpc/
|
60
|
-
"@orpc/
|
61
|
-
"@orpc/standard-server-
|
62
|
-
"@orpc/standard-server": "0.
|
55
|
+
"@orpc/client": "0.49.0",
|
56
|
+
"@orpc/contract": "0.49.0",
|
57
|
+
"@orpc/openapi-client": "0.49.0",
|
58
|
+
"@orpc/server": "0.49.0",
|
59
|
+
"@orpc/shared": "0.49.0",
|
60
|
+
"@orpc/standard-server-fetch": "0.49.0",
|
61
|
+
"@orpc/standard-server-node": "0.49.0",
|
62
|
+
"@orpc/standard-server": "0.49.0"
|
63
63
|
},
|
64
64
|
"devDependencies": {
|
65
65
|
"zod": "^3.24.2"
|