@orpc/openapi 0.0.0-next.b0f324e → 0.0.0-next.b11d127

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/dist/index.d.ts CHANGED
@@ -1,169 +1,131 @@
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';
1
+ import { AnyContractProcedure, AnySchema, AnyContractRouter } from '@orpc/contract';
2
+ import { OpenAPIV3_1 } from 'openapi-types';
3
+ export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
4
+ import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
9
5
  import { AnyRouter } from '@orpc/server';
6
+ import { Promisable } from '@orpc/shared';
7
+ import { JSONSchema } from 'json-schema-typed/draft-2020-12';
8
+ export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
9
+ import { HTTPPath, HTTPMethod } from '@orpc/client';
10
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;
11
+ type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current: OpenAPIV3_1.OperationObject, procedure: AnyContractProcedure) => OpenAPIV3_1.OperationObject);
12
+ /**
13
+ * Customize The Operation Object by proxy an error map item or a middleware.
14
+ *
15
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
16
+ */
17
+ declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
18
+ declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
19
+ declare function applyCustomOpenAPIOperation(operation: OpenAPIV3_1.OperationObject, contract: AnyContractProcedure): OpenAPIV3_1.OperationObject;
15
20
 
16
- type ObjectSchema = JSONSchema.JSONSchema & {
21
+ /**
22
+ * @internal
23
+ */
24
+ type ObjectSchema = JSONSchema & {
17
25
  type: 'object';
18
26
  } & object;
19
- type FileSchema = JSONSchema.JSONSchema & {
27
+ /**
28
+ * @internal
29
+ */
30
+ type FileSchema = JSONSchema & {
20
31
  type: 'string';
21
32
  contentMediaType: string;
22
33
  } & 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>;
34
+ /**
35
+ * @internal
36
+ */
37
+ declare const LOGIC_KEYWORDS: string[];
49
38
 
50
39
  interface SchemaConvertOptions {
51
40
  strategy: 'input' | 'output';
52
41
  }
53
42
  interface SchemaConverter {
54
- condition(schema: Schema, options: SchemaConvertOptions): boolean;
55
- convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
43
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
44
+ }
45
+ interface ConditionalSchemaConverter extends SchemaConverter {
46
+ condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
56
47
  }
57
48
  declare class CompositeSchemaConverter implements SchemaConverter {
58
49
  private readonly converters;
59
- constructor(converters: SchemaConverter[]);
60
- condition(): boolean;
61
- convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
50
+ constructor(converters: ConditionalSchemaConverter[]);
51
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
62
52
  }
63
53
 
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;
54
+ interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
55
+ schemaConverters?: ConditionalSchemaConverter[];
78
56
  }
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;
57
+ /**
58
+ * The generator that converts oRPC routers/contracts to OpenAPI specifications.
59
+ *
60
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
61
+ */
62
+ declare class OpenAPIGenerator {
63
+ #private;
64
+ private readonly serializer;
65
+ private readonly converter;
66
+ constructor(options?: OpenAPIGeneratorOptions);
136
67
  /**
137
- * Strict error response
68
+ * Generates OpenAPI specifications from oRPC routers/contracts.
138
69
  *
139
- * @default true
70
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
140
71
  */
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>;
72
+ generate(router: AnyContractRouter | AnyRouter, base: Omit<OpenAPIV3_1.Document, 'openapi'>): Promise<OpenAPIV3_1.Document>;
158
73
  }
159
74
 
160
- declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
161
- declare function toOpenAPI31RoutePattern(path: HTTPPath): string;
75
+ /**
76
+ * @internal
77
+ */
78
+ declare function toOpenAPIPath(path: HTTPPath): string;
79
+ /**
80
+ * @internal
81
+ */
82
+ declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
83
+ /**
84
+ * @internal
85
+ */
86
+ declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPIV3_1.MediaTypeObject>;
87
+ /**
88
+ * @internal
89
+ */
90
+ declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPIV3_1.MediaTypeObject>;
91
+ /**
92
+ * @internal
93
+ */
94
+ declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPIV3_1.ParameterObject[];
95
+ /**
96
+ * @internal
97
+ */
98
+ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
99
+ /**
100
+ * @internal
101
+ */
102
+ declare function toOpenAPISchema(schema: JSONSchema): OpenAPIV3_1.SchemaObject & object;
162
103
 
163
- /** unnoq */
104
+ /**
105
+ *@internal
106
+ */
107
+ declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
108
+ /**
109
+ * @internal
110
+ */
111
+ declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
112
+ /**
113
+ * @internal
114
+ */
115
+ declare function isAnySchema(schema: JSONSchema): boolean;
116
+ /**
117
+ * @internal
118
+ */
119
+ declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
120
+ /**
121
+ * @internal
122
+ */
123
+ declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
124
+ declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
164
125
 
165
126
  declare const oo: {
166
- spec: typeof setOperationExtender;
127
+ spec: typeof customOpenAPIOperation;
167
128
  };
168
129
 
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 };
130
+ export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
131
+ export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter };