@@ -23,7 +23,7 @@ import { join } from "path"
23
23
export const parseSchema = (
24
24
schemaValue : OpenAPIV3_1 . ReferenceObject | OpenAPIV3_1 . SchemaObject ,
25
25
specialSchema : ReturnType < typeof specialFakerParser > ,
26
- isStatic : boolean ,
26
+ options : Options ,
27
27
outputSchema : ParseSchemaType = { }
28
28
) : ParseSchemaType => {
29
29
if ( isReference ( schemaValue ) ) {
@@ -35,45 +35,45 @@ export const parseSchema = (
35
35
if ( schemaValue . properties === undefined ) return { }
36
36
return Object . entries ( schemaValue . properties ) . reduce (
37
37
( acc , [ key , field ] ) => {
38
- acc [ key ] = parseSchema ( field , specialSchema , isStatic , outputSchema ) as SchemaOutputType
38
+ acc [ key ] = parseSchema ( field , specialSchema , options , outputSchema ) as SchemaOutputType
39
39
return acc
40
40
} ,
41
41
{ } as Record < string , SchemaOutputType >
42
42
)
43
43
} else if ( schemaValue . enum !== undefined ) {
44
44
// enum value
45
- const enumValue = isStatic
45
+ const enumValue = options . isStatic
46
46
? faker . helpers . arrayElement ( schemaValue . enum )
47
47
: `faker.helpers.arrayElement(${ toUnquotedJSON ( schemaValue . enum , {
48
48
depth : 0 ,
49
- isStatic,
49
+ isStatic : options . isStatic ,
50
50
singleLine : true ,
51
51
} ) } )`
52
- if ( isStatic && typeof enumValue === "string" ) return enumValue + " as const"
52
+ if ( options . isStatic && typeof enumValue === "string" ) return enumValue + " as const"
53
53
return enumValue
54
54
} else if ( schemaValue . allOf !== undefined ) {
55
55
// allOf value, sub model
56
56
const allOfValue = schemaValue . allOf
57
57
return faker . helpers . arrayElement (
58
58
allOfValue . map ( ( field ) => {
59
- return parseSchema ( field , specialSchema , isStatic , outputSchema )
59
+ return parseSchema ( field , specialSchema , options , outputSchema )
60
60
} )
61
61
)
62
62
} else if ( schemaValue . anyOf !== undefined ) {
63
63
// anyOf value, select one or more. ex) string or null
64
64
const anyOfValue = schemaValue . anyOf
65
- return isStatic
65
+ return options . isStatic
66
66
? faker . helpers . arrayElement (
67
67
anyOfValue . map ( ( field ) => {
68
- return parseSchema ( field , specialSchema , isStatic , outputSchema )
68
+ return parseSchema ( field , specialSchema , options , outputSchema )
69
69
} )
70
70
)
71
71
: multiLineStr ( `
72
72
faker.helpers.arrayElement([
73
73
${ anyOfValue . map ( ( field ) =>
74
- toUnquotedJSON ( parseSchema ( field , specialSchema , isStatic , { } ) , {
74
+ toUnquotedJSON ( parseSchema ( field , specialSchema , options , { } ) , {
75
75
depth : 0 ,
76
- isStatic,
76
+ isStatic : options . isStatic ,
77
77
singleLine : true ,
78
78
} )
79
79
) }
@@ -82,18 +82,18 @@ export const parseSchema = (
82
82
} else if ( schemaValue . oneOf !== undefined ) {
83
83
// oneOf value, exactly one. Can't find example
84
84
const oneOfValue = schemaValue . oneOf
85
- return isStatic
85
+ return options . isStatic
86
86
? faker . helpers . arrayElement (
87
87
oneOfValue . map ( ( field ) => {
88
- return parseSchema ( field , specialSchema , isStatic , outputSchema )
88
+ return parseSchema ( field , specialSchema , options , outputSchema )
89
89
} )
90
90
)
91
91
: multiLineStr ( `
92
92
faker.helpers.arrayElement([
93
93
${ oneOfValue . map ( ( field ) =>
94
- toUnquotedJSON ( parseSchema ( field , specialSchema , isStatic , { } ) , {
94
+ toUnquotedJSON ( parseSchema ( field , specialSchema , options , { } ) , {
95
95
depth : 0 ,
96
- isStatic,
96
+ isStatic : options . isStatic ,
97
97
singleLine : true ,
98
98
} )
99
99
) }
@@ -102,11 +102,11 @@ export const parseSchema = (
102
102
} else if ( schemaValue . type === "array" ) {
103
103
// array
104
104
const arrayValue = schemaValue . items
105
- return getRandomLengthArray ( ) . map ( ( ) =>
106
- parseSchema ( arrayValue , specialSchema , isStatic , outputSchema )
105
+ return getRandomLengthArray ( options . arrayMinLength , options . arrayMaxLength ) . map ( ( ) =>
106
+ parseSchema ( arrayValue , specialSchema , options , outputSchema )
107
107
) as ( SchemaOutputType | Record < string , SchemaOutputType > ) [ ]
108
108
}
109
- return valueGenerator ( schemaValue , specialSchema , isStatic )
109
+ return valueGenerator ( schemaValue , specialSchema , options . isStatic )
110
110
}
111
111
112
112
const uuidToB64 = ( uuid : string ) => {
@@ -317,7 +317,7 @@ export const specialFakerParser = (options: Options) => {
317
317
const titleSpecial = Object . entries ( titleSpecialKey ) . reduce (
318
318
( acc , [ key , value ] ) => {
319
319
const fakerValue = getFakerValue ( value , {
320
- isStatic : options . static ,
320
+ isStatic : options . isStatic ,
321
321
} )
322
322
acc [ key ] = fakerValue
323
323
return acc
@@ -328,7 +328,7 @@ export const specialFakerParser = (options: Options) => {
328
328
const descriptionSpecial = Object . entries ( descriptionSpecialKey ) . reduce (
329
329
( acc , [ key , value ] ) => {
330
330
const fakerValue = getFakerValue ( value , {
331
- isStatic : options . static ,
331
+ isStatic : options . isStatic ,
332
332
} )
333
333
acc [ key ] = fakerValue
334
334
return acc
0 commit comments