@@ -4,6 +4,7 @@ const { MonoSchemaParser } = require('../mono-schema-parser');
4
4
5
5
class DiscriminatorSchemaParser extends MonoSchemaParser {
6
6
parse ( ) {
7
+ const ts = this . config . Ts ;
7
8
const { discriminator, ...noDiscriminatorSchema } = this . schema ;
8
9
9
10
if ( ! discriminator . mapping ) {
@@ -27,7 +28,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
27
28
abstractSchemaStruct,
28
29
} ) ;
29
30
30
- const schemaContent = this . config . Ts . IntersectionType (
31
+ const schemaContent = ts . IntersectionType (
31
32
[
32
33
abstractSchemaStruct ?. content ,
33
34
discriminatorSchemaStruct ?. content ,
@@ -40,7 +41,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
40
41
$parsedSchema : true ,
41
42
schemaType : SCHEMA_TYPES . COMPLEX ,
42
43
type : SCHEMA_TYPES . PRIMITIVE ,
43
- typeIdentifier : this . config . Ts . Keyword . Type ,
44
+ typeIdentifier : ts . Keyword . Type ,
44
45
name : this . typeName ,
45
46
description : this . schemaFormatters . formatDescription (
46
47
this . schema . description ,
@@ -50,6 +51,8 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
50
51
}
51
52
52
53
createDiscriminatorSchema = ( { skipMappingType, abstractSchemaStruct } ) => {
54
+ const ts = this . config . Ts ;
55
+
53
56
const refPath = this . schemaComponentsMap . createRef ( [
54
57
'components' ,
55
58
'schemas' ,
@@ -87,10 +90,10 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
87
90
mappingTypeName ,
88
91
] ) ,
89
92
) ,
90
- content : this . config . Ts . IntersectionType ( [
91
- this . config . Ts . ObjectWrapper (
92
- this . config . Ts . TypeField ( {
93
- key : this . config . Ts . StringValue ( discriminator . propertyName ) ,
93
+ content : ts . IntersectionType ( [
94
+ ts . ObjectWrapper (
95
+ ts . TypeField ( {
96
+ key : ts . StringValue ( discriminator . propertyName ) ,
94
97
value : 'Key' ,
95
98
} ) ,
96
99
) ,
@@ -112,18 +115,15 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
112
115
113
116
const mappingUsageKey =
114
117
mappingPropertySchemaEnumKeysMap [ mappingKey ] ||
115
- this . config . Ts . StringValue ( mappingKey ) ;
118
+ ts . StringValue ( mappingKey ) ;
116
119
117
120
if ( ableToCreateMappingType ) {
118
- return this . config . Ts . TypeWithGeneric ( mappingTypeName , [
119
- mappingUsageKey ,
120
- content ,
121
- ] ) ;
121
+ return ts . TypeWithGeneric ( mappingTypeName , [ mappingUsageKey , content ] ) ;
122
122
} else {
123
- return this . config . Ts . ExpressionGroup (
124
- this . config . Ts . IntersectionType ( [
125
- this . config . Ts . ObjectWrapper (
126
- this . config . Ts . TypeField ( {
123
+ return ts . ExpressionGroup (
124
+ ts . IntersectionType ( [
125
+ ts . ObjectWrapper (
126
+ ts . TypeField ( {
127
127
key : discriminator . propertyName ,
128
128
value : mappingUsageKey ,
129
129
} ) ,
@@ -151,9 +151,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
151
151
152
152
if ( skipMappingType ) return null ;
153
153
154
- const content = this . config . Ts . ExpressionGroup (
155
- this . config . Ts . UnionType ( mappingContents ) ,
156
- ) ;
154
+ const content = ts . ExpressionGroup ( ts . UnionType ( mappingContents ) ) ;
157
155
158
156
return {
159
157
content,
@@ -164,6 +162,8 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
164
162
abstractSchemaStruct,
165
163
discPropertyName,
166
164
} ) => {
165
+ const ts = this . config . Ts ;
166
+
167
167
let mappingPropertySchemaEnumKeysMap = { } ;
168
168
let mappingPropertySchema = _ . get (
169
169
abstractSchemaStruct ?. component ?. rawTypeData ,
@@ -183,7 +183,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
183
183
( acc , key , index ) => {
184
184
const enumKey =
185
185
mappingPropertySchema . rawTypeData . $parsed . content [ index ] . key ;
186
- acc [ key ] = this . config . Ts . EnumUsageKey (
186
+ acc [ key ] = ts . EnumUsageKey (
187
187
mappingPropertySchema . rawTypeData . $parsed . typeName ,
188
188
enumKey ,
189
189
) ;
@@ -284,12 +284,13 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
284
284
} ;
285
285
286
286
createComplexSchemaStruct = ( ) => {
287
+ const ts = this . config . Ts ;
287
288
const complexType = this . schemaUtils . getComplexType ( this . schema ) ;
288
289
289
290
if ( complexType === SCHEMA_TYPES . COMPLEX_UNKNOWN ) return null ;
290
291
291
292
return {
292
- content : this . config . Ts . ExpressionGroup (
293
+ content : ts . ExpressionGroup (
293
294
this . schemaParser . _complexSchemaParsers [ complexType ] ( this . schema ) ,
294
295
) ,
295
296
} ;
0 commit comments