@orpc/openapi 1.2.0 → 1.4.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 +1 -0
- package/dist/adapters/aws-lambda/index.d.mts +17 -0
- package/dist/adapters/aws-lambda/index.d.ts +17 -0
- package/dist/adapters/aws-lambda/index.mjs +18 -0
- package/dist/adapters/fetch/index.mjs +2 -1
- package/dist/adapters/node/index.mjs +2 -1
- package/dist/adapters/standard/index.d.mts +1 -0
- package/dist/adapters/standard/index.d.ts +1 -0
- package/dist/adapters/standard/index.mjs +2 -1
- package/dist/index.d.mts +22 -12
- package/dist/index.d.ts +22 -12
- package/dist/index.mjs +3 -3
- package/dist/plugins/index.d.mts +9 -10
- package/dist/plugins/index.d.ts +9 -10
- package/dist/plugins/index.mjs +1 -1
- package/dist/shared/{openapi.p5tsmBXx.mjs → openapi.C_UtQ8Us.mjs} +27 -6
- package/dist/shared/{openapi.fMEQd3Yd.mjs → openapi.DaYgbD_w.mjs} +150 -42
- package/dist/shared/{openapi.DP97kr00.d.mts → openapi.qZLdpE0a.d.mts} +10 -5
- package/dist/shared/{openapi.DP97kr00.d.ts → openapi.qZLdpE0a.d.ts} +10 -5
- package/package.json +13 -9
package/README.md
CHANGED
@@ -49,6 +49,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
49
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
50
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
51
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
52
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
|
52
53
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
53
54
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
54
55
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
2
|
+
import { AwsLambdaHandler, AwsLambdaHandlerOptions } from '@orpc/server/aws-lambda';
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
|
4
|
+
import '@orpc/openapi-client/standard';
|
5
|
+
import '@orpc/server/standard';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* OpenAPI Handler for AWS Lambda.
|
9
|
+
*
|
10
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
|
11
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
12
|
+
*/
|
13
|
+
declare class experimental_OpenAPIHandler<T extends Context> extends AwsLambdaHandler<T> {
|
14
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & AwsLambdaHandlerOptions>);
|
15
|
+
}
|
16
|
+
|
17
|
+
export { experimental_OpenAPIHandler };
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
2
|
+
import { AwsLambdaHandler, AwsLambdaHandlerOptions } from '@orpc/server/aws-lambda';
|
3
|
+
import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
|
4
|
+
import '@orpc/openapi-client/standard';
|
5
|
+
import '@orpc/server/standard';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* OpenAPI Handler for AWS Lambda.
|
9
|
+
*
|
10
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
|
11
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
12
|
+
*/
|
13
|
+
declare class experimental_OpenAPIHandler<T extends Context> extends AwsLambdaHandler<T> {
|
14
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & AwsLambdaHandlerOptions>);
|
15
|
+
}
|
16
|
+
|
17
|
+
export { experimental_OpenAPIHandler };
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { AwsLambdaHandler } from '@orpc/server/aws-lambda';
|
2
|
+
import '@orpc/client';
|
3
|
+
import '@orpc/contract';
|
4
|
+
import '@orpc/shared';
|
5
|
+
import { a as StandardOpenAPIHandler } from '../../shared/openapi.C_UtQ8Us.mjs';
|
6
|
+
import '@orpc/client/standard';
|
7
|
+
import '@orpc/server';
|
8
|
+
import 'rou3';
|
9
|
+
import '@orpc/openapi-client/standard';
|
10
|
+
import '@orpc/server/standard';
|
11
|
+
|
12
|
+
class experimental_OpenAPIHandler extends AwsLambdaHandler {
|
13
|
+
constructor(router, options = {}) {
|
14
|
+
super(new StandardOpenAPIHandler(router, options), options);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
export { experimental_OpenAPIHandler };
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { FetchHandler } from '@orpc/server/fetch';
|
2
|
+
import '@orpc/client';
|
2
3
|
import '@orpc/contract';
|
3
4
|
import '@orpc/shared';
|
4
|
-
import { a as StandardOpenAPIHandler } from '../../shared/openapi.
|
5
|
+
import { a as StandardOpenAPIHandler } from '../../shared/openapi.C_UtQ8Us.mjs';
|
5
6
|
import '@orpc/client/standard';
|
6
7
|
import '@orpc/server';
|
7
8
|
import 'rou3';
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { NodeHttpHandler } from '@orpc/server/node';
|
2
|
+
import '@orpc/client';
|
2
3
|
import '@orpc/contract';
|
3
4
|
import '@orpc/shared';
|
4
|
-
import { a as StandardOpenAPIHandler } from '../../shared/openapi.
|
5
|
+
import { a as StandardOpenAPIHandler } from '../../shared/openapi.C_UtQ8Us.mjs';
|
5
6
|
import '@orpc/client/standard';
|
6
7
|
import '@orpc/server';
|
7
8
|
import 'rou3';
|
@@ -6,6 +6,7 @@ import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
6
6
|
export { a as StandardOpenAPIHandler, S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
|
7
7
|
|
8
8
|
declare class StandardOpenAPICodec implements StandardCodec {
|
9
|
+
#private;
|
9
10
|
private readonly serializer;
|
10
11
|
constructor(serializer: StandardOpenAPISerializer);
|
11
12
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
@@ -6,6 +6,7 @@ import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
6
6
|
export { a as StandardOpenAPIHandler, S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
|
7
7
|
|
8
8
|
declare class StandardOpenAPICodec implements StandardCodec {
|
9
|
+
#private;
|
9
10
|
private readonly serializer;
|
10
11
|
constructor(serializer: StandardOpenAPISerializer);
|
11
12
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
@@ -1,6 +1,7 @@
|
|
1
|
-
export { S as StandardOpenAPICodec, a as StandardOpenAPIHandler, b as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.
|
1
|
+
export { S as StandardOpenAPICodec, a as StandardOpenAPIHandler, b as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.C_UtQ8Us.mjs';
|
2
2
|
import '@orpc/openapi-client/standard';
|
3
3
|
import '@orpc/server/standard';
|
4
|
+
import '@orpc/client';
|
4
5
|
import '@orpc/contract';
|
5
6
|
import '@orpc/shared';
|
6
7
|
import '@orpc/client/standard';
|
package/dist/index.d.mts
CHANGED
@@ -1,16 +1,15 @@
|
|
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.DP97kr00.mjs';
|
1
|
+
import { OpenAPI, AnyContractProcedure } from '@orpc/contract';
|
2
|
+
export { OpenAPI } from '@orpc/contract';
|
3
|
+
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.qZLdpE0a.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
|
*
|
@@ -18,7 +17,7 @@ type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current:
|
|
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,7 @@ 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;
|
69
68
|
|
70
69
|
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
70
|
|
@@ -90,10 +89,21 @@ declare function separateObjectSchema(schema: ObjectSchema, separatedProperties:
|
|
90
89
|
*/
|
91
90
|
declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
|
92
91
|
declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
|
92
|
+
/**
|
93
|
+
* Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
|
94
|
+
* recursively expands it into an array of its constituent, non-union base schemas.
|
95
|
+
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
96
|
+
*/
|
97
|
+
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
98
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
99
|
+
type: 'array';
|
100
|
+
items?: JSONSchema;
|
101
|
+
}];
|
102
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
93
103
|
|
94
104
|
declare const oo: {
|
95
105
|
spec: typeof customOpenAPIOperation;
|
96
106
|
};
|
97
107
|
|
98
|
-
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
108
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
99
109
|
export type { FileSchema, ObjectSchema, OverrideOperationValue };
|
package/dist/index.d.ts
CHANGED
@@ -1,16 +1,15 @@
|
|
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.DP97kr00.js';
|
1
|
+
import { OpenAPI, AnyContractProcedure } from '@orpc/contract';
|
2
|
+
export { OpenAPI } from '@orpc/contract';
|
3
|
+
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.qZLdpE0a.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
|
*
|
@@ -18,7 +17,7 @@ type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current:
|
|
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,7 @@ 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;
|
69
68
|
|
70
69
|
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
70
|
|
@@ -90,10 +89,21 @@ declare function separateObjectSchema(schema: ObjectSchema, separatedProperties:
|
|
90
89
|
*/
|
91
90
|
declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
|
92
91
|
declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
|
92
|
+
/**
|
93
|
+
* Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
|
94
|
+
* recursively expands it into an array of its constituent, non-union base schemas.
|
95
|
+
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
96
|
+
*/
|
97
|
+
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
98
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
99
|
+
type: 'array';
|
100
|
+
items?: JSONSchema;
|
101
|
+
}];
|
102
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
93
103
|
|
94
104
|
declare const oo: {
|
95
105
|
spec: typeof customOpenAPIOperation;
|
96
106
|
};
|
97
107
|
|
98
|
-
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
108
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
99
109
|
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, n as applySchemaOptionality, h as checkParamsSchema, m as filterSchemaBranches, g as getCustomOpenAPIOperation, l as isAnySchema, j as isFileSchema, k as isObjectSchema, s as separateObjectSchema, d as toOpenAPIContent, e as toOpenAPIEventIteratorContent, b as toOpenAPIMethod, f as toOpenAPIParameters, t as toOpenAPIPath, i as toOpenAPISchema } from './shared/openapi.
|
1
|
+
import { c as customOpenAPIOperation } from './shared/openapi.DaYgbD_w.mjs';
|
2
|
+
export { C as CompositeSchemaConverter, L as LOGIC_KEYWORDS, O as OpenAPIGenerator, a as applyCustomOpenAPIOperation, n as applySchemaOptionality, h as checkParamsSchema, p as expandArrayableSchema, o as expandUnionSchema, m as filterSchemaBranches, g as getCustomOpenAPIOperation, l as isAnySchema, j as isFileSchema, k as isObjectSchema, q as isPrimitiveSchema, s as separateObjectSchema, d as toOpenAPIContent, e as toOpenAPIEventIteratorContent, b as toOpenAPIMethod, f as toOpenAPIParameters, t as toOpenAPIPath, i as toOpenAPISchema } from './shared/openapi.DaYgbD_w.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
|
-
import { Value } from '@orpc/shared';
|
4
|
-
import {
|
5
|
-
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.DP97kr00.mjs';
|
6
|
-
import '@orpc/contract';
|
4
|
+
import { Value, Promisable } from '@orpc/shared';
|
5
|
+
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.qZLdpE0a.mjs';
|
7
6
|
import '@orpc/openapi-client/standard';
|
8
7
|
import 'json-schema-typed/draft-2020-12';
|
9
8
|
|
@@ -12,7 +11,7 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
12
11
|
* Options to pass to the OpenAPI generate.
|
13
12
|
*
|
14
13
|
*/
|
15
|
-
specGenerateOptions?: Value<OpenAPIGeneratorGenerateOptions
|
14
|
+
specGenerateOptions?: Value<Promisable<OpenAPIGeneratorGenerateOptions>, [StandardHandlerInterceptorOptions<T>]>;
|
16
15
|
/**
|
17
16
|
* The URL path at which to serve the OpenAPI JSON.
|
18
17
|
*
|
@@ -30,27 +29,27 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
30
29
|
*
|
31
30
|
* @default 'API Reference'
|
32
31
|
*/
|
33
|
-
docsTitle?: Value<string
|
32
|
+
docsTitle?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
34
33
|
/**
|
35
34
|
* Arbitrary configuration object for the UI.
|
36
35
|
*/
|
37
|
-
docsConfig?: Value<Record<string, unknown
|
36
|
+
docsConfig?: Value<Promisable<Record<string, unknown>>, [StandardHandlerInterceptorOptions<T>]>;
|
38
37
|
/**
|
39
38
|
* HTML to inject into the <head> of the docs page.
|
40
39
|
*
|
41
40
|
* @default ''
|
42
41
|
*/
|
43
|
-
docsHead?: Value<string
|
42
|
+
docsHead?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
44
43
|
/**
|
45
44
|
* URL of the external script bundle for the reference UI.
|
46
45
|
*
|
47
46
|
* @default 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
|
48
47
|
*/
|
49
|
-
docsScriptUrl?: Value<string
|
48
|
+
docsScriptUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
50
49
|
/**
|
51
50
|
* Override function to generate the full HTML for the docs page.
|
52
51
|
*/
|
53
|
-
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec:
|
52
|
+
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec: OpenAPI.Document) => string;
|
54
53
|
}
|
55
54
|
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
56
55
|
private readonly generator;
|
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
|
-
import { Value } from '@orpc/shared';
|
4
|
-
import {
|
5
|
-
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.DP97kr00.js';
|
6
|
-
import '@orpc/contract';
|
4
|
+
import { Value, Promisable } from '@orpc/shared';
|
5
|
+
import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.qZLdpE0a.js';
|
7
6
|
import '@orpc/openapi-client/standard';
|
8
7
|
import 'json-schema-typed/draft-2020-12';
|
9
8
|
|
@@ -12,7 +11,7 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
12
11
|
* Options to pass to the OpenAPI generate.
|
13
12
|
*
|
14
13
|
*/
|
15
|
-
specGenerateOptions?: Value<OpenAPIGeneratorGenerateOptions
|
14
|
+
specGenerateOptions?: Value<Promisable<OpenAPIGeneratorGenerateOptions>, [StandardHandlerInterceptorOptions<T>]>;
|
16
15
|
/**
|
17
16
|
* The URL path at which to serve the OpenAPI JSON.
|
18
17
|
*
|
@@ -30,27 +29,27 @@ interface OpenAPIReferencePluginOptions<T extends Context> extends OpenAPIGenera
|
|
30
29
|
*
|
31
30
|
* @default 'API Reference'
|
32
31
|
*/
|
33
|
-
docsTitle?: Value<string
|
32
|
+
docsTitle?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
34
33
|
/**
|
35
34
|
* Arbitrary configuration object for the UI.
|
36
35
|
*/
|
37
|
-
docsConfig?: Value<Record<string, unknown
|
36
|
+
docsConfig?: Value<Promisable<Record<string, unknown>>, [StandardHandlerInterceptorOptions<T>]>;
|
38
37
|
/**
|
39
38
|
* HTML to inject into the <head> of the docs page.
|
40
39
|
*
|
41
40
|
* @default ''
|
42
41
|
*/
|
43
|
-
docsHead?: Value<string
|
42
|
+
docsHead?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
44
43
|
/**
|
45
44
|
* URL of the external script bundle for the reference UI.
|
46
45
|
*
|
47
46
|
* @default 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'
|
48
47
|
*/
|
49
|
-
docsScriptUrl?: Value<string
|
48
|
+
docsScriptUrl?: Value<Promisable<string>, [StandardHandlerInterceptorOptions<T>]>;
|
50
49
|
/**
|
51
50
|
* Override function to generate the full HTML for the docs page.
|
52
51
|
*/
|
53
|
-
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec:
|
52
|
+
renderDocsHtml?: (specUrl: string, title: string, head: string, scriptUrl: string, config: Record<string, unknown> | undefined, spec: OpenAPI.Document) => string;
|
54
53
|
}
|
55
54
|
declare class OpenAPIReferencePlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
56
55
|
private readonly generator;
|
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.DaYgbD_w.mjs';
|
3
3
|
import '@orpc/client';
|
4
4
|
import '@orpc/client/standard';
|
5
5
|
import '@orpc/contract';
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
|
2
2
|
import { StandardHandler } from '@orpc/server/standard';
|
3
|
+
import { isORPCErrorStatus } from '@orpc/client';
|
3
4
|
import { fallbackContractConfig } from '@orpc/contract';
|
4
|
-
import { isObject } from '@orpc/shared';
|
5
|
+
import { isObject, stringifyJSON } from '@orpc/shared';
|
5
6
|
import { toHttpPath } from '@orpc/client/standard';
|
6
7
|
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
|
7
8
|
import { createRouter, addRoute, findRoute } from 'rou3';
|
@@ -52,13 +53,21 @@ class StandardOpenAPICodec {
|
|
52
53
|
body: this.serializer.serialize(output)
|
53
54
|
};
|
54
55
|
}
|
55
|
-
if (!
|
56
|
-
throw new Error(
|
57
|
-
|
58
|
-
|
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
|
+
`);
|
59
68
|
}
|
60
69
|
return {
|
61
|
-
status: successStatus,
|
70
|
+
status: output.status ?? successStatus,
|
62
71
|
headers: output.headers ?? {},
|
63
72
|
body: this.serializer.serialize(output.body)
|
64
73
|
};
|
@@ -70,6 +79,18 @@ class StandardOpenAPICodec {
|
|
70
79
|
body: this.serializer.serialize(error.toJSON(), { outputFormat: "plain" })
|
71
80
|
};
|
72
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
|
+
}
|
73
94
|
}
|
74
95
|
|
75
96
|
function toRou3Pattern(path) {
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import { fallbackORPCErrorStatus, fallbackORPCErrorMessage } from '@orpc/client';
|
1
|
+
import { isORPCErrorStatus, fallbackORPCErrorStatus, fallbackORPCErrorMessage } from '@orpc/client';
|
2
2
|
import { toHttpPath } from '@orpc/client/standard';
|
3
3
|
import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@orpc/contract';
|
4
4
|
import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, getDynamicParams } from '@orpc/openapi-client/standard';
|
5
5
|
import { isProcedure, resolveContractProcedures } from '@orpc/server';
|
6
|
-
import { isObject, findDeepMatches, toArray, clone } from '@orpc/shared';
|
7
|
-
import 'json-schema-typed/draft-2020-12';
|
6
|
+
import { isObject, stringifyJSON, findDeepMatches, toArray, clone } from '@orpc/shared';
|
7
|
+
import { TypeName } from 'json-schema-typed/draft-2020-12';
|
8
8
|
|
9
9
|
const OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
10
10
|
function customOpenAPIOperation(o, extend) {
|
@@ -184,6 +184,57 @@ function applySchemaOptionality(required, schema) {
|
|
184
184
|
]
|
185
185
|
};
|
186
186
|
}
|
187
|
+
function expandUnionSchema(schema) {
|
188
|
+
if (typeof schema === "object") {
|
189
|
+
for (const keyword of ["anyOf", "oneOf"]) {
|
190
|
+
if (schema[keyword] && Object.keys(schema).every(
|
191
|
+
(k) => k === keyword || !LOGIC_KEYWORDS.includes(k)
|
192
|
+
)) {
|
193
|
+
return schema[keyword].flatMap((s) => expandUnionSchema(s));
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
return [schema];
|
198
|
+
}
|
199
|
+
function expandArrayableSchema(schema) {
|
200
|
+
const schemas = expandUnionSchema(schema);
|
201
|
+
if (schemas.length !== 2) {
|
202
|
+
return void 0;
|
203
|
+
}
|
204
|
+
const arraySchema = schemas.find(
|
205
|
+
(s) => typeof s === "object" && s.type === "array" && Object.keys(s).filter((k) => LOGIC_KEYWORDS.includes(k)).every((k) => k === "type" || k === "items")
|
206
|
+
);
|
207
|
+
if (arraySchema === void 0) {
|
208
|
+
return void 0;
|
209
|
+
}
|
210
|
+
const items1 = arraySchema.items;
|
211
|
+
const items2 = schemas.find((s) => s !== arraySchema);
|
212
|
+
if (stringifyJSON(items1) !== stringifyJSON(items2)) {
|
213
|
+
return void 0;
|
214
|
+
}
|
215
|
+
return [items2, arraySchema];
|
216
|
+
}
|
217
|
+
const PRIMITIVE_SCHEMA_TYPES = /* @__PURE__ */ new Set([
|
218
|
+
TypeName.String,
|
219
|
+
TypeName.Number,
|
220
|
+
TypeName.Integer,
|
221
|
+
TypeName.Boolean,
|
222
|
+
TypeName.Null
|
223
|
+
]);
|
224
|
+
function isPrimitiveSchema(schema) {
|
225
|
+
return expandUnionSchema(schema).every((s) => {
|
226
|
+
if (typeof s === "boolean") {
|
227
|
+
return false;
|
228
|
+
}
|
229
|
+
if (typeof s.type === "string" && PRIMITIVE_SCHEMA_TYPES.has(s.type)) {
|
230
|
+
return true;
|
231
|
+
}
|
232
|
+
if (s.const !== void 0) {
|
233
|
+
return true;
|
234
|
+
}
|
235
|
+
return false;
|
236
|
+
});
|
237
|
+
}
|
187
238
|
|
188
239
|
function toOpenAPIPath(path) {
|
189
240
|
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/{$1}");
|
@@ -256,13 +307,26 @@ function toOpenAPIParameters(schema, parameterIn) {
|
|
256
307
|
const parameters = [];
|
257
308
|
for (const key in schema.properties) {
|
258
309
|
const keySchema = schema.properties[key];
|
310
|
+
let isDeepObjectStyle = true;
|
311
|
+
if (parameterIn !== "query") {
|
312
|
+
isDeepObjectStyle = false;
|
313
|
+
} else if (isPrimitiveSchema(keySchema)) {
|
314
|
+
isDeepObjectStyle = false;
|
315
|
+
} else {
|
316
|
+
const [item] = expandArrayableSchema(keySchema) ?? [];
|
317
|
+
if (item !== void 0 && isPrimitiveSchema(item)) {
|
318
|
+
isDeepObjectStyle = false;
|
319
|
+
}
|
320
|
+
}
|
259
321
|
parameters.push({
|
260
322
|
name: key,
|
261
323
|
in: parameterIn,
|
262
324
|
required: schema.required?.includes(key),
|
263
|
-
|
264
|
-
|
265
|
-
|
325
|
+
schema: toOpenAPISchema(keySchema),
|
326
|
+
style: isDeepObjectStyle ? "deepObject" : void 0,
|
327
|
+
explode: isDeepObjectStyle ? true : void 0,
|
328
|
+
allowEmptyValue: parameterIn === "query" ? true : void 0,
|
329
|
+
allowReserved: parameterIn === "query" ? true : void 0
|
266
330
|
});
|
267
331
|
}
|
268
332
|
return parameters;
|
@@ -312,14 +376,18 @@ class OpenAPIGenerator {
|
|
312
376
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
313
377
|
*/
|
314
378
|
async generate(router, options = {}) {
|
379
|
+
const exclude = options.exclude ?? (() => false);
|
315
380
|
const doc = {
|
316
381
|
...clone(options),
|
317
382
|
info: options.info ?? { title: "API Reference", version: "0.0.0" },
|
318
|
-
openapi: "3.1.1"
|
383
|
+
openapi: "3.1.1",
|
384
|
+
exclude: void 0
|
319
385
|
};
|
320
386
|
const contracts = [];
|
321
387
|
await resolveContractProcedures({ path: [], router }, ({ contract, path }) => {
|
322
|
-
|
388
|
+
if (!exclude(contract, path)) {
|
389
|
+
contracts.push({ contract, path });
|
390
|
+
}
|
323
391
|
});
|
324
392
|
const errors = [];
|
325
393
|
for (const { contract, path } of contracts) {
|
@@ -328,16 +396,21 @@ class OpenAPIGenerator {
|
|
328
396
|
const def = contract["~orpc"];
|
329
397
|
const method = toOpenAPIMethod(fallbackContractConfig("defaultMethod", def.route.method));
|
330
398
|
const httpPath = toOpenAPIPath(def.route.path ?? toHttpPath(path));
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
399
|
+
let operationObjectRef;
|
400
|
+
if (def.route.spec !== void 0) {
|
401
|
+
operationObjectRef = def.route.spec;
|
402
|
+
} else {
|
403
|
+
operationObjectRef = {
|
404
|
+
operationId,
|
405
|
+
summary: def.route.summary,
|
406
|
+
description: def.route.description,
|
407
|
+
deprecated: def.route.deprecated,
|
408
|
+
tags: def.route.tags?.map((tag) => tag)
|
409
|
+
};
|
410
|
+
await this.#request(operationObjectRef, def);
|
411
|
+
await this.#successResponse(operationObjectRef, def);
|
412
|
+
await this.#errorResponse(operationObjectRef, def);
|
413
|
+
}
|
341
414
|
doc.paths ??= {};
|
342
415
|
doc.paths[httpPath] ??= {};
|
343
416
|
doc.paths[httpPath][method] = applyCustomOpenAPIOperation(operationObjectRef, contract);
|
@@ -459,36 +532,71 @@ ${errors.join("\n\n")}`
|
|
459
532
|
return;
|
460
533
|
}
|
461
534
|
const [required, json] = await this.converter.convert(outputSchema, { strategy: "output" });
|
462
|
-
ref.responses ??= {};
|
463
|
-
ref.responses[status] = {
|
464
|
-
description
|
465
|
-
};
|
466
535
|
if (outputStructure === "compact") {
|
536
|
+
ref.responses ??= {};
|
537
|
+
ref.responses[status] = {
|
538
|
+
description
|
539
|
+
};
|
467
540
|
ref.responses[status].content = toOpenAPIContent(applySchemaOptionality(required, json));
|
468
541
|
return;
|
469
542
|
}
|
470
|
-
const
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
543
|
+
const handledStatuses = /* @__PURE__ */ new Set();
|
544
|
+
for (const item of expandUnionSchema(json)) {
|
545
|
+
const error = new OpenAPIGeneratorError(`
|
546
|
+
When output structure is "detailed", output schema must satisfy:
|
547
|
+
{
|
548
|
+
status?: number, // must be a literal number and in the range of 200-399
|
549
|
+
headers?: Record<string, unknown>,
|
550
|
+
body?: unknown
|
551
|
+
}
|
552
|
+
|
553
|
+
But got: ${stringifyJSON(item)}
|
554
|
+
`);
|
555
|
+
if (!isObjectSchema(item)) {
|
478
556
|
throw error;
|
479
557
|
}
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
}
|
558
|
+
let schemaStatus;
|
559
|
+
let schemaDescription;
|
560
|
+
if (item.properties?.status !== void 0) {
|
561
|
+
if (typeof item.properties.status !== "object" || item.properties.status.const === void 0 || typeof item.properties.status.const !== "number" || !Number.isInteger(item.properties.status.const) || isORPCErrorStatus(item.properties.status.const)) {
|
562
|
+
throw error;
|
563
|
+
}
|
564
|
+
schemaStatus = item.properties.status.const;
|
565
|
+
schemaDescription = item.properties.status.description;
|
566
|
+
}
|
567
|
+
const itemStatus = schemaStatus ?? status;
|
568
|
+
const itemDescription = schemaDescription ?? description;
|
569
|
+
if (handledStatuses.has(itemStatus)) {
|
570
|
+
throw new OpenAPIGeneratorError(`
|
571
|
+
When output structure is "detailed", each success status must be unique.
|
572
|
+
But got status: ${itemStatus} used more than once.
|
573
|
+
`);
|
574
|
+
}
|
575
|
+
handledStatuses.add(itemStatus);
|
576
|
+
ref.responses ??= {};
|
577
|
+
ref.responses[itemStatus] = {
|
578
|
+
description: itemDescription
|
579
|
+
};
|
580
|
+
if (item.properties?.headers !== void 0) {
|
581
|
+
if (!isObjectSchema(item.properties.headers)) {
|
582
|
+
throw error;
|
583
|
+
}
|
584
|
+
for (const key in item.properties.headers.properties) {
|
585
|
+
const headerSchema = item.properties.headers.properties[key];
|
586
|
+
if (headerSchema !== void 0) {
|
587
|
+
ref.responses[itemStatus].headers ??= {};
|
588
|
+
ref.responses[itemStatus].headers[key] = {
|
589
|
+
schema: toOpenAPISchema(headerSchema),
|
590
|
+
required: item.properties.headers.required?.includes(key)
|
591
|
+
};
|
592
|
+
}
|
593
|
+
}
|
594
|
+
}
|
595
|
+
if (item.properties?.body !== void 0) {
|
596
|
+
ref.responses[itemStatus].content = toOpenAPIContent(
|
597
|
+
applySchemaOptionality(item.required?.includes("body") ?? false, item.properties.body)
|
598
|
+
);
|
486
599
|
}
|
487
|
-
}
|
488
|
-
if (json.properties?.body !== void 0) {
|
489
|
-
ref.responses[status].content = toOpenAPIContent(
|
490
|
-
applySchemaOptionality(json.required?.includes("body") ?? false, json.properties.body)
|
491
|
-
);
|
492
600
|
}
|
493
601
|
}
|
494
602
|
async #errorResponse(ref, def) {
|
@@ -541,4 +649,4 @@ ${errors.join("\n\n")}`
|
|
541
649
|
}
|
542
650
|
}
|
543
651
|
|
544
|
-
export { CompositeSchemaConverter as C, LOGIC_KEYWORDS as L, OpenAPIGenerator as O, applyCustomOpenAPIOperation as a, toOpenAPIMethod as b, customOpenAPIOperation as c, toOpenAPIContent as d, toOpenAPIEventIteratorContent as e, toOpenAPIParameters as f, getCustomOpenAPIOperation as g, checkParamsSchema as h, toOpenAPISchema as i, isFileSchema as j, isObjectSchema as k, isAnySchema as l, filterSchemaBranches as m, applySchemaOptionality as n, separateObjectSchema as s, toOpenAPIPath as t };
|
652
|
+
export { CompositeSchemaConverter as C, LOGIC_KEYWORDS as L, OpenAPIGenerator as O, applyCustomOpenAPIOperation as a, toOpenAPIMethod as b, customOpenAPIOperation as c, toOpenAPIContent as d, toOpenAPIEventIteratorContent as e, toOpenAPIParameters as f, getCustomOpenAPIOperation as g, checkParamsSchema as h, toOpenAPISchema as i, isFileSchema as j, isObjectSchema as k, isAnySchema as l, filterSchemaBranches as m, applySchemaOptionality as n, expandUnionSchema as o, expandArrayableSchema as p, isPrimitiveSchema as q, separateObjectSchema as s, toOpenAPIPath as t };
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import { AnySchema, AnyContractRouter } from '@orpc/contract';
|
1
|
+
import { AnySchema, OpenAPI, AnyContractProcedure, AnyContractRouter } from '@orpc/contract';
|
2
2
|
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
3
|
-
import { AnyRouter } from '@orpc/server';
|
4
|
-
import { OpenAPIV3_1 } from 'openapi-types';
|
3
|
+
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
5
4
|
import { Promisable } from '@orpc/shared';
|
6
5
|
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
7
6
|
|
@@ -23,7 +22,13 @@ declare class CompositeSchemaConverter implements SchemaConverter {
|
|
23
22
|
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
24
23
|
schemaConverters?: ConditionalSchemaConverter[];
|
25
24
|
}
|
26
|
-
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<
|
25
|
+
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
|
26
|
+
/**
|
27
|
+
* Exclude procedures from the OpenAPI specification.
|
28
|
+
*
|
29
|
+
* @default () => false
|
30
|
+
*/
|
31
|
+
exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
|
27
32
|
}
|
28
33
|
/**
|
29
34
|
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
@@ -40,7 +45,7 @@ declare class OpenAPIGenerator {
|
|
40
45
|
*
|
41
46
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
42
47
|
*/
|
43
|
-
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<
|
48
|
+
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
44
49
|
}
|
45
50
|
|
46
51
|
export { OpenAPIGenerator as b, CompositeSchemaConverter as d };
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import { AnySchema, AnyContractRouter } from '@orpc/contract';
|
1
|
+
import { AnySchema, OpenAPI, AnyContractProcedure, AnyContractRouter } from '@orpc/contract';
|
2
2
|
import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
|
3
|
-
import { AnyRouter } from '@orpc/server';
|
4
|
-
import { OpenAPIV3_1 } from 'openapi-types';
|
3
|
+
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
5
4
|
import { Promisable } from '@orpc/shared';
|
6
5
|
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
7
6
|
|
@@ -23,7 +22,13 @@ declare class CompositeSchemaConverter implements SchemaConverter {
|
|
23
22
|
interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
|
24
23
|
schemaConverters?: ConditionalSchemaConverter[];
|
25
24
|
}
|
26
|
-
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<
|
25
|
+
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
|
26
|
+
/**
|
27
|
+
* Exclude procedures from the OpenAPI specification.
|
28
|
+
*
|
29
|
+
* @default () => false
|
30
|
+
*/
|
31
|
+
exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
|
27
32
|
}
|
28
33
|
/**
|
29
34
|
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
@@ -40,7 +45,7 @@ declare class OpenAPIGenerator {
|
|
40
45
|
*
|
41
46
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
42
47
|
*/
|
43
|
-
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<
|
48
|
+
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
44
49
|
}
|
45
50
|
|
46
51
|
export { OpenAPIGenerator as b, CompositeSchemaConverter as d };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/openapi",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.
|
4
|
+
"version": "1.4.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -38,6 +38,11 @@
|
|
38
38
|
"types": "./dist/adapters/node/index.d.mts",
|
39
39
|
"import": "./dist/adapters/node/index.mjs",
|
40
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"
|
41
46
|
}
|
42
47
|
},
|
43
48
|
"files": [
|
@@ -45,17 +50,16 @@
|
|
45
50
|
],
|
46
51
|
"dependencies": {
|
47
52
|
"json-schema-typed": "^8.0.1",
|
48
|
-
"openapi-types": "^12.1.3",
|
49
53
|
"rou3": "^0.6.0",
|
50
|
-
"@orpc/client": "1.
|
51
|
-
"@orpc/contract": "1.
|
52
|
-
"@orpc/
|
53
|
-
"@orpc/server": "1.
|
54
|
-
"@orpc/
|
55
|
-
"@orpc/
|
54
|
+
"@orpc/client": "1.4.0",
|
55
|
+
"@orpc/contract": "1.4.0",
|
56
|
+
"@orpc/shared": "1.4.0",
|
57
|
+
"@orpc/standard-server": "1.4.0",
|
58
|
+
"@orpc/openapi-client": "1.4.0",
|
59
|
+
"@orpc/server": "1.4.0"
|
56
60
|
},
|
57
61
|
"devDependencies": {
|
58
|
-
"zod": "^3.
|
62
|
+
"zod": "^3.25.49"
|
59
63
|
},
|
60
64
|
"scripts": {
|
61
65
|
"build": "unbuild",
|