@@ -14,22 +14,26 @@ import { Logger } from "./utils/logger";
14
14
15
15
export interface GeneratorOptions {
16
16
emitDefinitionsOnly : boolean ;
17
- modelPropertyNaming : ModelPropertyNaming
17
+ modelPropertyNaming : ModelPropertyNaming ;
18
18
}
19
19
20
20
const defaultOptions : GeneratorOptions = {
21
21
emitDefinitionsOnly : false ,
22
- modelPropertyNaming : null
22
+ modelPropertyNaming : null ,
23
23
} ;
24
24
25
25
/**
26
26
* To avoid duplicated imports
27
27
*/
28
- function addSafeImport ( imports : OptionalKind < ImportDeclarationStructure > [ ] , moduleSpecifier : string , namedImport : string ) {
29
- if ( ! imports . find ( imp => imp . moduleSpecifier == moduleSpecifier ) ) {
28
+ function addSafeImport (
29
+ imports : OptionalKind < ImportDeclarationStructure > [ ] ,
30
+ moduleSpecifier : string ,
31
+ namedImport : string
32
+ ) {
33
+ if ( ! imports . find ( ( imp ) => imp . moduleSpecifier == moduleSpecifier ) ) {
30
34
imports . push ( {
31
- moduleSpecifier,
32
- namedImports : [ { name : namedImport } ]
35
+ moduleSpecifier,
36
+ namedImports : [ { name : namedImport } ] ,
33
37
} ) ;
34
38
}
35
39
}
@@ -39,7 +43,7 @@ const incorrectPropNameChars = [" ", "-", "."];
39
43
* This is temporally method to fix this issue https://github.com/dsherret/ts-morph/issues/1160
40
44
*/
41
45
function sanitizePropName ( propName : string ) {
42
- if ( incorrectPropNameChars . some ( char => propName . includes ( char ) ) ) {
46
+ if ( incorrectPropNameChars . some ( ( char ) => propName . includes ( char ) ) ) {
43
47
return `"${ propName } "` ;
44
48
}
45
49
return propName ;
@@ -80,7 +84,7 @@ function generateDefinitionFile(
80
84
const definitionImports : OptionalKind < ImportDeclarationStructure > [ ] = [ ] ;
81
85
const definitionProperties : PropertySignatureStructure [ ] = [ ] ;
82
86
for ( const prop of definition . properties ) {
83
- if ( options . modelPropertyNaming ) {
87
+ if ( options . modelPropertyNaming ) {
84
88
switch ( options . modelPropertyNaming ) {
85
89
case ModelPropertyNaming . camelCase :
86
90
prop . name = camelcase ( prop . name ) ;
@@ -100,7 +104,7 @@ function generateDefinitionFile(
100
104
generateDefinitionFile ( project , prop . ref , defDir , [ ...stack , prop . ref . name ] , generated , options ) ;
101
105
}
102
106
// If a property is of the same type as its parent type, don't add import
103
- if ( prop . ref . name !== definition . name ) {
107
+ if ( prop . ref . name !== definition . name ) {
104
108
addSafeImport ( definitionImports , `./${ prop . ref . name } ` , prop . ref . name ) ;
105
109
}
106
110
definitionProperties . push ( createProperty ( prop . name , prop . ref . name , prop . sourceName , prop . isArray ) ) ;
@@ -122,10 +126,14 @@ function generateDefinitionFile(
122
126
defFile . saveSync ( ) ;
123
127
}
124
128
125
- export async function generate ( parsedWsdl : ParsedWsdl , outDir : string , options : Partial < GeneratorOptions > ) : Promise < void > {
129
+ export async function generate (
130
+ parsedWsdl : ParsedWsdl ,
131
+ outDir : string ,
132
+ options : Partial < GeneratorOptions >
133
+ ) : Promise < void > {
126
134
const mergedOptions : GeneratorOptions = {
127
135
...defaultOptions ,
128
- ...options
136
+ ...options ,
129
137
} ;
130
138
const project = new Project ( ) ;
131
139
@@ -167,9 +175,17 @@ export async function generate(parsedWsdl: ParsedWsdl, outDir: string, options:
167
175
allDefinitions ,
168
176
mergedOptions
169
177
) ;
170
- addSafeImport ( clientImports , `./definitions/${ method . paramDefinition . name } ` , method . paramDefinition . name ) ;
178
+ addSafeImport (
179
+ clientImports ,
180
+ `./definitions/${ method . paramDefinition . name } ` ,
181
+ method . paramDefinition . name
182
+ ) ;
171
183
}
172
- addSafeImport ( portImports , `../definitions/${ method . paramDefinition . name } ` , method . paramDefinition . name ) ;
184
+ addSafeImport (
185
+ portImports ,
186
+ `../definitions/${ method . paramDefinition . name } ` ,
187
+ method . paramDefinition . name
188
+ ) ;
173
189
}
174
190
if ( method . returnDefinition !== null ) {
175
191
if ( ! allDefinitions . includes ( method . returnDefinition ) ) {
@@ -182,9 +198,17 @@ export async function generate(parsedWsdl: ParsedWsdl, outDir: string, options:
182
198
allDefinitions ,
183
199
mergedOptions
184
200
) ;
185
- addSafeImport ( clientImports , `./definitions/${ method . returnDefinition . name } ` , method . returnDefinition . name ) ;
201
+ addSafeImport (
202
+ clientImports ,
203
+ `./definitions/${ method . returnDefinition . name } ` ,
204
+ method . returnDefinition . name
205
+ ) ;
186
206
}
187
- addSafeImport ( portImports , `../definitions/${ method . returnDefinition . name } ` , method . returnDefinition . name ) ;
207
+ addSafeImport (
208
+ portImports ,
209
+ `../definitions/${ method . returnDefinition . name } ` ,
210
+ method . returnDefinition . name
211
+ ) ;
188
212
}
189
213
// TODO: Deduplicate PortMethods
190
214
allMethods . push ( method ) ;
@@ -269,14 +293,16 @@ export async function generate(parsedWsdl: ParsedWsdl, outDir: string, options:
269
293
properties : clientServices ,
270
294
extends : [ "SoapClient" ] ,
271
295
methods : allMethods . map < OptionalKind < MethodSignatureStructure > > ( ( method ) => ( {
272
- name : sanitizePropName ( `${ ( method . name ) } Async` ) ,
296
+ name : sanitizePropName ( `${ method . name } Async` ) ,
273
297
parameters : [
274
298
{
275
299
name : camelcase ( method . paramName ) ,
276
300
type : method . paramDefinition ? method . paramDefinition . name : "{}" ,
277
301
} ,
278
302
] ,
279
- returnType : `Promise<[result: ${ method . returnDefinition ? method . returnDefinition . name : "unknown" } , rawResponse: any, soapHeader: any, rawRequest: any]>` ,
303
+ returnType : `Promise<[result: ${
304
+ method . returnDefinition ? method . returnDefinition . name : "unknown"
305
+ } , rawResponse: any, soapHeader: any, rawRequest: any]>`,
280
306
} ) ) ,
281
307
} ,
282
308
] ) ;
0 commit comments