@orpc/openapi 0.0.0-next.e0f01a5 → 0.0.0-next.e1d2637

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,17 +1,23 @@
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';
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';
1
+ import { OpenAPI, AnyContractProcedure } from '@orpc/contract';
2
+ export { OpenAPI } from '@orpc/contract';
3
+ export { e as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, c as SchemaConvertOptions, d as SchemaConverter, S as SchemaConverterComponent } from './shared/openapi.BGy4N6eR.js';
9
4
  import { HTTPPath, HTTPMethod } from '@orpc/client';
5
+ import { JSONSchema } 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';
7
+ import { JsonifiedClient } from '@orpc/openapi-client';
8
+ import { AnyRouter, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@orpc/server';
9
+ import { MaybeOptionalOptions } from '@orpc/shared';
10
+ import '@orpc/openapi-client/standard';
10
11
 
11
- type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current: OpenAPIV3_1.OperationObject, procedure: AnyContractProcedure) => OpenAPIV3_1.OperationObject);
12
+ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
13
+ /**
14
+ * Customize The Operation Object by proxy an error map item or a middleware.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
17
+ */
12
18
  declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
13
19
  declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
14
- declare function applyCustomOpenAPIOperation(operation: OpenAPIV3_1.OperationObject, contract: AnyContractProcedure): OpenAPIV3_1.OperationObject;
20
+ declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
15
21
 
16
22
  /**
17
23
  * @internal
@@ -31,32 +37,6 @@ type FileSchema = JSONSchema & {
31
37
  */
32
38
  declare const LOGIC_KEYWORDS: string[];
33
39
 
34
- interface SchemaConvertOptions {
35
- strategy: 'input' | 'output';
36
- }
37
- interface SchemaConverter {
38
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
39
- }
40
- interface ConditionalSchemaConverter extends SchemaConverter {
41
- condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
42
- }
43
- declare class CompositeSchemaConverter implements SchemaConverter {
44
- private readonly converters;
45
- constructor(converters: ConditionalSchemaConverter[]);
46
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
47
- }
48
-
49
- interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
50
- schemaConverters?: ConditionalSchemaConverter[];
51
- }
52
- declare class OpenAPIGenerator {
53
- #private;
54
- private readonly serializer;
55
- private readonly converter;
56
- constructor(options?: OpenAPIGeneratorOptions);
57
- generate(router: AnyContractRouter | AnyRouter, base: Omit<OpenAPIV3_1.Document, 'openapi'>): Promise<OpenAPIV3_1.Document>;
58
- }
59
-
60
40
  /**
61
41
  * @internal
62
42
  */
@@ -68,15 +48,15 @@ declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
68
48
  /**
69
49
  * @internal
70
50
  */
71
- declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPIV3_1.MediaTypeObject>;
51
+ declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
72
52
  /**
73
53
  * @internal
74
54
  */
75
- declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPIV3_1.MediaTypeObject>;
55
+ declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
76
56
  /**
77
57
  * @internal
78
58
  */
79
- declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPIV3_1.ParameterObject[];
59
+ declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
80
60
  /**
81
61
  * @internal
82
62
  */
@@ -84,7 +64,16 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
84
64
  /**
85
65
  * @internal
86
66
  */
87
- declare function toOpenAPISchema(schema: JSONSchema): OpenAPIV3_1.SchemaObject & object;
67
+ declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
68
+ declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
69
+ /**
70
+ * Simplifies composed object JSON Schemas (using anyOf, oneOf, allOf) by flattening nested compositions
71
+ *
72
+ * @warning The result is looser than the original schema and may not fully validate the same data.
73
+ */
74
+ declare function simplifyComposedObjectJsonSchemasAndRefs(schema: JSONSchema, doc?: OpenAPI.Document): JSONSchema;
75
+
76
+ 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>>;
88
77
 
89
78
  /**
90
79
  *@internal
@@ -107,10 +96,21 @@ declare function separateObjectSchema(schema: ObjectSchema, separatedProperties:
107
96
  */
108
97
  declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
109
98
  declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
99
+ /**
100
+ * Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
101
+ * recursively expands it into an array of its constituent, non-union base schemas.
102
+ * If the schema is not a simple union or is a base type, it's returned as a single-element array.
103
+ */
104
+ declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
105
+ declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
106
+ type: 'array';
107
+ items?: JSONSchema;
108
+ }];
109
+ declare function isPrimitiveSchema(schema: JSONSchema): boolean;
110
110
 
111
111
  declare const oo: {
112
112
  spec: typeof customOpenAPIOperation;
113
113
  };
114
114
 
115
- export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
116
- export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter };
115
+ export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, simplifyComposedObjectJsonSchemasAndRefs, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
116
+ export type { FileSchema, ObjectSchema, OverrideOperationValue };