File tree 3 files changed +132
-4
lines changed
packages/mock/src/faker/getters
3 files changed +132
-4
lines changed Original file line number Diff line number Diff line change @@ -115,17 +115,18 @@ export const getMockScalar = ({
115
115
`faker.number.int({min: ${ item . minimum } , max: ${ item . maximum } })` ,
116
116
item . nullable ,
117
117
) ;
118
+ let numberImports : GeneratorImport [ ] = [ ] ;
118
119
if ( item . enum ) {
119
120
// By default the value isn't a reference, so we don't have the object explicitly defined.
120
121
// So we have to create an array with the enum values and force them to be a const.
121
- const joindEnumValues = item . enum . filter ( Boolean ) . join ( ',' ) ;
122
+ const joinedEnumValues = item . enum . filter ( Boolean ) . join ( ',' ) ;
122
123
123
- let enumValue = `[${ joindEnumValues } ] as const` ;
124
+ let enumValue = `[${ joinedEnumValues } ] as const` ;
124
125
125
126
// But if the value is a reference, we can use the object directly via the imports and using Object.values.
126
127
if ( item . isRef ) {
127
128
enumValue = `Object.values(${ item . name } )` ;
128
- imports = [
129
+ numberImports = [
129
130
{
130
131
name : item . name ,
131
132
values : true ,
@@ -142,7 +143,7 @@ export const getMockScalar = ({
142
143
}
143
144
return {
144
145
value,
145
- imports : [ ] ,
146
+ imports : numberImports ,
146
147
name : item . name ,
147
148
} ;
148
149
}
Original file line number Diff line number Diff line change @@ -114,4 +114,16 @@ export default defineConfig({
114
114
target : '../specifications/null-type.yaml' ,
115
115
} ,
116
116
} ,
117
+ enumRefs : {
118
+ output : {
119
+ mode : 'tags' ,
120
+ schemas : '../generated/mock/enumRefs/model' ,
121
+ target : '../generated/mock/enumRefs/endpoints.ts' ,
122
+ client : 'axios' ,
123
+ mock : true ,
124
+ } ,
125
+ input : {
126
+ target : '../specifications/enum-refs.yaml' ,
127
+ } ,
128
+ } ,
117
129
} ) ;
Original file line number Diff line number Diff line change
1
+ openapi : 3.0.1
2
+ info :
3
+ title : Sample API
4
+ description : ' A sample api'
5
+ version : ' 1.0'
6
+ paths :
7
+ ' /sampleApi ' :
8
+ get :
9
+ tags :
10
+ - Sample
11
+ responses :
12
+ ' 200 ' :
13
+ description : Success
14
+ content :
15
+ application/json :
16
+ schema :
17
+ $ref : ' #/components/schemas/SampleStepsResponse'
18
+ components :
19
+ schemas :
20
+ SampleAccountStatus :
21
+ enum :
22
+ - 0
23
+ - 1
24
+ - 2
25
+ - 3
26
+ type : integer
27
+ format : int32
28
+ x-enumNames :
29
+ - Unknown
30
+ - NotStarted
31
+ - InProgress
32
+ - Completed
33
+ SampleStepResponse :
34
+ type : object
35
+ properties :
36
+ stepKey :
37
+ type : string
38
+ nullable : true
39
+ groupKey :
40
+ type : string
41
+ nullable : true
42
+ displayName :
43
+ type : string
44
+ nullable : true
45
+ description :
46
+ type : string
47
+ nullable : true
48
+ staffInstructions :
49
+ type : string
50
+ nullable : true
51
+ clientInstructions :
52
+ type : string
53
+ nullable : true
54
+ lastModifiedOn :
55
+ type : string
56
+ format : date-time
57
+ lastModifiedBy :
58
+ type : string
59
+ nullable : true
60
+ stepStatus :
61
+ $ref : ' #/components/schemas/SampleStepStatus'
62
+ statusChanges :
63
+ type : array
64
+ items :
65
+ $ref : ' #/components/schemas/SampleStepStatusChangeResponse'
66
+ nullable : true
67
+ additionalProperties : false
68
+ SampleStepStatus :
69
+ enum :
70
+ - 0
71
+ - 1
72
+ - 2
73
+ - 3
74
+ - 4
75
+ - 5
76
+ - 6
77
+ type : integer
78
+ format : int32
79
+ x-enumNames :
80
+ - Unknown
81
+ - NotStarted
82
+ - InProgress
83
+ - Completed
84
+ - Skipped
85
+ - Waiting
86
+ - ReadyForReview
87
+ SampleStepStatusChangeResponse :
88
+ type : object
89
+ properties :
90
+ oldStatus :
91
+ $ref : ' #/components/schemas/SampleStepStatus'
92
+ newStatus :
93
+ $ref : ' #/components/schemas/SampleStepStatus'
94
+ stepKey :
95
+ type : string
96
+ nullable : true
97
+ modifiedOn :
98
+ type : string
99
+ format : date-time
100
+ modifiedBy :
101
+ type : string
102
+ nullable : true
103
+ additionalProperties : false
104
+ SampleStepsResponse :
105
+ type : object
106
+ properties :
107
+ organizationId :
108
+ type : string
109
+ format : uuid
110
+ steps :
111
+ type : array
112
+ items :
113
+ $ref : ' #/components/schemas/SampleStepResponse'
114
+ nullable : true
115
+ additionalProperties : false
You can’t perform that action at this time.
0 commit comments