typed-openapi 0.10.0 → 1.0.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/dist/index.d.cts DELETED
@@ -1,268 +0,0 @@
1
- import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
- import { OpenAPIObject, SchemaObject, ReferenceObject, OperationObject } from 'openapi3-ts/oas31';
3
- import * as arktype from 'arktype';
4
- import * as Codegen from '@sinclair/typebox-codegen';
5
-
6
- declare class Box<T extends AnyBoxDef = AnyBoxDef> {
7
- definition: T;
8
- type: T["type"];
9
- value: T["value"];
10
- params: T["params"];
11
- schema: T["schema"];
12
- ctx: T["ctx"];
13
- constructor(definition: T);
14
- toJSON(): {
15
- type: T["type"];
16
- value: T["value"];
17
- };
18
- toString(): string;
19
- recompute(callback: OpenapiSchemaConvertContext["onBox"]): Box<AnyBoxDef>;
20
- static fromJSON(json: string): Box<any>;
21
- static isBox(box: unknown): box is Box<AnyBoxDef>;
22
- static isUnion(box: Box<AnyBoxDef>): box is Box<BoxUnion>;
23
- static isIntersection(box: Box<AnyBoxDef>): box is Box<BoxIntersection>;
24
- static isArray(box: Box<AnyBoxDef>): box is Box<BoxArray>;
25
- static isOptional(box: Box<AnyBoxDef>): box is Box<BoxOptional>;
26
- static isReference(box: Box<AnyBoxDef>): box is Box<BoxRef>;
27
- static isKeyword(box: Box<AnyBoxDef>): box is Box<BoxKeyword>;
28
- static isObject(box: Box<AnyBoxDef>): box is Box<BoxObject>;
29
- static isLiteral(box: Box<AnyBoxDef>): box is Box<BoxLiteral>;
30
- }
31
-
32
- type RefInfo = {
33
- /**
34
- * The (potentially autocorrected) ref
35
- * @example "#/components/schemas/MySchema"
36
- */
37
- ref: string;
38
- /**
39
- * The name of the ref
40
- * @example "MySchema"
41
- * */
42
- name: string;
43
- normalized: string;
44
- kind: "schemas" | "responses" | "parameters" | "requestBodies" | "headers";
45
- };
46
- declare const createRefResolver: (doc: OpenAPIObject, factory: GenericFactory) => {
47
- get: <T = SchemaObject>(ref: string) => NonNullable<T>;
48
- unwrap: <T_1 extends {} | ReferenceObject>(component: T_1) => Exclude<T_1, ReferenceObject>;
49
- getInfosByRef: (ref: string) => RefInfo;
50
- infos: Map<string, RefInfo>;
51
- /**
52
- * Get the schemas in the order they should be generated, depending on their dependencies
53
- * so that a schema is generated before the ones that depend on it
54
- */
55
- getOrderedSchemas: () => [schema: Box<AnyBoxDef>, infos: RefInfo][];
56
- directDependencies: Map<string, Set<string>>;
57
- transitiveDependencies: Map<string, Set<string>>;
58
- };
59
- interface RefResolver extends ReturnType<typeof createRefResolver> {
60
- }
61
-
62
- type BoxDefinition = {
63
- type: string;
64
- params: unknown;
65
- value: string;
66
- };
67
- type BoxParams = string | BoxDefinition;
68
- type WithSchema = {
69
- schema: SchemaObject | ReferenceObject | undefined;
70
- ctx: OpenapiSchemaConvertContext;
71
- };
72
- type BoxUnion = WithSchema & {
73
- type: "union";
74
- params: {
75
- types: Array<BoxParams>;
76
- };
77
- value: string;
78
- };
79
- type BoxIntersection = WithSchema & {
80
- type: "intersection";
81
- params: {
82
- types: Array<BoxParams>;
83
- };
84
- value: string;
85
- };
86
- type BoxArray = WithSchema & {
87
- type: "array";
88
- params: {
89
- type: BoxParams;
90
- };
91
- value: string;
92
- };
93
- type BoxOptional = WithSchema & {
94
- type: "optional";
95
- params: {
96
- type: BoxParams;
97
- };
98
- value: string;
99
- };
100
- type BoxRef = WithSchema & {
101
- type: "ref";
102
- params: {
103
- name: string;
104
- generics?: BoxParams[] | undefined;
105
- };
106
- value: string;
107
- };
108
- type BoxLiteral = WithSchema & {
109
- type: "literal";
110
- params: {};
111
- value: string;
112
- };
113
- type BoxKeyword = WithSchema & {
114
- type: "keyword";
115
- params: {
116
- name: string;
117
- };
118
- value: string;
119
- };
120
- type BoxObject = WithSchema & {
121
- type: "object";
122
- params: {
123
- props: Record<string, BoxParams>;
124
- };
125
- value: string;
126
- };
127
- type AnyBoxDef = BoxUnion | BoxIntersection | BoxArray | BoxOptional | BoxRef | BoxLiteral | BoxKeyword | BoxObject;
128
- type AnyBox = Box<AnyBoxDef>;
129
- type OpenapiSchemaConvertArgs = {
130
- schema: SchemaObject | ReferenceObject;
131
- ctx: OpenapiSchemaConvertContext;
132
- meta?: {} | undefined;
133
- };
134
- type FactoryCreator = (schema: SchemaObject | ReferenceObject, ctx: OpenapiSchemaConvertContext) => GenericFactory;
135
- type OpenapiSchemaConvertContext = {
136
- factory: FactoryCreator | GenericFactory;
137
- refs: RefResolver;
138
- onBox?: (box: Box<AnyBoxDef>) => Box<AnyBoxDef>;
139
- };
140
- type StringOrBox = string | Box<AnyBoxDef>;
141
- type BoxFactory = {
142
- union: (types: Array<StringOrBox>) => Box<BoxUnion>;
143
- intersection: (types: Array<StringOrBox>) => Box<BoxIntersection>;
144
- array: (type: StringOrBox) => Box<BoxArray>;
145
- object: (props: Record<string, StringOrBox>) => Box<BoxObject>;
146
- optional: (type: StringOrBox) => Box<BoxOptional>;
147
- reference: (name: string, generics?: Array<StringOrBox> | undefined) => Box<BoxRef>;
148
- literal: (value: StringOrBox) => Box<BoxLiteral>;
149
- string: () => Box<BoxKeyword>;
150
- number: () => Box<BoxKeyword>;
151
- boolean: () => Box<BoxKeyword>;
152
- unknown: () => Box<BoxKeyword>;
153
- any: () => Box<BoxKeyword>;
154
- never: () => Box<BoxKeyword>;
155
- };
156
- type GenericFactory = {
157
- callback?: OpenapiSchemaConvertContext["onBox"];
158
- union: (types: Array<StringOrBox>) => string;
159
- intersection: (types: Array<StringOrBox>) => string;
160
- array: (type: StringOrBox) => string;
161
- object: (props: Record<string, StringOrBox>) => string;
162
- optional: (type: StringOrBox) => string;
163
- reference: (name: string, generics?: Array<StringOrBox> | undefined) => string;
164
- literal: (value: StringOrBox) => string;
165
- string: () => string;
166
- number: () => string;
167
- boolean: () => string;
168
- unknown: () => string;
169
- any: () => string;
170
- never: () => string;
171
- };
172
-
173
- declare const unwrap: (param: StringOrBox) => string;
174
- declare const createFactory: <T extends GenericFactory | FactoryCreator>(f: T) => T;
175
- /**
176
- * Create a box-factory using your schema provider and automatically add the input schema to each box.
177
- */
178
- declare const createBoxFactory: (schema: SchemaObject | ReferenceObject, ctx: OpenapiSchemaConvertContext) => BoxFactory;
179
-
180
- declare const mapOpenApiEndpoints: (doc: OpenAPIObject) => {
181
- doc: OpenAPIObject;
182
- refs: {
183
- get: <T = openapi3_ts_oas31.SchemaObject>(ref: string) => NonNullable<T>;
184
- unwrap: <T_1 extends {} | openapi3_ts_oas31.ReferenceObject>(component: T_1) => Exclude<T_1, openapi3_ts_oas31.ReferenceObject>;
185
- getInfosByRef: (ref: string) => RefInfo;
186
- infos: Map<string, RefInfo>;
187
- getOrderedSchemas: () => [schema: Box<AnyBoxDef>, infos: RefInfo][];
188
- directDependencies: Map<string, Set<string>>;
189
- transitiveDependencies: Map<string, Set<string>>;
190
- };
191
- endpointList: Endpoint<DefaultEndpoint>[];
192
- factory: {
193
- union: (types: StringOrBox[]) => string;
194
- intersection: (types: StringOrBox[]) => string;
195
- array: (type: StringOrBox) => string;
196
- optional: (type: StringOrBox) => string;
197
- reference: (name: string, typeArgs: StringOrBox[] | undefined) => string;
198
- literal: (value: StringOrBox) => string;
199
- string: () => "string";
200
- number: () => "number";
201
- boolean: () => "boolean";
202
- unknown: () => "unknown";
203
- any: () => "any";
204
- never: () => "never";
205
- object: (props: Record<string, StringOrBox>) => string;
206
- };
207
- };
208
- type MutationMethod = "post" | "put" | "patch" | "delete";
209
- type Method = "get" | "head" | "options" | MutationMethod;
210
- type EndpointParameters = {
211
- body?: Box<BoxRef>;
212
- query?: Box<BoxRef> | Record<string, AnyBox>;
213
- header?: Box<BoxRef> | Record<string, AnyBox>;
214
- path?: Box<BoxRef> | Record<string, AnyBox>;
215
- };
216
- type RequestFormat = "json" | "form-data" | "form-url" | "binary" | "text";
217
- type DefaultEndpoint = {
218
- parameters?: EndpointParameters | undefined;
219
- response: AnyBox;
220
- };
221
- type Endpoint<TConfig extends DefaultEndpoint = DefaultEndpoint> = {
222
- operation: OperationObject;
223
- method: Method;
224
- path: string;
225
- parameters?: TConfig["parameters"];
226
- requestFormat: RequestFormat;
227
- meta: {
228
- alias: string;
229
- hasParameters: boolean;
230
- areParametersRequired: boolean;
231
- };
232
- response: TConfig["response"];
233
- };
234
-
235
- type GeneratorOptions = ReturnType<typeof mapOpenApiEndpoints> & {
236
- runtime?: "none" | keyof typeof runtimeValidationGenerator;
237
- };
238
- declare const allowedRuntimes: arktype.Type<"zod" | "arktype" | "typebox" | "valibot" | "yup" | "io-ts" | "none">;
239
- type OutputRuntime = typeof allowedRuntimes.infer;
240
- declare const runtimeValidationGenerator: {
241
- arktype: typeof Codegen.ModelToArkType.Generate;
242
- "io-ts": typeof Codegen.ModelToIoTs.Generate;
243
- typebox: typeof Codegen.ModelToTypeBox.Generate;
244
- valibot: typeof Codegen.ModelToValibot.Generate;
245
- yup: typeof Codegen.ModelToYup.Generate;
246
- zod: typeof Codegen.ModelToZod.Generate;
247
- };
248
- declare const generateFile: (options: GeneratorOptions) => string;
249
-
250
- declare const openApiSchemaToTs: ({ schema, meta: _inheritedMeta, ctx }: OpenapiSchemaConvertArgs) => Box<AnyBoxDef>;
251
-
252
- declare const tsFactory: {
253
- union: (types: StringOrBox[]) => string;
254
- intersection: (types: StringOrBox[]) => string;
255
- array: (type: StringOrBox) => string;
256
- optional: (type: StringOrBox) => string;
257
- reference: (name: string, typeArgs: StringOrBox[] | undefined) => string;
258
- literal: (value: StringOrBox) => string;
259
- string: () => "string";
260
- number: () => "number";
261
- boolean: () => "boolean";
262
- unknown: () => "unknown";
263
- any: () => "any";
264
- never: () => "never";
265
- object: (props: Record<string, StringOrBox>) => string;
266
- };
267
-
268
- export { AnyBox, AnyBoxDef, BoxArray, BoxDefinition, BoxFactory, BoxIntersection, BoxKeyword, BoxLiteral, BoxObject, BoxOptional, BoxParams, BoxRef, BoxUnion, Endpoint, EndpointParameters, FactoryCreator, GenericFactory, OpenapiSchemaConvertArgs, OpenapiSchemaConvertContext, OutputRuntime, RefInfo, RefResolver, StringOrBox, WithSchema, createBoxFactory, createFactory, createRefResolver, generateFile, mapOpenApiEndpoints, openApiSchemaToTs, tsFactory, unwrap };