@@ -34,6 +34,7 @@ import {generateOperationMethods} from './operation-methods';
34
34
import { GeneratedServicesImportInfo } from './services' ;
35
35
import { OpenApiInfo , OpenApiServer } from '../../schemas/common' ;
36
36
import { OpenApiPaths } from '../../schemas/openapi' ;
37
+ import { makeProtected } from '../../utils/ast' ;
37
38
import {
38
39
addDependencyImport ,
39
40
DependencyImports ,
@@ -67,8 +68,10 @@ export function generateClient({
67
68
exportModels,
68
69
exportServices,
69
70
exportErrorClass,
71
+ exportOptionsType,
70
72
errorClassName,
71
73
generateJsDoc,
74
+ generateErrorJsDoc,
72
75
...filenameConfig
73
76
} ,
74
77
generatedServiceImports,
@@ -107,41 +110,47 @@ export function generateClient({
107
110
const clientPropertyName = 'client' ;
108
111
const commonHttpClientImportName = 'commonHttpClient' ;
109
112
const { importPath : clientImportPath , filename} = getFilenameAndImportPath ( name , filenameConfig ) ;
110
- const clientProperty = classProperty ( identifier ( clientPropertyName ) ) ;
111
- clientProperty . typeAnnotation = tsTypeAnnotation (
112
- tsTypeReference ( tsQualifiedName ( identifier ( commonHttpClientImportName ) , identifier ( commonHttpClientClassName ) ) )
113
- ) ;
114
-
115
113
const errorTypeName = errorClassName ?? `${ name } Error` ;
116
114
const additionalTypeStatements : Statement [ ] = [ ] ;
117
115
const errorClassDeclaration = classDeclaration (
118
116
identifier ( errorTypeName ) ,
119
117
memberExpression ( identifier ( commonHttpClientImportName ) , identifier ( commonHttpClientErrorClassName ) ) ,
120
118
classBody ( [ classProperty ( identifier ( 'name' ) , stringLiteral ( errorTypeName ) ) ] )
121
119
) ;
122
- if ( exportErrorClass !== false ) {
123
- additionalTypeStatements . push ( exportNamedDeclaration ( errorClassDeclaration ) ) ;
124
- } else {
125
- additionalTypeStatements . push ( errorClassDeclaration ) ;
126
- }
120
+ const errorClassSuggestedJsDoc : JsDocBlock = { title : `Error class for ${ info . summary } ` , tags : [ ] } ;
121
+ additionalTypeStatements . push (
122
+ attachJsDocComment (
123
+ exportErrorClass !== false ? exportNamedDeclaration ( errorClassDeclaration ) : errorClassDeclaration ,
124
+ renderJsDoc (
125
+ generateErrorJsDoc
126
+ ? generateErrorJsDoc ( { suggestedJsDoc : errorClassSuggestedJsDoc , info} )
127
+ : errorClassSuggestedJsDoc ,
128
+ jsDocRenderConfig
129
+ )
130
+ )
131
+ ) ;
127
132
128
133
const clientClassBody = classBody ( [
129
- classProperty (
130
- identifier ( clientPropertyName ) ,
131
- newExpression (
132
- memberExpression ( identifier ( commonHttpClientImportName ) , identifier ( commonHttpClientClassName ) ) ,
133
- [
134
- objectExpression ( [
135
- objectProperty ( identifier ( 'baseUrl' ) , stringLiteral ( servers [ 0 ] ?. url ?? defaultServerUrl ) ) ,
136
- objectProperty ( identifier ( 'binaryResponseType' ) , stringLiteral ( responseBinaryType ) ) ,
137
- objectProperty ( identifier ( 'errorClass' ) , identifier ( errorTypeName ) )
138
- ] )
139
- ]
134
+ makeProtected (
135
+ classProperty (
136
+ identifier ( clientPropertyName ) ,
137
+ newExpression (
138
+ memberExpression ( identifier ( commonHttpClientImportName ) , identifier ( commonHttpClientClassName ) ) ,
139
+ [
140
+ objectExpression ( [
141
+ objectProperty ( identifier ( 'baseUrl' ) , stringLiteral ( servers [ 0 ] ?. url ?? defaultServerUrl ) ) ,
142
+ objectProperty ( identifier ( 'binaryResponseType' ) , stringLiteral ( responseBinaryType ) ) ,
143
+ objectProperty ( identifier ( 'errorClass' ) , identifier ( errorTypeName ) )
144
+ ] )
145
+ ]
146
+ )
140
147
)
141
148
) ,
142
- classProperty (
143
- identifier ( 'getClient' ) ,
144
- arrowFunctionExpression ( [ ] , memberExpression ( thisExpression ( ) , identifier ( clientPropertyName ) ) )
149
+ makeProtected (
150
+ classProperty (
151
+ identifier ( 'getClient' ) ,
152
+ arrowFunctionExpression ( [ ] , memberExpression ( thisExpression ( ) , identifier ( clientPropertyName ) ) )
153
+ )
145
154
)
146
155
] ) ;
147
156
const dependencyImports : DependencyImports = { } ;
@@ -186,23 +195,23 @@ export function generateClient({
186
195
}
187
196
188
197
const optionsTypeName = `${ name } Options` ;
189
- const optionsTypeExport = exportNamedDeclaration (
190
- tsTypeAliasDeclaration (
191
- identifier ( optionsTypeName ) ,
192
- null ,
193
- tsTypeReference (
194
- identifier ( 'Partial' ) ,
195
- tsTypeParameterInstantiation ( [
196
- tsTypeReference (
197
- tsQualifiedName (
198
- identifier ( commonHttpClientImportName ) ,
199
- identifier ( commonHttpClientClassOptionsName )
200
- )
198
+ const optionsTypeDeclaration = tsTypeAliasDeclaration (
199
+ identifier ( optionsTypeName ) ,
200
+ null ,
201
+ tsTypeReference (
202
+ identifier ( 'Partial' ) ,
203
+ tsTypeParameterInstantiation ( [
204
+ tsTypeReference (
205
+ tsQualifiedName (
206
+ identifier ( commonHttpClientImportName ) ,
207
+ identifier ( commonHttpClientClassOptionsName )
201
208
)
202
- ] )
203
- )
209
+ )
210
+ ] )
204
211
)
205
212
) ;
213
+ const optionsTypeStatement =
214
+ exportOptionsType === false ? optionsTypeDeclaration : exportNamedDeclaration ( optionsTypeDeclaration ) ;
206
215
207
216
const generatedMethods = generateOperationMethods ( {
208
217
paths,
@@ -260,13 +269,15 @@ export function generateClient({
260
269
261
270
if ( generatedMethods . validationStatements . length > 0 ) {
262
271
clientClassBody . body . push (
263
- classMethod (
264
- 'method' ,
265
- identifier ( 'initialize' ) ,
266
- [ ] ,
267
- blockStatement ( generatedMethods . validationStatements ) ,
268
- false ,
269
- true
272
+ makeProtected (
273
+ classMethod (
274
+ 'method' ,
275
+ identifier ( 'initialize' ) ,
276
+ [ ] ,
277
+ blockStatement ( generatedMethods . validationStatements ) ,
278
+ false ,
279
+ true
280
+ )
270
281
)
271
282
) ;
272
283
}
@@ -350,7 +361,7 @@ export function generateClient({
350
361
stringLiteral ( getRelativeImportPath ( clientImportPath , commonHttpClientImportPath ) )
351
362
) ,
352
363
...generateTsImports ( dependencyImports ) ,
353
- optionsTypeExport ,
364
+ optionsTypeStatement ,
354
365
...additionalTypeStatements ,
355
366
clientClass ,
356
367
...otherStatements ,
0 commit comments