typed-openapi 0.1.1

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/src/types.ts ADDED
@@ -0,0 +1,133 @@
1
+ import type { ReferenceObject, SchemaObject } from "openapi3-ts/oas31";
2
+
3
+ import type { RefResolver } from "./ref-resolver";
4
+ import { Box } from "./box";
5
+
6
+ export type BoxDefinition = {
7
+ type: string;
8
+ params: unknown;
9
+ value: string;
10
+ };
11
+ export type BoxParams = string | BoxDefinition;
12
+ export type WithSchema = {
13
+ schema: SchemaObject | ReferenceObject | undefined;
14
+ ctx: OpenapiSchemaConvertContext;
15
+ };
16
+
17
+ export type BoxUnion = WithSchema & {
18
+ type: "union";
19
+ params: {
20
+ types: Array<BoxParams>;
21
+ };
22
+ value: string;
23
+ };
24
+
25
+ export type BoxIntersection = WithSchema & {
26
+ type: "intersection";
27
+ params: {
28
+ types: Array<BoxParams>;
29
+ };
30
+ value: string;
31
+ };
32
+
33
+ export type BoxArray = WithSchema & {
34
+ type: "array";
35
+ params: {
36
+ type: BoxParams;
37
+ };
38
+ value: string;
39
+ };
40
+
41
+ export type BoxOptional = WithSchema & {
42
+ type: "optional";
43
+ params: {
44
+ type: BoxParams;
45
+ };
46
+ value: string;
47
+ };
48
+
49
+ export type BoxRef = WithSchema & {
50
+ type: "ref";
51
+ params: { name: string; generics?: BoxParams[] | undefined };
52
+ value: string;
53
+ };
54
+
55
+ export type BoxLiteral = WithSchema & {
56
+ type: "literal";
57
+ params: {};
58
+ value: string;
59
+ };
60
+
61
+ export type BoxKeyword = WithSchema & {
62
+ type: "keyword";
63
+ params: { name: string };
64
+ value: string;
65
+ };
66
+
67
+ export type BoxObject = WithSchema & {
68
+ type: "object";
69
+ params: { props: Record<string, BoxParams> };
70
+ value: string;
71
+ };
72
+
73
+ export type AnyBoxDef =
74
+ | BoxUnion
75
+ | BoxIntersection
76
+ | BoxArray
77
+ | BoxOptional
78
+ | BoxRef
79
+ | BoxLiteral
80
+ | BoxKeyword
81
+ | BoxObject;
82
+ export type AnyBox = Box<AnyBoxDef>;
83
+
84
+ export type OpenapiSchemaConvertArgs = {
85
+ schema: SchemaObject | ReferenceObject;
86
+ ctx: OpenapiSchemaConvertContext;
87
+ meta?: {} | undefined;
88
+ };
89
+
90
+ export type FactoryCreator = (
91
+ schema: SchemaObject | ReferenceObject,
92
+ ctx: OpenapiSchemaConvertContext,
93
+ ) => GenericFactory;
94
+ export type OpenapiSchemaConvertContext = {
95
+ factory: FactoryCreator | GenericFactory;
96
+ refs: RefResolver;
97
+ onBox?: (box: Box<AnyBoxDef>) => Box<AnyBoxDef>;
98
+ };
99
+
100
+ export type StringOrBox = string | Box<AnyBoxDef>;
101
+
102
+ export type BoxFactory = {
103
+ union: (types: Array<StringOrBox>) => Box<BoxUnion>;
104
+ intersection: (types: Array<StringOrBox>) => Box<BoxIntersection>;
105
+ array: (type: StringOrBox) => Box<BoxArray>;
106
+ object: (props: Record<string, StringOrBox>) => Box<BoxObject>;
107
+ optional: (type: StringOrBox) => Box<BoxOptional>;
108
+ reference: (name: string, generics?: Array<StringOrBox> | undefined) => Box<BoxRef>;
109
+ literal: (value: StringOrBox) => Box<BoxLiteral>;
110
+ string: () => Box<BoxKeyword>;
111
+ number: () => Box<BoxKeyword>;
112
+ boolean: () => Box<BoxKeyword>;
113
+ unknown: () => Box<BoxKeyword>;
114
+ any: () => Box<BoxKeyword>;
115
+ never: () => Box<BoxKeyword>;
116
+ };
117
+
118
+ export type GenericFactory = {
119
+ callback?: OpenapiSchemaConvertContext["onBox"];
120
+ union: (types: Array<StringOrBox>) => string;
121
+ intersection: (types: Array<StringOrBox>) => string;
122
+ array: (type: StringOrBox) => string;
123
+ object: (props: Record<string, StringOrBox>) => string;
124
+ optional: (type: StringOrBox) => string;
125
+ reference: (name: string, generics?: Array<StringOrBox> | undefined) => string;
126
+ literal: (value: StringOrBox) => string;
127
+ string: () => string;
128
+ number: () => string;
129
+ boolean: () => string;
130
+ unknown: () => string;
131
+ any: () => string;
132
+ never: () => string;
133
+ };