@@ -17,45 +17,45 @@ export const getModel = (
17
17
parentDefinition : OpenApiSchema | null = null
18
18
) : Model => {
19
19
const model : Model = {
20
- name,
21
- export : 'interface' ,
22
- type : 'any' ,
23
20
base : 'any' ,
24
- template : null ,
25
- link : null ,
21
+ deprecated : Boolean ( definition . deprecated ) ,
26
22
description : definition . description || null ,
27
- deprecated : definition . deprecated === true ,
23
+ enum : [ ] ,
24
+ enums : [ ] ,
25
+ exclusiveMaximum : definition . exclusiveMaximum ,
26
+ exclusiveMinimum : definition . exclusiveMinimum ,
27
+ export : 'interface' ,
28
+ format : definition . format ,
29
+ imports : [ ] ,
28
30
isDefinition,
29
- isReadOnly : definition . readOnly === true ,
30
31
isNullable : definition . nullable === true ,
32
+ isReadOnly : definition . readOnly === true ,
31
33
isRequired : false ,
32
- format : definition . format ,
34
+ link : null ,
33
35
maximum : definition . maximum ,
34
- exclusiveMaximum : definition . exclusiveMaximum ,
35
- minimum : definition . minimum ,
36
- exclusiveMinimum : definition . exclusiveMinimum ,
37
- multipleOf : definition . multipleOf ,
38
- maxLength : definition . maxLength ,
39
- minLength : definition . minLength ,
40
36
maxItems : definition . maxItems ,
41
- minItems : definition . minItems ,
42
- uniqueItems : definition . uniqueItems ,
37
+ maxLength : definition . maxLength ,
43
38
maxProperties : definition . maxProperties ,
39
+ minimum : definition . minimum ,
40
+ minItems : definition . minItems ,
41
+ minLength : definition . minLength ,
44
42
minProperties : definition . minProperties ,
43
+ multipleOf : definition . multipleOf ,
44
+ name,
45
45
pattern : getPattern ( definition . pattern ) ,
46
- imports : [ ] ,
47
- enum : [ ] ,
48
- enums : [ ] ,
49
46
properties : [ ] ,
47
+ template : null ,
48
+ type : 'any' ,
49
+ uniqueItems : definition . uniqueItems ,
50
50
} ;
51
51
52
52
if ( definition . $ref ) {
53
53
const definitionRef = getType ( definition . $ref ) ;
54
- model . export = 'reference' ;
55
- model . type = definitionRef . type ;
56
54
model . base = definitionRef . base ;
57
- model . template = definitionRef . template ;
55
+ model . export = 'reference' ;
58
56
model . imports . push ( ...definitionRef . imports ) ;
57
+ model . template = definitionRef . template ;
58
+ model . type = definitionRef . type ;
59
59
model . default = getModelDefault ( definition , model ) ;
60
60
return model ;
61
61
}
@@ -64,10 +64,10 @@ export const getModel = (
64
64
const enumerators = getEnum ( definition . enum ) ;
65
65
const extendedEnumerators = extendEnum ( enumerators , definition ) ;
66
66
if ( extendedEnumerators . length ) {
67
- model . export = 'enum' ;
68
- model . type = 'string' ;
69
67
model . base = 'string' ;
70
68
model . enum . push ( ...extendedEnumerators ) ;
69
+ model . export = 'enum' ;
70
+ model . type = 'string' ;
71
71
model . default = getModelDefault ( definition , model ) ;
72
72
return model ;
73
73
}
@@ -76,11 +76,11 @@ export const getModel = (
76
76
if ( definition . type === 'array' && definition . items ) {
77
77
if ( definition . items . $ref ) {
78
78
const arrayItems = getType ( definition . items . $ref ) ;
79
- model . export = 'array' ;
80
- model . type = arrayItems . type ;
81
79
model . base = arrayItems . base ;
82
- model . template = arrayItems . template ;
80
+ model . export = 'array' ;
83
81
model . imports . push ( ...arrayItems . imports ) ;
82
+ model . template = arrayItems . template ;
83
+ model . type = arrayItems . type ;
84
84
model . default = getModelDefault ( definition , model ) ;
85
85
return model ;
86
86
}
@@ -93,12 +93,12 @@ export const getModel = (
93
93
}
94
94
95
95
const arrayItems = getModel ( openApi , definition . items ) ;
96
- model . export = 'array' ;
97
- model . type = arrayItems . type ;
98
96
model . base = arrayItems . base ;
99
- model . template = arrayItems . template ;
100
- model . link = arrayItems ;
97
+ model . export = 'array' ;
101
98
model . imports . push ( ...arrayItems . imports ) ;
99
+ model . link = arrayItems ;
100
+ model . template = arrayItems . template ;
101
+ model . type = arrayItems . type ;
102
102
model . default = getModelDefault ( definition , model ) ;
103
103
return model ;
104
104
}
@@ -117,15 +117,15 @@ export const getModel = (
117
117
118
118
if ( definition . type === 'object' ) {
119
119
if ( definition . properties ) {
120
+ model . base = 'any' ;
120
121
model . export = 'interface' ;
121
122
model . type = 'any' ;
122
- model . base = 'any' ;
123
123
model . default = getModelDefault ( definition , model ) ;
124
124
125
125
const modelProperties = getModelProperties ( openApi , definition , getModel , model ) ;
126
126
modelProperties . forEach ( modelProperty => {
127
- model . imports . push ( ...modelProperty . imports ) ;
128
127
model . enums . push ( ...modelProperty . enums ) ;
128
+ model . imports . push ( ...modelProperty . imports ) ;
129
129
model . properties . push ( modelProperty ) ;
130
130
if ( modelProperty . export === 'enum' ) {
131
131
model . enums . push ( modelProperty ) ;
@@ -144,23 +144,23 @@ export const getModel = (
144
144
}
145
145
146
146
if ( definition . const !== undefined ) {
147
- model . export = 'const' ;
148
147
const definitionConst = definition . const ;
149
148
const modelConst = typeof definitionConst === 'string' ? `"${ definitionConst } "` : `${ definitionConst } ` ;
150
- model . type = modelConst ;
151
149
model . base = modelConst ;
150
+ model . export = 'const' ;
151
+ model . type = modelConst ;
152
152
return model ;
153
153
}
154
154
155
155
// If the schema has a type than it can be a basic or generic type.
156
156
if ( definition . type ) {
157
157
const definitionType = getType ( definition . type , definition . format ) ;
158
- model . export = 'generic' ;
159
- model . type = definitionType . type ;
160
158
model . base = definitionType . base ;
161
- model . template = definitionType . template ;
162
- model . isNullable = definitionType . isNullable || model . isNullable ;
159
+ model . export = 'generic' ;
163
160
model . imports . push ( ...definitionType . imports ) ;
161
+ model . isNullable = definitionType . isNullable || model . isNullable ;
162
+ model . template = definitionType . template ;
163
+ model . type = definitionType . type ;
164
164
model . default = getModelDefault ( definition , model ) ;
165
165
return model ;
166
166
}
0 commit comments