@orpc/openapi 0.43.0 → 0.44.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 -1
- package/dist/adapters/fetch/index.d.mts +14 -0
- package/dist/adapters/fetch/index.d.ts +14 -0
- package/dist/adapters/fetch/index.mjs +10 -0
- package/dist/adapters/hono/index.d.mts +7 -0
- package/dist/adapters/hono/index.d.ts +7 -0
- package/dist/adapters/hono/index.mjs +10 -0
- package/dist/adapters/next/index.d.mts +7 -0
- package/dist/adapters/next/index.d.ts +7 -0
- package/dist/adapters/next/index.mjs +10 -0
- package/dist/adapters/node/index.d.mts +14 -0
- package/dist/adapters/node/index.d.ts +14 -0
- package/dist/adapters/node/index.mjs +29 -0
- package/dist/adapters/standard/index.d.mts +24 -0
- package/dist/adapters/standard/index.d.ts +24 -0
- package/dist/adapters/standard/index.mjs +7 -0
- package/dist/index.d.mts +169 -0
- package/dist/index.d.ts +169 -0
- package/dist/{index.js → index.mjs} +46 -86
- package/dist/{chunk-XGHV4TH3.js → shared/openapi.BHG_gu5Z.mjs} +1 -6
- package/dist/{chunk-LTTK3H5J.js → shared/openapi.CDsfPHgw.mjs} +12 -21
- package/dist/{chunk-PW7RAFQQ.js → shared/openapi.D0VMNR6V.mjs} +9 -16
- package/dist/shared/openapi.Dz_6xooR.d.mts +7 -0
- package/dist/shared/openapi.Dz_6xooR.d.ts +7 -0
- package/package.json +28 -32
- package/dist/fetch.js +0 -9
- package/dist/hono.js +0 -9
- package/dist/next.js +0 -9
- package/dist/node.js +0 -30
- package/dist/src/adapters/fetch/index.d.ts +0 -2
- package/dist/src/adapters/fetch/openapi-handler.d.ts +0 -11
- package/dist/src/adapters/hono/index.d.ts +0 -2
- package/dist/src/adapters/next/index.d.ts +0 -2
- package/dist/src/adapters/node/index.d.ts +0 -2
- package/dist/src/adapters/node/openapi-handler.d.ts +0 -11
- package/dist/src/adapters/standard/index.d.ts +0 -4
- package/dist/src/adapters/standard/openapi-codec.d.ts +0 -13
- package/dist/src/adapters/standard/openapi-handler.d.ts +0 -5
- package/dist/src/adapters/standard/openapi-matcher.d.ts +0 -10
- package/dist/src/index.d.ts +0 -16
- package/dist/src/openapi-content-builder.d.ts +0 -10
- package/dist/src/openapi-error.d.ts +0 -3
- package/dist/src/openapi-generator.d.ts +0 -67
- package/dist/src/openapi-input-structure-parser.d.ts +0 -22
- package/dist/src/openapi-operation-extender.d.ts +0 -7
- package/dist/src/openapi-output-structure-parser.d.ts +0 -18
- package/dist/src/openapi-parameters-builder.d.ts +0 -12
- package/dist/src/openapi-path-parser.d.ts +0 -8
- package/dist/src/openapi.d.ts +0 -3
- package/dist/src/schema-converter.d.ts +0 -16
- package/dist/src/schema-utils.d.ts +0 -11
- package/dist/src/schema.d.ts +0 -12
- package/dist/src/utils.d.ts +0 -4
- package/dist/standard.js +0 -10
package/README.md
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
2
|
+
import { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
|
3
|
+
import { StandardHandleOptions } from '@orpc/server/standard';
|
4
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
5
|
+
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
6
|
+
import { O as OpenAPIHandlerOptions } from '../../shared/openapi.Dz_6xooR.mjs';
|
7
|
+
|
8
|
+
declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
9
|
+
private readonly standardHandler;
|
10
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
11
|
+
handle(request: Request, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
12
|
+
}
|
13
|
+
|
14
|
+
export { OpenAPIHandler };
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
2
|
+
import { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
|
3
|
+
import { StandardHandleOptions } from '@orpc/server/standard';
|
4
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
5
|
+
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
6
|
+
import { O as OpenAPIHandlerOptions } from '../../shared/openapi.Dz_6xooR.js';
|
7
|
+
|
8
|
+
declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
9
|
+
private readonly standardHandler;
|
10
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
11
|
+
handle(request: Request, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T> & ToFetchResponseOptions>): Promise<FetchHandleResult>;
|
12
|
+
}
|
13
|
+
|
14
|
+
export { OpenAPIHandler };
|
@@ -0,0 +1,10 @@
|
|
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';
|
@@ -0,0 +1,10 @@
|
|
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';
|
@@ -0,0 +1,10 @@
|
|
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';
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
2
|
+
import { NodeHttpHandler, NodeHttpRequest, NodeHttpResponse, NodeHttpHandleResult } from '@orpc/server/node';
|
3
|
+
import { StandardHandleOptions } from '@orpc/server/standard';
|
4
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
5
|
+
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
6
|
+
import { O as OpenAPIHandlerOptions } from '../../shared/openapi.Dz_6xooR.mjs';
|
7
|
+
|
8
|
+
declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
|
9
|
+
private readonly standardHandler;
|
10
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
11
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
12
|
+
}
|
13
|
+
|
14
|
+
export { OpenAPIHandler };
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Context, Router } from '@orpc/server';
|
2
|
+
import { NodeHttpHandler, NodeHttpRequest, NodeHttpResponse, NodeHttpHandleResult } from '@orpc/server/node';
|
3
|
+
import { StandardHandleOptions } from '@orpc/server/standard';
|
4
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
5
|
+
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
6
|
+
import { O as OpenAPIHandlerOptions } from '../../shared/openapi.Dz_6xooR.js';
|
7
|
+
|
8
|
+
declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
|
9
|
+
private readonly standardHandler;
|
10
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
11
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T> & SendStandardResponseOptions>): Promise<NodeHttpHandleResult>;
|
12
|
+
}
|
13
|
+
|
14
|
+
export { OpenAPIHandler };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { StandardHandler } from '@orpc/server/standard';
|
2
|
+
import { toStandardRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
3
|
+
import { a as OpenAPIMatcher, O as OpenAPICodec } from '../../shared/openapi.CDsfPHgw.mjs';
|
4
|
+
import '@orpc/contract';
|
5
|
+
import '@orpc/openapi-client/standard';
|
6
|
+
import '@orpc/shared';
|
7
|
+
import '@orpc/server';
|
8
|
+
import 'rou3';
|
9
|
+
import '../../shared/openapi.BHG_gu5Z.mjs';
|
10
|
+
|
11
|
+
class OpenAPIHandler {
|
12
|
+
standardHandler;
|
13
|
+
constructor(router, options) {
|
14
|
+
const matcher = options?.matcher ?? new OpenAPIMatcher();
|
15
|
+
const codec = options?.codec ?? new OpenAPICodec();
|
16
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, { ...options });
|
17
|
+
}
|
18
|
+
async handle(req, res, ...[options]) {
|
19
|
+
const standardRequest = toStandardRequest(req, res);
|
20
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
21
|
+
if (!result.matched) {
|
22
|
+
return { matched: false };
|
23
|
+
}
|
24
|
+
await sendStandardResponse(res, result.response, options);
|
25
|
+
return { matched: true };
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
export { OpenAPIHandler };
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
2
|
+
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
3
|
+
import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
4
|
+
import { StandardRequest, StandardResponse } from '@orpc/standard-server';
|
5
|
+
import { OpenAPISerializer } from '@orpc/openapi-client/standard';
|
6
|
+
export { O as OpenAPIHandlerOptions } from '../../shared/openapi.Dz_6xooR.mjs';
|
7
|
+
import { HTTPPath } from '@orpc/contract';
|
8
|
+
|
9
|
+
declare class OpenAPICodec implements StandardCodec {
|
10
|
+
private readonly serializer;
|
11
|
+
constructor(serializer?: OpenAPISerializer);
|
12
|
+
decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
13
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
14
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
15
|
+
}
|
16
|
+
|
17
|
+
declare class OpenAPIMatcher implements StandardMatcher {
|
18
|
+
private readonly tree;
|
19
|
+
private pendingRouters;
|
20
|
+
init(router: AnyRouter, path?: string[]): void;
|
21
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
22
|
+
}
|
23
|
+
|
24
|
+
export { OpenAPICodec, OpenAPIMatcher };
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
2
|
+
import { AnyProcedure, AnyRouter } from '@orpc/server';
|
3
|
+
import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
4
|
+
import { StandardRequest, StandardResponse } from '@orpc/standard-server';
|
5
|
+
import { OpenAPISerializer } from '@orpc/openapi-client/standard';
|
6
|
+
export { O as OpenAPIHandlerOptions } from '../../shared/openapi.Dz_6xooR.js';
|
7
|
+
import { HTTPPath } from '@orpc/contract';
|
8
|
+
|
9
|
+
declare class OpenAPICodec implements StandardCodec {
|
10
|
+
private readonly serializer;
|
11
|
+
constructor(serializer?: OpenAPISerializer);
|
12
|
+
decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
13
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
14
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
15
|
+
}
|
16
|
+
|
17
|
+
declare class OpenAPIMatcher implements StandardMatcher {
|
18
|
+
private readonly tree;
|
19
|
+
private pendingRouters;
|
20
|
+
init(router: AnyRouter, path?: string[]): void;
|
21
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
22
|
+
}
|
23
|
+
|
24
|
+
export { OpenAPICodec, OpenAPIMatcher };
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export { O as OpenAPICodec, a as OpenAPIMatcher } from '../../shared/openapi.CDsfPHgw.mjs';
|
2
|
+
import '@orpc/contract';
|
3
|
+
import '@orpc/openapi-client/standard';
|
4
|
+
import '@orpc/shared';
|
5
|
+
import '@orpc/server';
|
6
|
+
import 'rou3';
|
7
|
+
import '../../shared/openapi.BHG_gu5Z.mjs';
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
import { AnyContractProcedure, Schema, ContractRouter, HTTPPath } from '@orpc/contract';
|
2
|
+
import * as OpenAPI from 'openapi3-ts/oas31';
|
3
|
+
export { OpenAPI };
|
4
|
+
export { OpenApiBuilder } from 'openapi3-ts/oas31';
|
5
|
+
import * as JSONSchema from 'json-schema-typed/draft-2020-12';
|
6
|
+
export { JSONSchema };
|
7
|
+
export { Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
8
|
+
import { OpenAPIJsonSerializer } from '@orpc/openapi-client/standard';
|
9
|
+
import { AnyRouter } from '@orpc/server';
|
10
|
+
|
11
|
+
type OverrideOperationValue = OpenAPI.OperationObject | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
12
|
+
declare function setOperationExtender<T extends object>(o: T, extend: OverrideOperationValue): T;
|
13
|
+
declare function getOperationExtender(o: object): OverrideOperationValue | undefined;
|
14
|
+
declare function extendOperation(operation: OpenAPI.OperationObject, procedure: AnyContractProcedure): OpenAPI.OperationObject;
|
15
|
+
|
16
|
+
type ObjectSchema = JSONSchema.JSONSchema & {
|
17
|
+
type: 'object';
|
18
|
+
} & object;
|
19
|
+
type FileSchema = JSONSchema.JSONSchema & {
|
20
|
+
type: 'string';
|
21
|
+
contentMediaType: string;
|
22
|
+
} & object;
|
23
|
+
declare const NON_LOGIC_KEYWORDS: string[];
|
24
|
+
|
25
|
+
declare class SchemaUtils {
|
26
|
+
isFileSchema(schema: JSONSchema.JSONSchema): schema is FileSchema;
|
27
|
+
isObjectSchema(schema: JSONSchema.JSONSchema): schema is ObjectSchema;
|
28
|
+
isAnySchema(schema: JSONSchema.JSONSchema): boolean;
|
29
|
+
isUndefinableSchema(schema: JSONSchema.JSONSchema): boolean;
|
30
|
+
separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
31
|
+
filterSchemaBranches(schema: JSONSchema.JSONSchema, check: (schema: JSONSchema.JSONSchema) => boolean, matches?: JSONSchema.JSONSchema[]): [matches: JSONSchema.JSONSchema[], rest: JSONSchema.JSONSchema | undefined];
|
32
|
+
}
|
33
|
+
type PublicSchemaUtils = Pick<SchemaUtils, keyof SchemaUtils>;
|
34
|
+
|
35
|
+
declare class OpenAPIContentBuilder {
|
36
|
+
private readonly schemaUtils;
|
37
|
+
constructor(schemaUtils: PublicSchemaUtils);
|
38
|
+
build(jsonSchema: JSONSchema.JSONSchema, options?: Partial<OpenAPI.MediaTypeObject>): OpenAPI.ContentObject;
|
39
|
+
}
|
40
|
+
type PublicOpenAPIContentBuilder = Pick<OpenAPIContentBuilder, keyof OpenAPIContentBuilder>;
|
41
|
+
|
42
|
+
declare class OpenAPIPathParser {
|
43
|
+
parseDynamicParams(path: string): {
|
44
|
+
name: string;
|
45
|
+
raw: string;
|
46
|
+
}[];
|
47
|
+
}
|
48
|
+
type PublicOpenAPIPathParser = Pick<OpenAPIPathParser, keyof OpenAPIPathParser>;
|
49
|
+
|
50
|
+
interface SchemaConvertOptions {
|
51
|
+
strategy: 'input' | 'output';
|
52
|
+
}
|
53
|
+
interface SchemaConverter {
|
54
|
+
condition(schema: Schema, options: SchemaConvertOptions): boolean;
|
55
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
56
|
+
}
|
57
|
+
declare class CompositeSchemaConverter implements SchemaConverter {
|
58
|
+
private readonly converters;
|
59
|
+
constructor(converters: SchemaConverter[]);
|
60
|
+
condition(): boolean;
|
61
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
62
|
+
}
|
63
|
+
|
64
|
+
interface OpenAPIInputStructureParseResult {
|
65
|
+
paramsSchema: ObjectSchema | undefined;
|
66
|
+
querySchema: ObjectSchema | undefined;
|
67
|
+
headersSchema: ObjectSchema | undefined;
|
68
|
+
bodySchema: JSONSchema.JSONSchema | undefined;
|
69
|
+
}
|
70
|
+
declare class OpenAPIInputStructureParser {
|
71
|
+
private readonly schemaConverter;
|
72
|
+
private readonly schemaUtils;
|
73
|
+
private readonly pathParser;
|
74
|
+
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils, pathParser: PublicOpenAPIPathParser);
|
75
|
+
parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIInputStructureParseResult;
|
76
|
+
private parseDetailedSchema;
|
77
|
+
private parseCompactSchema;
|
78
|
+
}
|
79
|
+
type PublicOpenAPIInputStructureParser = Pick<OpenAPIInputStructureParser, keyof OpenAPIInputStructureParser>;
|
80
|
+
|
81
|
+
interface OpenAPIOutputStructureParseResult {
|
82
|
+
headersSchema: ObjectSchema | undefined;
|
83
|
+
bodySchema: JSONSchema.JSONSchema | undefined;
|
84
|
+
}
|
85
|
+
declare class OpenAPIOutputStructureParser {
|
86
|
+
private readonly schemaConverter;
|
87
|
+
private readonly schemaUtils;
|
88
|
+
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils);
|
89
|
+
parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIOutputStructureParseResult;
|
90
|
+
private parseDetailedSchema;
|
91
|
+
private parseCompactSchema;
|
92
|
+
}
|
93
|
+
type PublicOpenAPIOutputStructureParser = Pick<OpenAPIOutputStructureParser, keyof OpenAPIOutputStructureParser>;
|
94
|
+
|
95
|
+
declare class OpenAPIParametersBuilder {
|
96
|
+
build(paramIn: OpenAPI.ParameterObject['in'], jsonSchema: JSONSchema.JSONSchema & {
|
97
|
+
type: 'object';
|
98
|
+
} & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.ParameterObject[];
|
99
|
+
buildHeadersObject(jsonSchema: JSONSchema.JSONSchema & {
|
100
|
+
type: 'object';
|
101
|
+
} & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.HeadersObject;
|
102
|
+
}
|
103
|
+
type PublicOpenAPIParametersBuilder = Pick<OpenAPIParametersBuilder, keyof OpenAPIParametersBuilder>;
|
104
|
+
|
105
|
+
type ErrorHandlerStrategy = 'throw' | 'log' | 'ignore';
|
106
|
+
interface OpenAPIGeneratorOptions {
|
107
|
+
contentBuilder?: PublicOpenAPIContentBuilder;
|
108
|
+
parametersBuilder?: PublicOpenAPIParametersBuilder;
|
109
|
+
schemaConverters?: SchemaConverter[];
|
110
|
+
schemaUtils?: PublicSchemaUtils;
|
111
|
+
jsonSerializer?: OpenAPIJsonSerializer;
|
112
|
+
pathParser?: PublicOpenAPIPathParser;
|
113
|
+
inputStructureParser?: PublicOpenAPIInputStructureParser;
|
114
|
+
outputStructureParser?: PublicOpenAPIOutputStructureParser;
|
115
|
+
/**
|
116
|
+
* Throw error when you missing define tag definition on OpenAPI root tags
|
117
|
+
*
|
118
|
+
* Example: if procedure has tags ['foo', 'bar'], and OpenAPI root tags is ['foo'], then error will be thrown
|
119
|
+
* Because OpenAPI root tags is missing 'bar' tag
|
120
|
+
*
|
121
|
+
* @default false
|
122
|
+
*/
|
123
|
+
considerMissingTagDefinitionAsError?: boolean;
|
124
|
+
/**
|
125
|
+
* Weather ignore procedures that has no path defined.
|
126
|
+
*
|
127
|
+
* @default false
|
128
|
+
*/
|
129
|
+
ignoreUndefinedPathProcedures?: boolean;
|
130
|
+
/**
|
131
|
+
* What to do when we found an error with our router
|
132
|
+
*
|
133
|
+
* @default 'throw'
|
134
|
+
*/
|
135
|
+
errorHandlerStrategy?: ErrorHandlerStrategy;
|
136
|
+
/**
|
137
|
+
* Strict error response
|
138
|
+
*
|
139
|
+
* @default true
|
140
|
+
*/
|
141
|
+
strictErrorResponses?: boolean;
|
142
|
+
}
|
143
|
+
declare class OpenAPIGenerator {
|
144
|
+
private readonly contentBuilder;
|
145
|
+
private readonly parametersBuilder;
|
146
|
+
private readonly schemaConverter;
|
147
|
+
private readonly schemaUtils;
|
148
|
+
private readonly jsonSerializer;
|
149
|
+
private readonly pathParser;
|
150
|
+
private readonly inputStructureParser;
|
151
|
+
private readonly outputStructureParser;
|
152
|
+
private readonly errorHandlerStrategy;
|
153
|
+
private readonly ignoreUndefinedPathProcedures;
|
154
|
+
private readonly considerMissingTagDefinitionAsError;
|
155
|
+
private readonly strictErrorResponses;
|
156
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
157
|
+
generate(router: ContractRouter<any> | AnyRouter, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
|
158
|
+
}
|
159
|
+
|
160
|
+
declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
161
|
+
declare function toOpenAPI31RoutePattern(path: HTTPPath): string;
|
162
|
+
|
163
|
+
/** unnoq */
|
164
|
+
|
165
|
+
declare const oo: {
|
166
|
+
spec: typeof setOperationExtender;
|
167
|
+
};
|
168
|
+
|
169
|
+
export { CompositeSchemaConverter, type FileSchema, NON_LOGIC_KEYWORDS, type ObjectSchema, OpenAPIContentBuilder, OpenAPIGenerator, type OpenAPIGeneratorOptions, OpenAPIParametersBuilder, OpenAPIPathParser, type OverrideOperationValue, type PublicOpenAPIContentBuilder, type PublicOpenAPIParametersBuilder, type PublicOpenAPIPathParser, type PublicSchemaUtils, type SchemaConvertOptions, type SchemaConverter, SchemaUtils, extendOperation, getOperationExtender, oo, setOperationExtender, standardizeHTTPPath, toOpenAPI31RoutePattern };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
import { AnyContractProcedure, Schema, ContractRouter, HTTPPath } from '@orpc/contract';
|
2
|
+
import * as OpenAPI from 'openapi3-ts/oas31';
|
3
|
+
export { OpenAPI };
|
4
|
+
export { OpenApiBuilder } from 'openapi3-ts/oas31';
|
5
|
+
import * as JSONSchema from 'json-schema-typed/draft-2020-12';
|
6
|
+
export { JSONSchema };
|
7
|
+
export { Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
|
8
|
+
import { OpenAPIJsonSerializer } from '@orpc/openapi-client/standard';
|
9
|
+
import { AnyRouter } from '@orpc/server';
|
10
|
+
|
11
|
+
type OverrideOperationValue = OpenAPI.OperationObject | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
12
|
+
declare function setOperationExtender<T extends object>(o: T, extend: OverrideOperationValue): T;
|
13
|
+
declare function getOperationExtender(o: object): OverrideOperationValue | undefined;
|
14
|
+
declare function extendOperation(operation: OpenAPI.OperationObject, procedure: AnyContractProcedure): OpenAPI.OperationObject;
|
15
|
+
|
16
|
+
type ObjectSchema = JSONSchema.JSONSchema & {
|
17
|
+
type: 'object';
|
18
|
+
} & object;
|
19
|
+
type FileSchema = JSONSchema.JSONSchema & {
|
20
|
+
type: 'string';
|
21
|
+
contentMediaType: string;
|
22
|
+
} & object;
|
23
|
+
declare const NON_LOGIC_KEYWORDS: string[];
|
24
|
+
|
25
|
+
declare class SchemaUtils {
|
26
|
+
isFileSchema(schema: JSONSchema.JSONSchema): schema is FileSchema;
|
27
|
+
isObjectSchema(schema: JSONSchema.JSONSchema): schema is ObjectSchema;
|
28
|
+
isAnySchema(schema: JSONSchema.JSONSchema): boolean;
|
29
|
+
isUndefinableSchema(schema: JSONSchema.JSONSchema): boolean;
|
30
|
+
separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
31
|
+
filterSchemaBranches(schema: JSONSchema.JSONSchema, check: (schema: JSONSchema.JSONSchema) => boolean, matches?: JSONSchema.JSONSchema[]): [matches: JSONSchema.JSONSchema[], rest: JSONSchema.JSONSchema | undefined];
|
32
|
+
}
|
33
|
+
type PublicSchemaUtils = Pick<SchemaUtils, keyof SchemaUtils>;
|
34
|
+
|
35
|
+
declare class OpenAPIContentBuilder {
|
36
|
+
private readonly schemaUtils;
|
37
|
+
constructor(schemaUtils: PublicSchemaUtils);
|
38
|
+
build(jsonSchema: JSONSchema.JSONSchema, options?: Partial<OpenAPI.MediaTypeObject>): OpenAPI.ContentObject;
|
39
|
+
}
|
40
|
+
type PublicOpenAPIContentBuilder = Pick<OpenAPIContentBuilder, keyof OpenAPIContentBuilder>;
|
41
|
+
|
42
|
+
declare class OpenAPIPathParser {
|
43
|
+
parseDynamicParams(path: string): {
|
44
|
+
name: string;
|
45
|
+
raw: string;
|
46
|
+
}[];
|
47
|
+
}
|
48
|
+
type PublicOpenAPIPathParser = Pick<OpenAPIPathParser, keyof OpenAPIPathParser>;
|
49
|
+
|
50
|
+
interface SchemaConvertOptions {
|
51
|
+
strategy: 'input' | 'output';
|
52
|
+
}
|
53
|
+
interface SchemaConverter {
|
54
|
+
condition(schema: Schema, options: SchemaConvertOptions): boolean;
|
55
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
56
|
+
}
|
57
|
+
declare class CompositeSchemaConverter implements SchemaConverter {
|
58
|
+
private readonly converters;
|
59
|
+
constructor(converters: SchemaConverter[]);
|
60
|
+
condition(): boolean;
|
61
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
62
|
+
}
|
63
|
+
|
64
|
+
interface OpenAPIInputStructureParseResult {
|
65
|
+
paramsSchema: ObjectSchema | undefined;
|
66
|
+
querySchema: ObjectSchema | undefined;
|
67
|
+
headersSchema: ObjectSchema | undefined;
|
68
|
+
bodySchema: JSONSchema.JSONSchema | undefined;
|
69
|
+
}
|
70
|
+
declare class OpenAPIInputStructureParser {
|
71
|
+
private readonly schemaConverter;
|
72
|
+
private readonly schemaUtils;
|
73
|
+
private readonly pathParser;
|
74
|
+
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils, pathParser: PublicOpenAPIPathParser);
|
75
|
+
parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIInputStructureParseResult;
|
76
|
+
private parseDetailedSchema;
|
77
|
+
private parseCompactSchema;
|
78
|
+
}
|
79
|
+
type PublicOpenAPIInputStructureParser = Pick<OpenAPIInputStructureParser, keyof OpenAPIInputStructureParser>;
|
80
|
+
|
81
|
+
interface OpenAPIOutputStructureParseResult {
|
82
|
+
headersSchema: ObjectSchema | undefined;
|
83
|
+
bodySchema: JSONSchema.JSONSchema | undefined;
|
84
|
+
}
|
85
|
+
declare class OpenAPIOutputStructureParser {
|
86
|
+
private readonly schemaConverter;
|
87
|
+
private readonly schemaUtils;
|
88
|
+
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils);
|
89
|
+
parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIOutputStructureParseResult;
|
90
|
+
private parseDetailedSchema;
|
91
|
+
private parseCompactSchema;
|
92
|
+
}
|
93
|
+
type PublicOpenAPIOutputStructureParser = Pick<OpenAPIOutputStructureParser, keyof OpenAPIOutputStructureParser>;
|
94
|
+
|
95
|
+
declare class OpenAPIParametersBuilder {
|
96
|
+
build(paramIn: OpenAPI.ParameterObject['in'], jsonSchema: JSONSchema.JSONSchema & {
|
97
|
+
type: 'object';
|
98
|
+
} & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.ParameterObject[];
|
99
|
+
buildHeadersObject(jsonSchema: JSONSchema.JSONSchema & {
|
100
|
+
type: 'object';
|
101
|
+
} & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.HeadersObject;
|
102
|
+
}
|
103
|
+
type PublicOpenAPIParametersBuilder = Pick<OpenAPIParametersBuilder, keyof OpenAPIParametersBuilder>;
|
104
|
+
|
105
|
+
type ErrorHandlerStrategy = 'throw' | 'log' | 'ignore';
|
106
|
+
interface OpenAPIGeneratorOptions {
|
107
|
+
contentBuilder?: PublicOpenAPIContentBuilder;
|
108
|
+
parametersBuilder?: PublicOpenAPIParametersBuilder;
|
109
|
+
schemaConverters?: SchemaConverter[];
|
110
|
+
schemaUtils?: PublicSchemaUtils;
|
111
|
+
jsonSerializer?: OpenAPIJsonSerializer;
|
112
|
+
pathParser?: PublicOpenAPIPathParser;
|
113
|
+
inputStructureParser?: PublicOpenAPIInputStructureParser;
|
114
|
+
outputStructureParser?: PublicOpenAPIOutputStructureParser;
|
115
|
+
/**
|
116
|
+
* Throw error when you missing define tag definition on OpenAPI root tags
|
117
|
+
*
|
118
|
+
* Example: if procedure has tags ['foo', 'bar'], and OpenAPI root tags is ['foo'], then error will be thrown
|
119
|
+
* Because OpenAPI root tags is missing 'bar' tag
|
120
|
+
*
|
121
|
+
* @default false
|
122
|
+
*/
|
123
|
+
considerMissingTagDefinitionAsError?: boolean;
|
124
|
+
/**
|
125
|
+
* Weather ignore procedures that has no path defined.
|
126
|
+
*
|
127
|
+
* @default false
|
128
|
+
*/
|
129
|
+
ignoreUndefinedPathProcedures?: boolean;
|
130
|
+
/**
|
131
|
+
* What to do when we found an error with our router
|
132
|
+
*
|
133
|
+
* @default 'throw'
|
134
|
+
*/
|
135
|
+
errorHandlerStrategy?: ErrorHandlerStrategy;
|
136
|
+
/**
|
137
|
+
* Strict error response
|
138
|
+
*
|
139
|
+
* @default true
|
140
|
+
*/
|
141
|
+
strictErrorResponses?: boolean;
|
142
|
+
}
|
143
|
+
declare class OpenAPIGenerator {
|
144
|
+
private readonly contentBuilder;
|
145
|
+
private readonly parametersBuilder;
|
146
|
+
private readonly schemaConverter;
|
147
|
+
private readonly schemaUtils;
|
148
|
+
private readonly jsonSerializer;
|
149
|
+
private readonly pathParser;
|
150
|
+
private readonly inputStructureParser;
|
151
|
+
private readonly outputStructureParser;
|
152
|
+
private readonly errorHandlerStrategy;
|
153
|
+
private readonly ignoreUndefinedPathProcedures;
|
154
|
+
private readonly considerMissingTagDefinitionAsError;
|
155
|
+
private readonly strictErrorResponses;
|
156
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
157
|
+
generate(router: ContractRouter<any> | AnyRouter, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
|
158
|
+
}
|
159
|
+
|
160
|
+
declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
161
|
+
declare function toOpenAPI31RoutePattern(path: HTTPPath): string;
|
162
|
+
|
163
|
+
/** unnoq */
|
164
|
+
|
165
|
+
declare const oo: {
|
166
|
+
spec: typeof setOperationExtender;
|
167
|
+
};
|
168
|
+
|
169
|
+
export { CompositeSchemaConverter, type FileSchema, NON_LOGIC_KEYWORDS, type ObjectSchema, OpenAPIContentBuilder, OpenAPIGenerator, type OpenAPIGeneratorOptions, OpenAPIParametersBuilder, OpenAPIPathParser, type OverrideOperationValue, type PublicOpenAPIContentBuilder, type PublicOpenAPIParametersBuilder, type PublicOpenAPIPathParser, type PublicSchemaUtils, type SchemaConvertOptions, type SchemaConverter, SchemaUtils, extendOperation, getOperationExtender, oo, setOperationExtender, standardizeHTTPPath, toOpenAPI31RoutePattern };
|