swagger-typescript-api 13.2.7 → 13.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +2 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/lib.cjs +1 -1
- package/dist/lib.d.cts +205 -16
- package/dist/lib.d.ts +205 -16
- package/dist/lib.js +1 -1
- package/dist/{src-DYNtMxii.cjs → src-B-cU8h_Y.cjs} +41 -29
- package/dist/src-B-cU8h_Y.cjs.map +1 -0
- package/dist/{src-BgBqKQNC.js → src-BGOGeWR6.js} +105 -100
- package/dist/src-BGOGeWR6.js.map +1 -0
- package/package.json +13 -13
- package/templates/base/http-clients/fetch-http-client.ejs +9 -4
- package/templates/base/route-type.ejs +2 -1
- package/templates/default/procedure-call.ejs +3 -1
- package/templates/modular/procedure-call.ejs +4 -2
- package/dist/src-BgBqKQNC.js.map +0 -1
- package/dist/src-DYNtMxii.cjs.map +0 -1
package/dist/lib.d.cts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { OpenAPI } from "openapi-types";
|
|
2
|
-
import * as typescript$1 from "typescript";
|
|
3
2
|
import * as typescript from "typescript";
|
|
4
|
-
import * as
|
|
5
|
-
import * as lodash14 from "lodash";
|
|
3
|
+
import * as lodash0 from "lodash";
|
|
6
4
|
import lodash from "lodash";
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
5
|
+
import * as swagger_schema_official0 from "swagger-schema-official";
|
|
6
|
+
import * as eta0 from "eta";
|
|
9
7
|
|
|
10
8
|
//#region rolldown:runtime
|
|
11
9
|
//#endregion
|
|
@@ -381,7 +379,7 @@ declare class JavascriptTranslator extends Translator {
|
|
|
381
379
|
compileTSCode: (input: TranslatorIO) => Record<string, string>;
|
|
382
380
|
translate: (input: any) => Promise<{
|
|
383
381
|
fileName: any;
|
|
384
|
-
fileExtension: typescript
|
|
382
|
+
fileExtension: typescript.Extension;
|
|
385
383
|
fileContent: string;
|
|
386
384
|
}[]>;
|
|
387
385
|
}
|
|
@@ -530,7 +528,7 @@ declare class CodeGenProcess {
|
|
|
530
528
|
}) => string;
|
|
531
529
|
NameResolver: typeof NameResolver;
|
|
532
530
|
_: lodash.LoDashStatic;
|
|
533
|
-
require: (packageOrPath: string) =>
|
|
531
|
+
require: (packageOrPath: string) => any;
|
|
534
532
|
};
|
|
535
533
|
};
|
|
536
534
|
getTemplate: (name: string, fileName: string, path?: string) => string | undefined;
|
|
@@ -635,7 +633,7 @@ declare class CodeGenProcess {
|
|
|
635
633
|
}) => string;
|
|
636
634
|
NameResolver: typeof NameResolver;
|
|
637
635
|
_: lodash.LoDashStatic;
|
|
638
|
-
require: (packageOrPath: string) =>
|
|
636
|
+
require: (packageOrPath: string) => any;
|
|
639
637
|
};
|
|
640
638
|
config: CodeGenConfig;
|
|
641
639
|
};
|
|
@@ -672,7 +670,7 @@ declare class TemplatesWorker {
|
|
|
672
670
|
getTemplatePaths: (config: CodeGenConfig) => CodeGenConfig["templatePaths"];
|
|
673
671
|
cropExtension: (path: string) => string;
|
|
674
672
|
getTemplateFullPath: (path_: string, fileName: string) => string | undefined;
|
|
675
|
-
requireFnFromTemplate: (packageOrPath: string) =>
|
|
673
|
+
requireFnFromTemplate: (packageOrPath: string) => any;
|
|
676
674
|
getTemplate: (name: string, fileName: string, path?: string) => string | undefined;
|
|
677
675
|
getTemplates: ({
|
|
678
676
|
templatePaths
|
|
@@ -776,6 +774,54 @@ declare class MonoSchemaParser {
|
|
|
776
774
|
//#endregion
|
|
777
775
|
//#region types/index.d.ts
|
|
778
776
|
type HttpClientType = (typeof HTTP_CLIENT)[keyof typeof HTTP_CLIENT];
|
|
777
|
+
type CodeGenConstruct = {
|
|
778
|
+
Keyword: {
|
|
779
|
+
Number: string;
|
|
780
|
+
String: string;
|
|
781
|
+
Boolean: string;
|
|
782
|
+
Any: string;
|
|
783
|
+
Void: string;
|
|
784
|
+
Unknown: string;
|
|
785
|
+
Null: string;
|
|
786
|
+
Undefined: string;
|
|
787
|
+
Object: string;
|
|
788
|
+
File: string;
|
|
789
|
+
Date: string;
|
|
790
|
+
Type: string;
|
|
791
|
+
Enum: string;
|
|
792
|
+
Interface: string;
|
|
793
|
+
Array: string;
|
|
794
|
+
Record: string;
|
|
795
|
+
Intersection: string;
|
|
796
|
+
Union: string;
|
|
797
|
+
};
|
|
798
|
+
CodeGenKeyword: {
|
|
799
|
+
UtilRequiredKeys: string;
|
|
800
|
+
};
|
|
801
|
+
ArrayType: (content: unknown) => string;
|
|
802
|
+
StringValue: (content: unknown) => string;
|
|
803
|
+
BooleanValue: (content: unknown) => string;
|
|
804
|
+
NumberValue: (content: unknown) => string;
|
|
805
|
+
NullValue: (content: unknown) => string;
|
|
806
|
+
UnionType: (content: unknown) => string;
|
|
807
|
+
ExpressionGroup: (content: unknown) => string;
|
|
808
|
+
IntersectionType: (content: unknown) => string;
|
|
809
|
+
RecordType: (content: unknown) => string;
|
|
810
|
+
TypeField: (content: unknown) => string;
|
|
811
|
+
InterfaceDynamicField: (content: unknown) => string;
|
|
812
|
+
EnumUsageKey: (enumStruct: unknown, key: unknown) => string;
|
|
813
|
+
EnumField: (content: unknown) => string;
|
|
814
|
+
EnumFieldDescription: (content: unknown) => string;
|
|
815
|
+
EnumFieldsWrapper: (content: unknown) => string;
|
|
816
|
+
ObjectWrapper: (content: unknown) => string;
|
|
817
|
+
MultilineComment: (content: unknown) => string;
|
|
818
|
+
TypeWithGeneric: (content: unknown) => string;
|
|
819
|
+
Tuple: (content: unknown) => string;
|
|
820
|
+
};
|
|
821
|
+
type PrimitiveTypeStructValue = string | ((schema: Record<string, unknown>, parser: SchemaParser) => string);
|
|
822
|
+
type PrimitiveTypeStruct = Record<"integer" | "number" | "boolean" | "object" | "file" | "string" | "array", string | ({
|
|
823
|
+
$default: PrimitiveTypeStructValue;
|
|
824
|
+
} & Record<string, PrimitiveTypeStructValue>)>;
|
|
779
825
|
type BuildRouteParam = {
|
|
780
826
|
/** {bar} */
|
|
781
827
|
$match: string;
|
|
@@ -911,7 +957,7 @@ type RawRouteInfo = {
|
|
|
911
957
|
description?: string;
|
|
912
958
|
tags?: string[];
|
|
913
959
|
summary?: string;
|
|
914
|
-
responses?:
|
|
960
|
+
responses?: swagger_schema_official0.Spec["responses"];
|
|
915
961
|
produces?: string[];
|
|
916
962
|
requestBody?: object;
|
|
917
963
|
consumes?: string[];
|
|
@@ -1014,18 +1060,45 @@ type ExtractingOptions = {
|
|
|
1014
1060
|
};
|
|
1015
1061
|
interface GenerateApiConfiguration {
|
|
1016
1062
|
apiConfig: {
|
|
1063
|
+
/** base url from schema */
|
|
1017
1064
|
baseUrl: string;
|
|
1065
|
+
/** document title */
|
|
1018
1066
|
title: string;
|
|
1067
|
+
/** document version */
|
|
1019
1068
|
version: string;
|
|
1069
|
+
/** description split into lines */
|
|
1020
1070
|
description: string[];
|
|
1071
|
+
/** flag that description is present */
|
|
1021
1072
|
hasDescription: boolean;
|
|
1022
1073
|
};
|
|
1023
1074
|
config: {
|
|
1075
|
+
/** path to swagger schema */
|
|
1024
1076
|
input: string;
|
|
1077
|
+
/**
|
|
1078
|
+
* generate separated files for http client, data contracts, and routes
|
|
1079
|
+
* @default false
|
|
1080
|
+
*/
|
|
1081
|
+
modular: boolean;
|
|
1082
|
+
/**
|
|
1083
|
+
* path to folder where the created api module will be placed.
|
|
1084
|
+
* may be set to `false` to skip writing content to disk; in this case
|
|
1085
|
+
* the `files` array on the return value will contain the generated contents.
|
|
1086
|
+
*/
|
|
1025
1087
|
output: string | false;
|
|
1088
|
+
/** url to swagger schema */
|
|
1026
1089
|
url: string;
|
|
1090
|
+
/** swagger schema JSON */
|
|
1027
1091
|
spec: unknown;
|
|
1092
|
+
/**
|
|
1093
|
+
* file name for the generated API module
|
|
1094
|
+
* @default 'Api.ts'
|
|
1095
|
+
*/
|
|
1028
1096
|
fileName: string;
|
|
1097
|
+
/**
|
|
1098
|
+
* path to folder containing custom templates
|
|
1099
|
+
* @default ""
|
|
1100
|
+
*/
|
|
1101
|
+
templates: string;
|
|
1029
1102
|
templatePaths: {
|
|
1030
1103
|
/** `templates/base` */
|
|
1031
1104
|
base: string;
|
|
@@ -1038,66 +1111,176 @@ interface GenerateApiConfiguration {
|
|
|
1038
1111
|
/** custom path to templates (`--templates`) */
|
|
1039
1112
|
custom: string | null;
|
|
1040
1113
|
};
|
|
1114
|
+
/** authorisation token for private swagger schema access */
|
|
1041
1115
|
authorizationToken?: string;
|
|
1116
|
+
/** generate additional information about request responses and error typings */
|
|
1042
1117
|
generateResponses: boolean;
|
|
1118
|
+
/**
|
|
1119
|
+
* use "default" response status code as success response.
|
|
1120
|
+
* some swagger schemas treat "default" as a successful response.
|
|
1121
|
+
*/
|
|
1043
1122
|
defaultResponseAsSuccess: boolean;
|
|
1123
|
+
/** generate type definitions for API routes */
|
|
1044
1124
|
generateRouteTypes: boolean;
|
|
1125
|
+
/** generate an API client */
|
|
1045
1126
|
generateClient: boolean;
|
|
1127
|
+
/** generate all "enum" types as union types (T1 | T2 | TN) */
|
|
1046
1128
|
generateUnionEnums: boolean;
|
|
1129
|
+
/** parsed swagger schema */
|
|
1047
1130
|
swaggerSchema: object;
|
|
1131
|
+
/** original swagger schema */
|
|
1048
1132
|
originalSchema: object;
|
|
1133
|
+
/** map of schema component references */
|
|
1049
1134
|
componentsMap: Record<string, SchemaComponent>;
|
|
1135
|
+
/** flag indicating the schema was converted from Swagger 2.0 */
|
|
1050
1136
|
convertedFromSwagger2: boolean;
|
|
1137
|
+
/** determines which path index should be used for routes separation */
|
|
1051
1138
|
moduleNameIndex: number;
|
|
1139
|
+
/** use the first tag for the module name */
|
|
1052
1140
|
moduleNameFirstTag: boolean;
|
|
1141
|
+
/** extra templates */
|
|
1053
1142
|
extraTemplates: {
|
|
1054
1143
|
name: string;
|
|
1055
1144
|
path: string;
|
|
1056
1145
|
}[];
|
|
1146
|
+
/** extract request params to data contract */
|
|
1057
1147
|
extractRequestParams: boolean;
|
|
1148
|
+
/** unwrap the data item from the response */
|
|
1058
1149
|
unwrapResponseData: boolean;
|
|
1150
|
+
/** sort data contracts in alphabetical order */
|
|
1059
1151
|
sortTypes: boolean;
|
|
1152
|
+
/** sort routes in alphabetical order */
|
|
1060
1153
|
sortRoutes: boolean;
|
|
1154
|
+
/** ability to send HttpClient instance to Api constructor */
|
|
1061
1155
|
singleHttpClient: boolean;
|
|
1156
|
+
/** prefix string value for type names */
|
|
1062
1157
|
typePrefix: string;
|
|
1158
|
+
/** suffix string value for type names */
|
|
1063
1159
|
typeSuffix: string;
|
|
1160
|
+
/** prefix string value for enum keys */
|
|
1064
1161
|
enumKeyPrefix: string;
|
|
1162
|
+
/** suffix string value for enum keys */
|
|
1065
1163
|
enumKeySuffix: string;
|
|
1164
|
+
/** fix up small errors in the swagger source definition */
|
|
1066
1165
|
patch: boolean;
|
|
1166
|
+
/** remove output directory before generating */
|
|
1067
1167
|
cleanOutput: boolean;
|
|
1168
|
+
/** output debug messages */
|
|
1068
1169
|
debug: boolean;
|
|
1170
|
+
/**
|
|
1171
|
+
* generate array types as Array<Type>
|
|
1172
|
+
* @default false
|
|
1173
|
+
*/
|
|
1069
1174
|
anotherArrayType: boolean;
|
|
1175
|
+
/** extract request body type to data contract */
|
|
1070
1176
|
extractRequestBody: boolean;
|
|
1177
|
+
/** generated http client type */
|
|
1071
1178
|
httpClientType: "axios" | "fetch";
|
|
1179
|
+
/** generate readonly properties */
|
|
1072
1180
|
addReadonly: boolean;
|
|
1181
|
+
/** customise primitive type mappings */
|
|
1182
|
+
primitiveTypeConstructs?: (struct: PrimitiveTypeStruct) => Partial<PrimitiveTypeStruct>;
|
|
1183
|
+
/** customise code generation constructs */
|
|
1184
|
+
codeGenConstructs?: (struct: CodeGenConstruct) => Partial<CodeGenConstruct>;
|
|
1185
|
+
/** extract response body type to data contract */
|
|
1073
1186
|
extractResponseBody: boolean;
|
|
1187
|
+
/** extract response error type to data contract */
|
|
1074
1188
|
extractResponseError: boolean;
|
|
1189
|
+
/** extract all enums from nested types/interfaces to `enum` construction */
|
|
1075
1190
|
extractEnums: boolean;
|
|
1191
|
+
/** extract all enums from inline interface/type content to typescript enum construction */
|
|
1076
1192
|
extractResponses: boolean;
|
|
1193
|
+
/**
|
|
1194
|
+
* prefix string value needed to fix invalid type names
|
|
1195
|
+
* @default "Type"
|
|
1196
|
+
*/
|
|
1077
1197
|
fixInvalidTypeNamePrefix: string;
|
|
1198
|
+
/**
|
|
1199
|
+
* prefix string value needed to fix invalid enum keys
|
|
1200
|
+
* @default "Value"
|
|
1201
|
+
*/
|
|
1078
1202
|
fixInvalidEnumKeyPrefix: string;
|
|
1203
|
+
/**
|
|
1204
|
+
* default type for empty response schema
|
|
1205
|
+
* @default "void"
|
|
1206
|
+
*/
|
|
1079
1207
|
defaultResponseType: string;
|
|
1208
|
+
/**
|
|
1209
|
+
* generate js api module with declaration file
|
|
1210
|
+
* @default false
|
|
1211
|
+
*/
|
|
1080
1212
|
toJS: boolean;
|
|
1213
|
+
/** disable throwing on a non-successful response */
|
|
1081
1214
|
disableThrowOnError: boolean;
|
|
1215
|
+
/**
|
|
1216
|
+
* output only errors to console
|
|
1217
|
+
* @default false
|
|
1218
|
+
*/
|
|
1082
1219
|
silent: boolean;
|
|
1220
|
+
/** hooks for customising the generation process */
|
|
1083
1221
|
hooks: Partial<Hooks>;
|
|
1222
|
+
/** use enum names as values */
|
|
1084
1223
|
enumNamesAsValues: boolean;
|
|
1224
|
+
/** package version */
|
|
1085
1225
|
version: string;
|
|
1226
|
+
/** ts compiler configuration object (for --to-js option) */
|
|
1086
1227
|
compilerTsConfig: Record<string, unknown>;
|
|
1228
|
+
/** enum key resolver name */
|
|
1087
1229
|
enumKeyResolverName: string;
|
|
1230
|
+
/** type name resolver name */
|
|
1088
1231
|
typeNameResolverName: string;
|
|
1232
|
+
/** specific argument name resolver name */
|
|
1089
1233
|
specificArgNameResolverName: string;
|
|
1234
|
+
/**
|
|
1235
|
+
* custom ts->* translator
|
|
1236
|
+
* do not use constructor args, just send class reference
|
|
1237
|
+
*/
|
|
1090
1238
|
customTranslator?: new () => Translator;
|
|
1239
|
+
/** internal constants */
|
|
1240
|
+
constants: typeof constants_d_exports;
|
|
1241
|
+
/** code generation constructs for TypeScript */
|
|
1242
|
+
Ts: CodeGenConstruct;
|
|
1243
|
+
/**
|
|
1244
|
+
* swagger schema type -> typescript type
|
|
1245
|
+
* https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-times
|
|
1246
|
+
*/
|
|
1247
|
+
primitiveTypes: PrimitiveTypeStruct;
|
|
1248
|
+
/** built-in template info */
|
|
1249
|
+
templateInfos: {
|
|
1250
|
+
name: string;
|
|
1251
|
+
fileName: string;
|
|
1252
|
+
}[];
|
|
1253
|
+
/** supported template file extensions */
|
|
1254
|
+
templateExtensions: string[];
|
|
1255
|
+
/** range of HTTP status codes treated as success */
|
|
1256
|
+
successResponseStatusRange: [number, number];
|
|
1257
|
+
/** custom schema parsers */
|
|
1258
|
+
schemaParsers?: {
|
|
1259
|
+
complexOneOf?: MonoSchemaParser;
|
|
1260
|
+
complexAllOf?: MonoSchemaParser;
|
|
1261
|
+
complexAnyOf?: MonoSchemaParser;
|
|
1262
|
+
complexNot?: MonoSchemaParser;
|
|
1263
|
+
enum?: MonoSchemaParser;
|
|
1264
|
+
object?: MonoSchemaParser;
|
|
1265
|
+
complex?: MonoSchemaParser;
|
|
1266
|
+
primitive?: MonoSchemaParser;
|
|
1267
|
+
discriminator?: MonoSchemaParser;
|
|
1268
|
+
array?: MonoSchemaParser;
|
|
1269
|
+
};
|
|
1270
|
+
/** internal options for templates */
|
|
1091
1271
|
internalTemplateOptions: {
|
|
1092
1272
|
addUtilRequiredKeysType: boolean;
|
|
1093
1273
|
};
|
|
1274
|
+
/** resolver for component type names */
|
|
1094
1275
|
componentTypeNameResolver: ComponentTypeNameResolver;
|
|
1276
|
+
/** generated file names */
|
|
1095
1277
|
fileNames: {
|
|
1096
1278
|
dataContracts: string;
|
|
1097
1279
|
routeTypes: string;
|
|
1098
1280
|
httpClient: string;
|
|
1099
1281
|
outOfModuleApi: string;
|
|
1100
1282
|
};
|
|
1283
|
+
/** Record<templateName, templateContent> */
|
|
1101
1284
|
templatesToRender: {
|
|
1102
1285
|
api: string;
|
|
1103
1286
|
dataContracts: string;
|
|
@@ -1110,10 +1293,16 @@ interface GenerateApiConfiguration {
|
|
|
1110
1293
|
enumDataContract: string;
|
|
1111
1294
|
objectFieldJsDoc: string;
|
|
1112
1295
|
};
|
|
1296
|
+
/** map of duplicate route names */
|
|
1113
1297
|
routeNameDuplicatesMap: Map<string, string>;
|
|
1298
|
+
/** name of the main exported class */
|
|
1114
1299
|
apiClassName: string;
|
|
1115
|
-
|
|
1116
|
-
|
|
1300
|
+
/** configuration for fetching swagger schema requests */
|
|
1301
|
+
requestOptions?: Partial<RequestInit>;
|
|
1302
|
+
/** extra configuration for extracting type names operations */
|
|
1303
|
+
extractingOptions: Partial<ExtractingOptions>;
|
|
1304
|
+
/** update configuration object during generation */
|
|
1305
|
+
update: (update: Partial<GenerateApiConfiguration["config"]>) => void;
|
|
1117
1306
|
};
|
|
1118
1307
|
modelTypes: ModelType[];
|
|
1119
1308
|
hasFormDataRoutes: boolean;
|
|
@@ -1144,7 +1333,7 @@ interface GenerateApiConfiguration {
|
|
|
1144
1333
|
fmtToJSDocLine: (line: string, params?: {
|
|
1145
1334
|
eol?: boolean;
|
|
1146
1335
|
}) => string;
|
|
1147
|
-
_:
|
|
1336
|
+
_: lodash0.LoDashStatic;
|
|
1148
1337
|
require: (path: string) => unknown;
|
|
1149
1338
|
};
|
|
1150
1339
|
}
|
|
@@ -1165,7 +1354,7 @@ interface GenerateApiOutput {
|
|
|
1165
1354
|
content: string;
|
|
1166
1355
|
withPrefix: boolean;
|
|
1167
1356
|
}) => void;
|
|
1168
|
-
renderTemplate: (templateContent: string, data: Record<string, unknown>, etaOptions?: Partial<
|
|
1357
|
+
renderTemplate: (templateContent: string, data: Record<string, unknown>, etaOptions?: Partial<eta0.EtaConfig>) => Promise<string> | string;
|
|
1169
1358
|
getTemplate: (params: {
|
|
1170
1359
|
fileName?: string;
|
|
1171
1360
|
name?: string;
|
|
@@ -1587,8 +1776,8 @@ declare function generateApi(config: Partial<GenerateApiConfiguration["config"]>
|
|
|
1587
1776
|
eol?: boolean | undefined;
|
|
1588
1777
|
}) => string;
|
|
1589
1778
|
NameResolver: typeof NameResolver;
|
|
1590
|
-
_:
|
|
1591
|
-
require: (packageOrPath: string) =>
|
|
1779
|
+
_: lodash0.LoDashStatic;
|
|
1780
|
+
require: (packageOrPath: string) => any;
|
|
1592
1781
|
};
|
|
1593
1782
|
};
|
|
1594
1783
|
getTemplate: (name: string, fileName: string, path?: string) => string | undefined;
|