@@ -15,33 +15,33 @@ const makeCtx = (schemas: SchemasObject): OpenapiSchemaConvertContext => ({
15
15
} ) ;
16
16
const makeDoc = ( schemas : SchemasObject ) => ( { components : { schemas } } as any ) ;
17
17
18
- const getSchemaBox = async ( schema : LibSchemaObject ) => {
19
- const output = await generateFile ( mapOpenApiEndpoints ( makeDoc ( { _Test : schema } ) ) ) ;
18
+ const getSchemaBox = ( schema : LibSchemaObject ) => {
19
+ const output = generateFile ( mapOpenApiEndpoints ( makeDoc ( { _Test : schema } ) ) ) ;
20
20
const start = output . indexOf ( "// <Schemas>" ) ;
21
21
const end = output . indexOf ( "// </Schemas>" ) ;
22
22
return output . substring ( start + "// <Schemas>" . length , end ) . trim ( ) ;
23
23
} ;
24
24
25
25
test ( "getSchemaBox" , async ( ) => {
26
- expect ( await getSchemaBox ( { type : "null" } ) ) . toMatchInlineSnapshot ( '"export type _Test = null;"' ) ;
27
- expect ( await getSchemaBox ( { type : "boolean" } ) ) . toMatchInlineSnapshot ( '"export type _Test = boolean;"' ) ;
28
- expect ( await getSchemaBox ( { type : "boolean" , nullable : true } ) ) . toMatchInlineSnapshot ( '"export type _Test = boolean | null;"' ) ;
29
- expect ( await getSchemaBox ( { type : "string" } ) ) . toMatchInlineSnapshot ( '"export type _Test = string;"' ) ;
30
- expect ( await getSchemaBox ( { type : "number" } ) ) . toMatchInlineSnapshot ( '"export type _Test = number;"' ) ;
31
- expect ( await getSchemaBox ( { type : "integer" } ) ) . toMatchInlineSnapshot ( '"export type _Test = number;"' ) ;
32
- expect ( await getSchemaBox ( { } ) ) . toMatchInlineSnapshot ( '"export type _Test = unknown;"' ) ;
33
-
34
- expect ( await getSchemaBox ( { type : "array" , items : { type : "string" } } ) ) . toMatchInlineSnapshot ( '"export type _Test = Array<string>;"' ) ;
35
- expect ( await getSchemaBox ( { type : "object" } ) ) . toMatchInlineSnapshot (
26
+ expect ( getSchemaBox ( { type : "null" } ) ) . toMatchInlineSnapshot ( '"export type _Test = null;"' ) ;
27
+ expect ( getSchemaBox ( { type : "boolean" } ) ) . toMatchInlineSnapshot ( '"export type _Test = boolean;"' ) ;
28
+ expect ( getSchemaBox ( { type : "boolean" , nullable : true } ) ) . toMatchInlineSnapshot ( '"export type _Test = boolean | null;"' ) ;
29
+ expect ( getSchemaBox ( { type : "string" } ) ) . toMatchInlineSnapshot ( '"export type _Test = string;"' ) ;
30
+ expect ( getSchemaBox ( { type : "number" } ) ) . toMatchInlineSnapshot ( '"export type _Test = number;"' ) ;
31
+ expect ( getSchemaBox ( { type : "integer" } ) ) . toMatchInlineSnapshot ( '"export type _Test = number;"' ) ;
32
+ expect ( getSchemaBox ( { } ) ) . toMatchInlineSnapshot ( '"export type _Test = unknown;"' ) ;
33
+
34
+ expect ( getSchemaBox ( { type : "array" , items : { type : "string" } } ) ) . toMatchInlineSnapshot ( '"export type _Test = Array<string>;"' ) ;
35
+ expect ( getSchemaBox ( { type : "object" } ) ) . toMatchInlineSnapshot (
36
36
'"export type _Test = Record<string, unknown>;"' ,
37
37
) ;
38
- expect ( await getSchemaBox ( { type : "object" , properties : { str : { type : "string" } } } ) ) . toMatchInlineSnapshot ( '"export type _Test = Partial<{ str: string }>;"' ) ;
39
- expect ( await getSchemaBox ( { type : "object" , properties : { str : { type : "string" } , nb : { type : "number" } } } ) )
38
+ expect ( getSchemaBox ( { type : "object" , properties : { str : { type : "string" } } } ) ) . toMatchInlineSnapshot ( '"export type _Test = Partial<{ str: string }>;"' ) ;
39
+ expect ( getSchemaBox ( { type : "object" , properties : { str : { type : "string" } , nb : { type : "number" } } } ) )
40
40
. toMatchInlineSnapshot ( '"export type _Test = Partial<{ str: string; nb: number }>;"' ) ;
41
41
42
42
// AllPropertiesRequired
43
43
expect (
44
- await getSchemaBox ( {
44
+ getSchemaBox ( {
45
45
type : "object" ,
46
46
properties : { str : { type : "string" } , nb : { type : "number" } } ,
47
47
required : [ "str" , "nb" ] ,
@@ -50,7 +50,7 @@ test("getSchemaBox", async () => {
50
50
51
51
// SomeOptionalProps
52
52
expect (
53
- await getSchemaBox ( {
53
+ getSchemaBox ( {
54
54
type : "object" ,
55
55
properties : { str : { type : "string" } , nb : { type : "number" } } ,
56
56
required : [ "str" ] ,
@@ -59,7 +59,7 @@ test("getSchemaBox", async () => {
59
59
60
60
// ObjectWithNestedProp
61
61
expect (
62
- await getSchemaBox ( {
62
+ getSchemaBox ( {
63
63
type : "object" ,
64
64
properties : {
65
65
str : { type : "string" } ,
@@ -76,20 +76,20 @@ test("getSchemaBox", async () => {
76
76
77
77
// ObjectWithAdditionalPropsNb
78
78
expect (
79
- await getSchemaBox ( { type : "object" , properties : { str : { type : "string" } } , additionalProperties : { type : "number" } } ) ,
79
+ getSchemaBox ( { type : "object" , properties : { str : { type : "string" } } , additionalProperties : { type : "number" } } ) ,
80
80
) . toMatchInlineSnapshot ( '"export type _Test = Partial<{ str: string } & { string: number }>;"' ) ;
81
81
82
82
// ObjectWithNestedRecordBoolean
83
83
expect (
84
- await getSchemaBox ( {
84
+ getSchemaBox ( {
85
85
type : "object" ,
86
86
properties : { str : { type : "string" } } ,
87
87
additionalProperties : { type : "object" , properties : { prop : { type : "boolean" } } } ,
88
88
} ) ,
89
89
) . toMatchInlineSnapshot ( '"export type _Test = Partial<{ str: string } & { string: Partial<{ prop: boolean }> }>;"' ) ;
90
90
91
91
expect (
92
- await getSchemaBox ( {
92
+ getSchemaBox ( {
93
93
type : "array" ,
94
94
items : {
95
95
type : "object" ,
@@ -101,7 +101,7 @@ test("getSchemaBox", async () => {
101
101
) . toMatchInlineSnapshot ( '"export type _Test = Array<Partial<{ str: string }>>;"' ) ;
102
102
103
103
expect (
104
- await getSchemaBox ( {
104
+ getSchemaBox ( {
105
105
type : "array" ,
106
106
items : {
107
107
type : "array" ,
@@ -114,54 +114,54 @@ test("getSchemaBox", async () => {
114
114
115
115
// ObjectWithEnum
116
116
expect (
117
- await getSchemaBox ( {
117
+ getSchemaBox ( {
118
118
type : "object" ,
119
119
properties : {
120
120
enumprop : { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ,
121
121
} ,
122
122
} ) ,
123
123
) . toMatchInlineSnapshot ( '"export type _Test = Partial<{ enumprop: "aaa" | "bbb" | "ccc" }>;"' ) ;
124
124
125
- expect ( await getSchemaBox ( { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ) ) . toMatchInlineSnapshot (
125
+ expect ( getSchemaBox ( { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ) ) . toMatchInlineSnapshot (
126
126
'"export type _Test = "aaa" | "bbb" | "ccc";"' ,
127
127
) ;
128
128
129
129
// StringENum
130
- expect ( await getSchemaBox ( { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ) ) . toMatchInlineSnapshot ( '"export type _Test = "aaa" | "bbb" | "ccc";"' ) ;
130
+ expect ( getSchemaBox ( { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ) ) . toMatchInlineSnapshot ( '"export type _Test = "aaa" | "bbb" | "ccc";"' ) ;
131
131
132
132
// ObjectWithUnion
133
133
expect (
134
- await getSchemaBox ( {
134
+ getSchemaBox ( {
135
135
type : "object" ,
136
136
properties : {
137
137
union : { oneOf : [ { type : "string" } , { type : "number" } ] } ,
138
138
} ,
139
139
} ) ,
140
140
) . toMatchInlineSnapshot ( '"export type _Test = Partial<{ union: string | number }>;"' ) ;
141
- expect ( await getSchemaBox ( { oneOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot (
141
+ expect ( getSchemaBox ( { oneOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot (
142
142
'"export type _Test = string | number;"' ,
143
143
) ;
144
144
145
145
// StringOrNumber
146
- expect ( await getSchemaBox ( { oneOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot ( '"export type _Test = string | number;"' ) ;
146
+ expect ( getSchemaBox ( { oneOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot ( '"export type _Test = string | number;"' ) ;
147
147
148
- expect ( await getSchemaBox ( { allOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot (
148
+ expect ( getSchemaBox ( { allOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot (
149
149
'"export type _Test = string & number;"' ,
150
150
) ;
151
151
152
152
// StringAndNumber
153
- expect ( await getSchemaBox ( { allOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot ( '"export type _Test = string & number;"' ) ;
153
+ expect ( getSchemaBox ( { allOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot ( '"export type _Test = string & number;"' ) ;
154
154
155
- expect ( await getSchemaBox ( { anyOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot (
155
+ expect ( getSchemaBox ( { anyOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot (
156
156
'"export type _Test = string | number | Array<string | number>;"' ,
157
157
) ;
158
158
159
159
// StringAndNumberMaybeMultiple
160
- expect ( await getSchemaBox ( { anyOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot ( '"export type _Test = string | number | Array<string | number>;"' ) ;
160
+ expect ( getSchemaBox ( { anyOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot ( '"export type _Test = string | number | Array<string | number>;"' ) ;
161
161
162
162
// ObjectWithArrayUnion
163
163
expect (
164
- await getSchemaBox ( {
164
+ getSchemaBox ( {
165
165
type : "object" ,
166
166
properties : {
167
167
unionOrArrayOfUnion : { anyOf : [ { type : "string" } , { type : "number" } ] } ,
@@ -171,18 +171,18 @@ test("getSchemaBox", async () => {
171
171
172
172
// ObjectWithIntersection
173
173
expect (
174
- await getSchemaBox ( {
174
+ getSchemaBox ( {
175
175
type : "object" ,
176
176
properties : {
177
177
intersection : { allOf : [ { type : "string" } , { type : "number" } ] } ,
178
178
} ,
179
179
} ) ,
180
180
) . toMatchInlineSnapshot ( '"export type _Test = Partial<{ intersection: string & number }>;"' ) ;
181
181
182
- expect ( await getSchemaBox ( { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ) ) . toMatchInlineSnapshot (
182
+ expect ( getSchemaBox ( { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ) ) . toMatchInlineSnapshot (
183
183
'"export type _Test = "aaa" | "bbb" | "ccc";"' ,
184
184
) ;
185
- expect ( await getSchemaBox ( { type : "number" , enum : [ 1 , 2 , 3 ] } ) ) . toMatchInlineSnapshot ( '"export type _Test = 1 | 2 | 3;"' ) ;
185
+ expect ( getSchemaBox ( { type : "number" , enum : [ 1 , 2 , 3 ] } ) ) . toMatchInlineSnapshot ( '"export type _Test = 1 | 2 | 3;"' ) ;
186
186
} ) ;
187
187
188
188
describe ( "getSchemaBox with context" , ( ) => {
0 commit comments