@@ -48,7 +48,7 @@ const printTraversable = (traversable: t.F<any>, ctx: OpenapiSchemaConvertContex
48
48
format : FORMAT = defaults . format ,
49
49
maxWidth : MAX_WIDTH = defaults . maxWidth ,
50
50
} = options ;
51
- const out = t . foldWithIndex < string > ( ( x , ix ) => {
51
+ const out = t . foldWithIndex < string | { $ref : string } > ( ( x , ix ) => {
52
52
const { depth } = ix ;
53
53
const OFFSET = OFF + depth * 2 ;
54
54
const JOIN = ",\n" + " " . repeat ( depth + 1 ) ;
@@ -64,7 +64,7 @@ const printTraversable = (traversable: t.F<any>, ctx: OpenapiSchemaConvertContex
64
64
const refSchema = ctx . refs . get ( x . def [ "$ref" ] ) ;
65
65
console . log ( { x, ref : x . def [ "$ref" ] , refSchema } ) ;
66
66
const refTraversable = openApiSchemaToTs ( { schema : refSchema , ctx } ) ;
67
- return refTraversable . toType ( ) ;
67
+ return toType ( refTraversable ) ;
68
68
}
69
69
case x . tag === URI . eq :
70
70
return jsonToString ( x . def , options , ix ) ;
@@ -161,7 +161,7 @@ test("empty object", () => {
161
161
} ) ;
162
162
test ( "object with properties" , ( ) => {
163
163
expect ( getSchemaBox ( { type : "object" , properties : { str : { type : "string" } } } ) ) . toMatchInlineSnapshot (
164
- `"{ ' str' : string }"` ,
164
+ `"{ str: string }"` ,
165
165
) ;
166
166
} ) ;
167
167
test ( "object with properties nullable" , ( ) => {
@@ -177,7 +177,7 @@ test("object with properties nullable", () => {
177
177
} ,
178
178
} ,
179
179
} ) ,
180
- ) . toMatchInlineSnapshot ( `"{ ' str' : string, 'nb' : number, ' nullable' : (string | null) }"` ) ;
180
+ ) . toMatchInlineSnapshot ( `"{ str: string, nb : number, nullable: (string | null) }"` ) ;
181
181
} ) ;
182
182
test ( "object with all properties required" , ( ) => {
183
183
// AllPropertiesRequired
@@ -187,7 +187,7 @@ test("object with all properties required", () => {
187
187
properties : { str : { type : "string" } , nb : { type : "number" } } ,
188
188
required : [ "str" , "nb" ] ,
189
189
} ) ,
190
- ) . toMatchInlineSnapshot ( `"{ ' str' : string, 'nb' : number }"` ) ;
190
+ ) . toMatchInlineSnapshot ( `"{ str: string, nb : number }"` ) ;
191
191
} ) ;
192
192
test ( "object with some optional properties" , ( ) => {
193
193
// SomeOptionalProps
@@ -197,7 +197,7 @@ test("object with some optional properties", () => {
197
197
properties : { str : { type : "string" } , nb : { type : "number" } } ,
198
198
required : [ "str" ] ,
199
199
} ) ,
200
- ) . toMatchInlineSnapshot ( `"{ ' str' : string, 'nb' ?: (number | undefined) }"` ) ;
200
+ ) . toMatchInlineSnapshot ( `"{ str: string, nb ?: (number | undefined) }"` ) ;
201
201
} ) ;
202
202
test ( "object with nested property" , ( ) => {
203
203
// ObjectWithNestedProp
@@ -215,13 +215,13 @@ test("object with nested property", () => {
215
215
} ,
216
216
} ,
217
217
} ) ,
218
- ) . toMatchInlineSnapshot ( `"{ ' str' : string, 'nb' : number, ' nested' : { ' nested_prop' : boolean } }"` ) ;
218
+ ) . toMatchInlineSnapshot ( `"{ str: string, nb : number, nested: { nested_prop: boolean } }"` ) ;
219
219
} ) ;
220
220
test ( "object with additional properties" , ( ) => {
221
221
// ObjectWithAdditionalPropsNb
222
222
expect (
223
223
getSchemaBox ( { type : "object" , properties : { str : { type : "string" } } , additionalProperties : { type : "number" } } ) ,
224
- ) . toMatchInlineSnapshot ( `"({ ' str' : string } & Record<string, number>)"` ) ;
224
+ ) . toMatchInlineSnapshot ( `"({ str: string } & Record<string, number>)"` ) ;
225
225
} ) ;
226
226
test ( "object with nested record boolean" , ( ) => {
227
227
// ObjectWithNestedRecordBoolean
@@ -231,7 +231,7 @@ test("object with nested record boolean", () => {
231
231
properties : { str : { type : "string" } } ,
232
232
additionalProperties : { type : "object" , properties : { prop : { type : "boolean" } } } ,
233
233
} ) ,
234
- ) . toMatchInlineSnapshot ( `"({ ' str' : string } & Record<string, { ' prop' : boolean }>)"` ) ;
234
+ ) . toMatchInlineSnapshot ( `"({ str: string } & Record<string, { prop: boolean }>)"` ) ;
235
235
} ) ;
236
236
test ( "array with object with nested property" , ( ) => {
237
237
expect (
@@ -245,7 +245,7 @@ test("array with object with nested property", () => {
245
245
} ,
246
246
} ,
247
247
} ) ,
248
- ) . toMatchInlineSnapshot ( `"({ ' str' : string, ' nullable' : (string | null) })[]"` ) ;
248
+ ) . toMatchInlineSnapshot ( `"({ str: string, nullable: (string | null) })[]"` ) ;
249
249
} ) ;
250
250
test ( "array with array" , ( ) => {
251
251
expect (
@@ -269,17 +269,17 @@ test("object with enum", () => {
269
269
enumprop : { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ,
270
270
} ,
271
271
} ) ,
272
- ) . toMatchInlineSnapshot ( `"{ ' enumprop' : (' aaa' | ' bbb' | ' ccc' ) }"` ) ;
272
+ ) . toMatchInlineSnapshot ( `"{ enumprop: (" aaa" | " bbb" | " ccc" ) }"` ) ;
273
273
} ) ;
274
274
test ( "string enum" , ( ) => {
275
275
expect ( getSchemaBox ( { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ) ) . toMatchInlineSnapshot (
276
- `"(' aaa' | ' bbb' | ' ccc' )"` ,
276
+ `"(" aaa" | " bbb" | " ccc" )"` ,
277
277
) ;
278
278
} ) ;
279
279
test ( "string enum" , ( ) => {
280
280
// StringENum
281
281
expect ( getSchemaBox ( { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ) ) . toMatchInlineSnapshot (
282
- `"(' aaa' | ' bbb' | ' ccc' )"` ,
282
+ `"(" aaa" | " bbb" | " ccc" )"` ,
283
283
) ;
284
284
} ) ;
285
285
test ( "object with union" , ( ) => {
@@ -291,7 +291,7 @@ test("object with union", () => {
291
291
union : { oneOf : [ { type : "string" } , { type : "number" } ] } ,
292
292
} ,
293
293
} ) ,
294
- ) . toMatchInlineSnapshot ( `"{ ' union' : (string | number) }"` ) ;
294
+ ) . toMatchInlineSnapshot ( `"{ union: (string | number) }"` ) ;
295
295
} ) ;
296
296
test ( "union" , ( ) => {
297
297
expect ( getSchemaBox ( { oneOf : [ { type : "string" } , { type : "number" } ] } ) ) . toMatchInlineSnapshot (
@@ -335,7 +335,7 @@ test("object with array union", () => {
335
335
unionOrArrayOfUnion : { anyOf : [ { type : "string" } , { type : "number" } ] } ,
336
336
} ,
337
337
} ) ,
338
- ) . toMatchInlineSnapshot ( `"{ ' unionOrArrayOfUnion' : (string | number) }"` ) ;
338
+ ) . toMatchInlineSnapshot ( `"{ unionOrArrayOfUnion: (string | number) }"` ) ;
339
339
} ) ;
340
340
test ( "object with intersection" , ( ) => {
341
341
// ObjectWithIntersection
@@ -346,11 +346,11 @@ test("object with intersection", () => {
346
346
intersection : { allOf : [ { type : "string" } , { type : "number" } ] } ,
347
347
} ,
348
348
} ) ,
349
- ) . toMatchInlineSnapshot ( `"{ ' intersection' : (string & number) }"` ) ;
349
+ ) . toMatchInlineSnapshot ( `"{ intersection: (string & number) }"` ) ;
350
350
} ) ;
351
351
test ( "string enum" , ( ) => {
352
352
expect ( getSchemaBox ( { type : "string" , enum : [ "aaa" , "bbb" , "ccc" ] } ) ) . toMatchInlineSnapshot (
353
- `"(' aaa' | ' bbb' | ' ccc' )"` ,
353
+ `"(" aaa" | " bbb" | " ccc" )"` ,
354
354
) ;
355
355
} ) ;
356
356
test ( "number enum" , ( ) => {
@@ -361,7 +361,7 @@ test("number enum - single", () => {
361
361
} ) ;
362
362
test ( "enum" , ( ) => {
363
363
expect ( getSchemaBox ( { enum : [ "red" , "amber" , "green" , null , 42 , true ] } ) ) . toMatchInlineSnapshot (
364
- `"(' red' | ' amber' | ' green' | null | 42 | true)"` ,
364
+ `"(" red" | " amber" | " green" | null | 42 | true)"` ,
365
365
) ;
366
366
} ) ;
367
367
test ( "object with array of object with properties" , ( ) => {
@@ -400,7 +400,7 @@ test("object with array of object with properties", () => {
400
400
required : [ "members" ] ,
401
401
} ) ,
402
402
) . toMatchInlineSnapshot (
403
- `"{ ' members' : ({ 'id' : string, ' firstName' ?: ((string | null) | undefined), ' lastName' ?: ((string | null) | undefined), ' email' : string, ' profilePictureURL' ?: ((string | null) | undefined) })[] }"` ,
403
+ `"{ members: ({ id : string, firstName?: ((string | null) | undefined), lastName?: ((string | null) | undefined), email: string, profilePictureURL?: ((string | null) | undefined) })[] }"` ,
404
404
) ;
405
405
} ) ;
406
406
@@ -425,7 +425,7 @@ describe("getSchemaBox with context", () => {
425
425
426
426
const ctx = makeCtx ( schemas ) ;
427
427
expect ( printTraversable ( openApiSchemaToTs ( { schema : schemas [ "Root" ] ! , ctx } ) , ctx ) ) . toMatchInlineSnapshot (
428
- `"t.object( { str: t. string, nb: t. number, nested: t.eq({ $ref: "#/components/schemas/Nested" }) }) "` ,
428
+ `"{ str: string, nb: number, nested: { nested_prop: boolean } } "` ,
429
429
) ;
430
430
} ) ;
431
431
@@ -450,7 +450,7 @@ describe("getSchemaBox with context", () => {
450
450
451
451
const ctx = makeCtx ( schemas ) ;
452
452
expect ( printTraversable ( openApiSchemaToTs ( { schema : schemas [ "Extends" ] ! , ctx } ) , ctx ) ) . toMatchInlineSnapshot (
453
- `"t.intersect(t.eq({ $ref: "#/components/schemas/Base" }), t.object( { str: t. string, nb: t.optional(t. number) }) )"` ,
453
+ `"({ baseProp: string } & { str: string, nb?: ( number | undefined ) })"` ,
454
454
) ;
455
455
} ) ;
456
456
@@ -483,7 +483,7 @@ describe("getSchemaBox with context", () => {
483
483
484
484
const ctx = makeCtx ( schemas ) ;
485
485
expect ( printTraversable ( openApiSchemaToTs ( { schema : schemas [ "Root2" ] ! , ctx } ) , ctx ) ) . toMatchInlineSnapshot (
486
- `"t.object( { str: t. string, nb: t. number, nested: t.eq({ $ref: "#/components/schemas/Nested2" }) }) "` ,
486
+ `"{ str: string, nb: number, nested: { nested_prop: boolean, deeplyNested: (("aaa" | "bbb" | "ccc"))[] } } "` ,
487
487
) ;
488
488
} ) ;
489
489
@@ -510,7 +510,7 @@ describe("getSchemaBox with context", () => {
510
510
const ctx = makeCtx ( schemas ) ;
511
511
512
512
expect ( printTraversable ( openApiSchemaToTs ( { schema : schemas [ "Root3" ] ! , ctx } ) , ctx ) ) . toMatchInlineSnapshot (
513
- `"t.object( { str: t. string, nb: t. number, nested: t.eq({ $ref: "#/components/schemas/Nested3" }) , arrayOfNested: t.array(t.eq({ $ref: "#/components/schemas/Nested3" })) }) "` ,
513
+ `"{ str: string, nb: number, nested: { 'nested_prop': boolean, 'backToRoot': string } , arrayOfNested: ({ 'nested_prop': boolean, 'backToRoot': string })[] } "` ,
514
514
) ;
515
515
} ) ;
516
516
@@ -539,7 +539,7 @@ describe("getSchemaBox with context", () => {
539
539
const result = openApiSchemaToTs ( { schema : schemas [ "Root4" ] ! , ctx } ) ;
540
540
541
541
expect ( printTraversable ( result , ctx ) ) . toMatchInlineSnapshot (
542
- `"t.object( { str: t. string, nb: t. number, self: t.eq({ $ref: "#/components/schemas/Root4" }), nested: t.eq({ $ref: "#/components/schemas/Nested4" }) , arrayOfSelf: t.array(t.eq({ $ref: "#/components/schemas/Root4" })) })"` ,
542
+ `"{ str: string, nb: number, self: { 'str': string, 'nb': number, 'self': string, ' nested': string, 'arrayOfSelf': (string)[] }, nested: { 'nested_prop': boolean, 'backToRoot': string } , arrayOfSelf: ({ 'str': string, 'nb': number, 'self': string, 'nested': string, 'arrayOfSelf': (string)[] })[] } "` ,
543
543
) ;
544
544
} ) ;
545
545
@@ -573,7 +573,7 @@ describe("getSchemaBox with context", () => {
573
573
const result = openApiSchemaToTs ( { schema : schemas [ "Root" ] ! , ctx } ) ;
574
574
575
575
expect ( printTraversable ( result , ctx ) ) . toMatchInlineSnapshot (
576
- `"t.object( { recursive: t.eq({ $ref: "#/components/schemas/User" }) , basic: t. number }) "` ,
576
+ `"{ recursive: { 'name': string, 'middle': string } , basic: number }"` ,
577
577
) ;
578
578
} ) ;
579
579
@@ -610,7 +610,7 @@ describe("getSchemaBox with context", () => {
610
610
const result = openApiSchemaToTs ( { schema : schemas [ "Root" ] ! , ctx } ) ;
611
611
612
612
expect ( printTraversable ( result , ctx ) ) . toMatchInlineSnapshot (
613
- `"t.object( { user: t.union(t.eq({ $ref: "#/components/schemas/User" }), t.eq({ $ref: "#/components/schemas/Member" })) , users: t.array(t.union(t.eq({ $ref: "#/components/schemas/User" }), t.eq({ $ref: "#/components/schemas/Member" }))) , basic: t. number }) "` ,
613
+ `"{ user: ({ name: string } | { name: string }), users: (({ name: string } | { name: string }))[] , basic: number }"` ,
614
614
) ;
615
615
} ) ;
616
616
@@ -626,8 +626,8 @@ describe("getSchemaBox with context", () => {
626
626
} satisfies SchemasObject ;
627
627
628
628
const ctx = makeCtx ( schemas ) ;
629
- const result = openApiSchemaToTs ( { schema : schemat . Member , ctx } ) ;
629
+ const result = openApiSchemaToTs ( { schema : schemas . Member , ctx } ) ;
630
630
631
- expect ( printTraversable ( result , ctx ) ) . toMatchInlineSnapshot ( `"t.object( { name: t.union(t. string, t. null) }) "` ) ;
631
+ expect ( printTraversable ( result , ctx ) ) . toMatchInlineSnapshot ( `"{ name: ( string | null) }"` ) ;
632
632
} ) ;
633
633
} ) ;
0 commit comments