@@ -106,7 +106,7 @@ interface GenerateApiParamsBase {
106106 /**
107107 * default type for empty response schema (default: "void")
108108 */
109- defaultResponseType ?: boolean ;
109+ defaultResponseType ?: string ;
110110 /**
111111 * Ability to send HttpClient instance to Api constructor
112112 */
@@ -136,6 +136,22 @@ interface GenerateApiParamsBase {
136136 primitiveTypeConstructs ?: ( struct : PrimitiveTypeStruct ) => Partial < PrimitiveTypeStruct > ;
137137
138138 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 > ;
139155}
140156
141157type CodeGenConstruct = {
@@ -212,9 +228,39 @@ interface GenerateApiParamsFromSpecLiteral extends GenerateApiParamsBase {
212228
213229export type GenerateApiParams = GenerateApiParamsFromPath | GenerateApiParamsFromUrl | GenerateApiParamsFromSpecLiteral ;
214230
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+
215253export 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 ;
216260 /** calls after parse schema component */
217261 onCreateComponent : ( component : SchemaComponent ) => SchemaComponent | void ;
262+ /** calls before parse any kind of schema */
263+ onPreParseSchema : ( originalSchema : any , typeName : string , schemaType : string ) => any ;
218264 /** calls after parse any kind of schema */
219265 onParseSchema : ( originalSchema : any , parsedSchema : any ) => any | void ;
220266 /** calls after parse route (return type: customized route (ParsedRoute), nothing change (void), false (ignore this route)) */
@@ -228,7 +274,7 @@ export interface Hooks {
228274 /** customize request params (path params, query params) */
229275 onCreateRequestParams ?: ( rawType : SchemaComponent [ "rawTypeData" ] ) => SchemaComponent [ "rawTypeData" ] | void ;
230276 /** 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 ;
232278 /** customize name of route (operationId), you can do it with using onCreateRouteName too */
233279 onFormatRouteName ?: ( routeInfo : RawRouteInfo , templateRouteName : string ) => string | void ;
234280}
@@ -376,6 +422,17 @@ export enum SCHEMA_TYPES {
376422
377423type MAIN_SCHEMA_TYPES = SCHEMA_TYPES . PRIMITIVE | SCHEMA_TYPES . OBJECT | SCHEMA_TYPES . ENUM ;
378424
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+
379436export interface GenerateApiConfiguration {
380437 apiConfig : {
381438 baseUrl : string ;
@@ -411,6 +468,8 @@ export interface GenerateApiConfiguration {
411468 singleHttpClient : boolean ;
412469 typePrefix : string ;
413470 typeSuffix : string ;
471+ enumKeyPrefix : string ;
472+ enumKeySuffix : string ;
414473 patch : boolean ;
415474 cleanOutput : boolean ;
416475 debug : boolean ;
@@ -420,7 +479,10 @@ export interface GenerateApiConfiguration {
420479 addReadonly : boolean ;
421480 extractResponseBody : boolean ;
422481 extractResponseError : boolean ;
423- defaultResponseType : boolean ;
482+ extractEnums : boolean ;
483+ fixInvalidTypeNamePrefix : string ;
484+ fixInvalidEnumKeyPrefix : string ;
485+ defaultResponseType : string ;
424486 toJS : boolean ;
425487 disableThrowOnError : boolean ;
426488 silent : boolean ;
@@ -452,6 +514,7 @@ export interface GenerateApiConfiguration {
452514 routeNameDuplicatesMap : Map < string , string > ;
453515 apiClassName : string ;
454516 requestOptions ?: import ( "node-fetch" ) . RequestInit ;
517+ extractingOptions : ExtractingOptions ;
455518 } ;
456519 modelTypes : ModelType [ ] ;
457520 rawModelTypes : SchemaComponent [ ] ;
0 commit comments