@orpc/openapi 0.0.0-next.1431467 → 0.0.0-next.16739f4

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,167 +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 { JSONSchema } from 'json-schema-typed/draft-2020-12';
6
- export { JSONSchema, Format as JSONSchemaFormat, keywords as JSONSchemaKeywords } from 'json-schema-typed/draft-2020-12';
7
- 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';
8
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';
9
10
 
10
- type OverrideOperationValue = OpenAPI.OperationObject | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
11
- declare function setOperationExtender<T extends object>(o: T, extend: OverrideOperationValue): T;
12
- declare function getOperationExtender(o: object): OverrideOperationValue | undefined;
13
- 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;
14
20
 
21
+ /**
22
+ * @internal
23
+ */
15
24
  type ObjectSchema = JSONSchema & {
16
25
  type: 'object';
17
26
  } & object;
27
+ /**
28
+ * @internal
29
+ */
18
30
  type FileSchema = JSONSchema & {
19
31
  type: 'string';
20
32
  contentMediaType: string;
21
33
  } & object;
22
- declare const NON_LOGIC_KEYWORDS: string[];
23
-
24
- declare class SchemaUtils {
25
- isFileSchema(schema: JSONSchema): schema is FileSchema;
26
- isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
27
- isAnySchema(schema: JSONSchema): boolean;
28
- isUndefinableSchema(schema: JSONSchema): boolean;
29
- separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
30
- filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
31
- }
32
- type PublicSchemaUtils = Pick<SchemaUtils, keyof SchemaUtils>;
34
+ /**
35
+ * @internal
36
+ */
37
+ declare const LOGIC_KEYWORDS: string[];
33
38
 
34
- declare class OpenAPIContentBuilder {
35
- private readonly schemaUtils;
36
- constructor(schemaUtils: PublicSchemaUtils);
37
- build(jsonSchema: JSONSchema, options?: Partial<OpenAPI.MediaTypeObject>): OpenAPI.ContentObject;
39
+ interface SchemaConvertOptions {
40
+ strategy: 'input' | 'output';
38
41
  }
39
- type PublicOpenAPIContentBuilder = Pick<OpenAPIContentBuilder, keyof OpenAPIContentBuilder>;
40
-
41
- declare class OpenAPIPathParser {
42
- parseDynamicParams(path: string): {
43
- name: string;
44
- raw: string;
45
- }[];
46
- }
47
- type PublicOpenAPIPathParser = Pick<OpenAPIPathParser, keyof OpenAPIPathParser>;
48
-
49
- type SchemaConvertStrategy = 'input' | 'output';
50
42
  interface SchemaConverter {
51
- convert(schema: Schema, strategy: SchemaConvertStrategy): [required: boolean, jsonSchema: JSONSchema];
43
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
52
44
  }
53
45
  interface ConditionalSchemaConverter extends SchemaConverter {
54
- condition(schema: Schema, strategy: SchemaConvertStrategy): boolean;
46
+ condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
55
47
  }
56
48
  declare class CompositeSchemaConverter implements SchemaConverter {
57
49
  private readonly converters;
58
50
  constructor(converters: ConditionalSchemaConverter[]);
59
- convert(schema: Schema, strategy: SchemaConvertStrategy): [required: boolean, jsonSchema: JSONSchema];
60
- }
61
-
62
- interface OpenAPIInputStructureParseResult {
63
- paramsSchema: ObjectSchema | undefined;
64
- querySchema: ObjectSchema | undefined;
65
- headersSchema: ObjectSchema | undefined;
66
- bodySchema: JSONSchema | undefined;
67
- }
68
- declare class OpenAPIInputStructureParser {
69
- private readonly schemaConverter;
70
- private readonly schemaUtils;
71
- private readonly pathParser;
72
- constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils, pathParser: PublicOpenAPIPathParser);
73
- parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIInputStructureParseResult;
74
- private parseDetailedSchema;
75
- private parseCompactSchema;
76
- }
77
- type PublicOpenAPIInputStructureParser = Pick<OpenAPIInputStructureParser, keyof OpenAPIInputStructureParser>;
78
-
79
- interface OpenAPIOutputStructureParseResult {
80
- headersSchema: ObjectSchema | undefined;
81
- bodySchema: JSONSchema | undefined;
51
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
82
52
  }
83
- declare class OpenAPIOutputStructureParser {
84
- private readonly schemaConverter;
85
- private readonly schemaUtils;
86
- constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils);
87
- parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIOutputStructureParseResult;
88
- private parseDetailedSchema;
89
- private parseCompactSchema;
90
- }
91
- type PublicOpenAPIOutputStructureParser = Pick<OpenAPIOutputStructureParser, keyof OpenAPIOutputStructureParser>;
92
-
93
- declare class OpenAPIParametersBuilder {
94
- build(paramIn: OpenAPI.ParameterObject['in'], jsonSchema: JSONSchema & {
95
- type: 'object';
96
- } & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.ParameterObject[];
97
- buildHeadersObject(jsonSchema: JSONSchema & {
98
- type: 'object';
99
- } & object, options?: Pick<OpenAPI.ParameterObject, 'example' | 'style' | 'required'>): OpenAPI.HeadersObject;
100
- }
101
- type PublicOpenAPIParametersBuilder = Pick<OpenAPIParametersBuilder, keyof OpenAPIParametersBuilder>;
102
53
 
103
- type ErrorHandlerStrategy = 'throw' | 'log' | 'ignore';
104
- interface OpenAPIGeneratorOptions {
105
- contentBuilder?: PublicOpenAPIContentBuilder;
106
- parametersBuilder?: PublicOpenAPIParametersBuilder;
54
+ interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
107
55
  schemaConverters?: ConditionalSchemaConverter[];
108
- schemaUtils?: PublicSchemaUtils;
109
- jsonSerializer?: OpenAPIJsonSerializer;
110
- pathParser?: PublicOpenAPIPathParser;
111
- inputStructureParser?: PublicOpenAPIInputStructureParser;
112
- outputStructureParser?: PublicOpenAPIOutputStructureParser;
113
- /**
114
- * Throw error when you missing define tag definition on OpenAPI root tags
115
- *
116
- * Example: if procedure has tags ['foo', 'bar'], and OpenAPI root tags is ['foo'], then error will be thrown
117
- * Because OpenAPI root tags is missing 'bar' tag
118
- *
119
- * @default false
120
- */
121
- considerMissingTagDefinitionAsError?: boolean;
122
- /**
123
- * Weather ignore procedures that has no path defined.
124
- *
125
- * @default false
126
- */
127
- ignoreUndefinedPathProcedures?: boolean;
128
- /**
129
- * What to do when we found an error with our router
130
- *
131
- * @default 'throw'
132
- */
133
- errorHandlerStrategy?: ErrorHandlerStrategy;
134
- /**
135
- * Strict error response
136
- *
137
- * @default true
138
- */
139
- strictErrorResponses?: boolean;
140
56
  }
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
+ */
141
62
  declare class OpenAPIGenerator {
142
- private readonly contentBuilder;
143
- private readonly parametersBuilder;
144
- private readonly schemaConverter;
145
- private readonly schemaUtils;
146
- private readonly jsonSerializer;
147
- private readonly pathParser;
148
- private readonly inputStructureParser;
149
- private readonly outputStructureParser;
150
- private readonly errorHandlerStrategy;
151
- private readonly ignoreUndefinedPathProcedures;
152
- private readonly considerMissingTagDefinitionAsError;
153
- private readonly strictErrorResponses;
63
+ #private;
64
+ private readonly serializer;
65
+ private readonly converter;
154
66
  constructor(options?: OpenAPIGeneratorOptions);
155
- generate(router: ContractRouter<any> | AnyRouter, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
67
+ /**
68
+ * Generates OpenAPI specifications from oRPC routers/contracts.
69
+ *
70
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
71
+ */
72
+ generate(router: AnyContractRouter | AnyRouter, base: Omit<OpenAPIV3_1.Document, 'openapi'>): Promise<OpenAPIV3_1.Document>;
156
73
  }
157
74
 
158
- declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
159
- 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;
160
103
 
161
- /** 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;
162
125
 
163
126
  declare const oo: {
164
- spec: typeof setOperationExtender;
127
+ spec: typeof customOpenAPIOperation;
165
128
  };
166
129
 
167
- export { CompositeSchemaConverter, type ConditionalSchemaConverter, type FileSchema, NON_LOGIC_KEYWORDS, type ObjectSchema, OpenAPIContentBuilder, OpenAPIGenerator, type OpenAPIGeneratorOptions, OpenAPIParametersBuilder, OpenAPIPathParser, type OverrideOperationValue, type PublicOpenAPIContentBuilder, type PublicOpenAPIParametersBuilder, type PublicOpenAPIPathParser, type PublicSchemaUtils, type SchemaConvertStrategy, 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 };