@@ -106,7 +106,7 @@ interface GenerateApiParamsBase {
106
106
/**
107
107
* default type for empty response schema (default: "void")
108
108
*/
109
- defaultResponseType ?: boolean ;
109
+ defaultResponseType ?: string ;
110
110
/**
111
111
* Ability to send HttpClient instance to Api constructor
112
112
*/
@@ -136,6 +136,22 @@ interface GenerateApiParamsBase {
136
136
primitiveTypeConstructs ?: ( struct : PrimitiveTypeStruct ) => Partial < PrimitiveTypeStruct > ;
137
137
138
138
codeGenConstructs ?: ( struct : CodeGenConstruct ) => Partial < CodeGenConstruct > ;
139
+
140
+ /** extract all enums from nested types\interfaces to `enum` construction */
141
+ extractEnums ?: boolean ;
142
+ /** prefix string value needed to fix invalid type names (default: 'Type') */
143
+ fixInvalidTypeNamePrefix ?: string ;
144
+ /** prefix string value needed to fix invalid enum keys (default: 'Value') */
145
+ fixInvalidEnumKeyPrefix ?: string ;
146
+ /** prefix string value for enum keys */
147
+ enumKeyPrefix ?: string ;
148
+ /** suffix string value for enum keys */
149
+ enumKeySuffix ?: string ;
150
+ /** prefix string value for type names */
151
+ typePrefix ?: string ;
152
+ /** suffix string value for type names */
153
+ typeSuffix ?: string ;
154
+ extractingOptions ?: Partial < ExtractingOptions > ;
139
155
}
140
156
141
157
type CodeGenConstruct = {
@@ -212,9 +228,39 @@ interface GenerateApiParamsFromSpecLiteral extends GenerateApiParamsBase {
212
228
213
229
export type GenerateApiParams = GenerateApiParamsFromPath | GenerateApiParamsFromUrl | GenerateApiParamsFromSpecLiteral ;
214
230
231
+ type BuildRouteParam = {
232
+ /** {bar} */
233
+ $match : string ;
234
+ name : string ;
235
+ required : boolean ;
236
+ type : "string" ;
237
+ description : string ;
238
+ schema : {
239
+ type : string ;
240
+ } ;
241
+ in : "path" | "query" ;
242
+ } ;
243
+
244
+ type BuildRoutePath = {
245
+ /** /foo/{bar}/baz */
246
+ originalRoute : string ;
247
+ /** /foo/${bar}/baz */
248
+ route : string ;
249
+ pathParams : BuildRouteParam [ ] ;
250
+ queryParams : BuildRouteParam [ ] ;
251
+ } ;
252
+
215
253
export interface Hooks {
254
+ /** calls before parse\process route path */
255
+ onPreBuildRoutePath : ( routePath : string ) => string | void ;
256
+ /** calls after parse\process route path */
257
+ onBuildRoutePath : ( data : BuildRoutePath ) => BuildRoutePath | void ;
258
+ /** calls before insert path param name into string path interpolation */
259
+ onInsertPathParam : ( paramName : string , index : number , arr : BuildRouteParam [ ] , resultRoute : string ) => string | void ;
216
260
/** calls after parse schema component */
217
261
onCreateComponent : ( component : SchemaComponent ) => SchemaComponent | void ;
262
+ /** calls before parse any kind of schema */
263
+ onPreParseSchema : ( originalSchema : any , typeName : string , schemaType : string ) => any ;
218
264
/** calls after parse any kind of schema */
219
265
onParseSchema : ( originalSchema : any , parsedSchema : any ) => any | void ;
220
266
/** calls after parse route (return type: customized route (ParsedRoute), nothing change (void), false (ignore this route)) */
@@ -228,7 +274,7 @@ export interface Hooks {
228
274
/** customize request params (path params, query params) */
229
275
onCreateRequestParams ?: ( rawType : SchemaComponent [ "rawTypeData" ] ) => SchemaComponent [ "rawTypeData" ] | void ;
230
276
/** customize name of model type */
231
- onFormatTypeName ?: ( typeName : string , rawTypeName ?: string ) => string | void ;
277
+ onFormatTypeName ?: ( typeName : string , rawTypeName ?: string , schemaType ?: "type-name" | "enum-key" ) => string | void ;
232
278
/** customize name of route (operationId), you can do it with using onCreateRouteName too */
233
279
onFormatRouteName ?: ( routeInfo : RawRouteInfo , templateRouteName : string ) => string | void ;
234
280
}
@@ -376,6 +422,17 @@ export enum SCHEMA_TYPES {
376
422
377
423
type MAIN_SCHEMA_TYPES = SCHEMA_TYPES . PRIMITIVE | SCHEMA_TYPES . OBJECT | SCHEMA_TYPES . ENUM ;
378
424
425
+ type ExtractingOptions = {
426
+ requestBodySuffix : string [ ] ;
427
+ responseBodySuffix : string [ ] ;
428
+ responseErrorSuffix : string [ ] ;
429
+ requestParamsSuffix : string [ ] ;
430
+ requestBodyNameResolver : ( name : string , reservedNames : string ) => string | undefined ;
431
+ responseBodyNameResolver : ( name : string , reservedNames : string ) => string | undefined ;
432
+ responseErrorNameResolver : ( name : string , reservedNames : string ) => string | undefined ;
433
+ requestParamsNameResolver : ( name : string , reservedNames : string ) => string | undefined ;
434
+ } ;
435
+
379
436
export interface GenerateApiConfiguration {
380
437
apiConfig : {
381
438
baseUrl : string ;
@@ -411,6 +468,8 @@ export interface GenerateApiConfiguration {
411
468
singleHttpClient : boolean ;
412
469
typePrefix : string ;
413
470
typeSuffix : string ;
471
+ enumKeyPrefix : string ;
472
+ enumKeySuffix : string ;
414
473
patch : boolean ;
415
474
cleanOutput : boolean ;
416
475
debug : boolean ;
@@ -420,7 +479,10 @@ export interface GenerateApiConfiguration {
420
479
addReadonly : boolean ;
421
480
extractResponseBody : boolean ;
422
481
extractResponseError : boolean ;
423
- defaultResponseType : boolean ;
482
+ extractEnums : boolean ;
483
+ fixInvalidTypeNamePrefix : string ;
484
+ fixInvalidEnumKeyPrefix : string ;
485
+ defaultResponseType : string ;
424
486
toJS : boolean ;
425
487
disableThrowOnError : boolean ;
426
488
silent : boolean ;
@@ -452,6 +514,7 @@ export interface GenerateApiConfiguration {
452
514
routeNameDuplicatesMap : Map < string , string > ;
453
515
apiClassName : string ;
454
516
requestOptions ?: import ( "node-fetch" ) . RequestInit ;
517
+ extractingOptions : ExtractingOptions ;
455
518
} ;
456
519
modelTypes : ModelType [ ] ;
457
520
rawModelTypes : SchemaComponent [ ] ;
0 commit comments