@@ -132,11 +132,20 @@ const getComplexType = (schema) => {
132
132
throw new Error ( "Uknown complex type" ) ;
133
133
} ;
134
134
135
+ const attachParsedRef = ( originalSchema , parsedSchema ) => {
136
+ if ( originalSchema ) {
137
+ originalSchema . $parsed = parsedSchema ;
138
+ }
139
+
140
+ return parsedSchema ;
141
+ } ;
142
+
135
143
const schemaParsers = {
136
144
enum : ( schema , typeName ) => {
137
145
const type = getType ( schema ) ;
138
146
const isIntegerEnum = type === types . number ;
139
- return {
147
+
148
+ return attachParsedRef ( schema , {
140
149
$parsedSchema : true ,
141
150
schemaType : "enum" ,
142
151
type : isIntegerEnum ? "intEnum" : "enum" ,
@@ -148,7 +157,7 @@ const schemaParsers = {
148
157
type,
149
158
value : isIntegerEnum ? `${ key } ` : `"${ key } "` ,
150
159
} ) ) ,
151
- } ;
160
+ } ) ;
152
161
} ,
153
162
object : ( schema , typeName ) => {
154
163
if ( _ . isArray ( schema . required ) && schema . properties ) {
@@ -162,7 +171,7 @@ const schemaParsers = {
162
171
const properties = _ . get ( schema , "properties" ) ;
163
172
const typeContent = getObjectTypeContent ( properties ) ;
164
173
165
- return {
174
+ return attachParsedRef ( schema , {
166
175
$parsedSchema : true ,
167
176
schemaType : "object" ,
168
177
type : "object" ,
@@ -171,20 +180,20 @@ const schemaParsers = {
171
180
description : formatDescription ( schema . description ) ,
172
181
allFieldsAreOptional : ! _ . some ( _ . values ( typeContent ) , ( part ) => part . isRequired ) ,
173
182
content : typeContent ,
174
- } ;
183
+ } ) ;
175
184
} ,
176
185
complex : ( schema , typeName ) => {
177
186
const complexType = getComplexType ( schema ) ;
178
187
179
- return {
188
+ return attachParsedRef ( schema , {
180
189
$parsedSchema : true ,
181
190
schemaType : "complex" ,
182
191
type : "type" ,
183
192
typeIdentifier : "type" ,
184
193
name : typeName ,
185
194
description : formatDescription ( schema . description ) ,
186
195
content : complexSchemaParsers [ complexType ] ( schema ) ,
187
- } ;
196
+ } ) ;
188
197
} ,
189
198
primitive : ( schema , typeName ) => {
190
199
let contentType = null ;
@@ -195,7 +204,7 @@ const schemaParsers = {
195
204
contentType = `Record<string, ${ fieldType } >` ;
196
205
}
197
206
198
- return {
207
+ return attachParsedRef ( schema , {
199
208
$parsedSchema : true ,
200
209
schemaType : "primitive" ,
201
210
type : "primitive" ,
@@ -204,7 +213,7 @@ const schemaParsers = {
204
213
description : formatDescription ( description ) ,
205
214
// TODO: probably it should be refactored. `type === 'null'` is not flexible
206
215
content : type === "null" ? type : contentType || getType ( schema ) ,
207
- } ;
216
+ } ) ;
208
217
} ,
209
218
} ;
210
219
@@ -227,9 +236,9 @@ const parseSchema = (rawSchema, typeName, formattersMap) => {
227
236
return rawSchema ;
228
237
}
229
238
230
- if ( rawSchema . $parsedSchema ) {
231
- schemaType = rawSchema . schemaType ;
232
- parsedSchema = rawSchema ;
239
+ if ( rawSchema . $parsed ) {
240
+ schemaType = rawSchema . $parsed . schemaType ;
241
+ parsedSchema = rawSchema . $parsed ;
233
242
} else {
234
243
const fixedRawSchema = checkAndFixSchema ( rawSchema ) ;
235
244
schemaType = getInternalSchemaType ( fixedRawSchema ) ;
0 commit comments