swagger-typescript-api 13.2.8 → 13.2.10

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/dist/lib.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- import * as lodash0$1 from "lodash";
2
1
  import * as lodash0 from "lodash";
3
2
  import lodash from "lodash";
4
- import * as typescript$1 from "typescript";
5
3
  import * as typescript from "typescript";
6
4
  import * as eta0 from "eta";
7
5
  import { OpenAPI } from "openapi-types";
@@ -379,7 +377,7 @@ declare class JavascriptTranslator extends Translator {
379
377
  compileTSCode: (input: TranslatorIO) => Record<string, string>;
380
378
  translate: (input: any) => Promise<{
381
379
  fileName: any;
382
- fileExtension: typescript$1.Extension;
380
+ fileExtension: typescript.Extension;
383
381
  fileContent: string;
384
382
  }[]>;
385
383
  }
@@ -528,7 +526,7 @@ declare class CodeGenProcess {
528
526
  }) => string;
529
527
  NameResolver: typeof NameResolver;
530
528
  _: lodash.LoDashStatic;
531
- require: (packageOrPath: string) => Promise<any>;
529
+ require: (packageOrPath: string) => any;
532
530
  };
533
531
  };
534
532
  getTemplate: (name: string, fileName: string, path?: string) => string | undefined;
@@ -633,7 +631,7 @@ declare class CodeGenProcess {
633
631
  }) => string;
634
632
  NameResolver: typeof NameResolver;
635
633
  _: lodash.LoDashStatic;
636
- require: (packageOrPath: string) => Promise<any>;
634
+ require: (packageOrPath: string) => any;
637
635
  };
638
636
  config: CodeGenConfig;
639
637
  };
@@ -670,7 +668,7 @@ declare class TemplatesWorker {
670
668
  getTemplatePaths: (config: CodeGenConfig) => CodeGenConfig["templatePaths"];
671
669
  cropExtension: (path: string) => string;
672
670
  getTemplateFullPath: (path_: string, fileName: string) => string | undefined;
673
- requireFnFromTemplate: (packageOrPath: string) => Promise<any>;
671
+ requireFnFromTemplate: (packageOrPath: string) => any;
674
672
  getTemplate: (name: string, fileName: string, path?: string) => string | undefined;
675
673
  getTemplates: ({
676
674
  templatePaths
@@ -774,6 +772,73 @@ declare class MonoSchemaParser {
774
772
  //#endregion
775
773
  //#region types/index.d.ts
776
774
  type HttpClientType = (typeof HTTP_CLIENT)[keyof typeof HTTP_CLIENT];
775
+ type CodeGenConstruct = {
776
+ Keyword: {
777
+ Number: string;
778
+ String: string;
779
+ Boolean: string;
780
+ Any: string;
781
+ Void: string;
782
+ Unknown: string;
783
+ Null: string;
784
+ Undefined: string;
785
+ Object: string;
786
+ File: string;
787
+ Date: string;
788
+ Type: string;
789
+ Enum: string;
790
+ Interface: string;
791
+ Array: string;
792
+ Record: string;
793
+ Intersection: string;
794
+ Union: string;
795
+ };
796
+ CodeGenKeyword: {
797
+ UtilRequiredKeys: string;
798
+ };
799
+ ArrayType: (content: unknown) => string;
800
+ StringValue: (content: unknown) => string;
801
+ BooleanValue: (content: unknown) => string;
802
+ NumberValue: (content: unknown) => string;
803
+ NullValue: (content: unknown) => string;
804
+ UnionType: (content: unknown) => string;
805
+ ExpressionGroup: (content: unknown) => string;
806
+ IntersectionType: (content: unknown) => string;
807
+ RecordType: (content: unknown) => string;
808
+ TypeField: (content: unknown) => string;
809
+ InterfaceDynamicField: (content: unknown) => string;
810
+ EnumUsageKey: (enumStruct: unknown, key: unknown) => string;
811
+ EnumField: (content: unknown) => string;
812
+ EnumFieldDescription: (content: unknown) => string;
813
+ EnumFieldsWrapper: (content: unknown) => string;
814
+ ObjectWrapper: (content: unknown) => string;
815
+ MultilineComment: (content: unknown) => string;
816
+ TypeWithGeneric: (content: unknown) => string;
817
+ Tuple: (content: unknown) => string;
818
+ };
819
+ type PrimitiveTypeStructValue = string | ((schema: Record<string, unknown>, parser: SchemaParser) => string);
820
+ type PrimitiveTypeStruct = Record<"integer" | "number" | "boolean" | "object" | "file" | "string" | "array", string | ({
821
+ $default: PrimitiveTypeStructValue;
822
+ } & Record<string, PrimitiveTypeStructValue>)>;
823
+ interface GenerateApiParamsFromPath extends Partial<GenerateApiConfiguration["config"]> {
824
+ /**
825
+ * path to swagger schema
826
+ */
827
+ input: string;
828
+ }
829
+ interface GenerateApiParamsFromUrl extends Partial<GenerateApiConfiguration["config"]> {
830
+ /**
831
+ * url to swagger schema
832
+ */
833
+ url: string;
834
+ }
835
+ interface GenerateApiParamsFromSpecLiteral extends Partial<GenerateApiConfiguration["config"]> {
836
+ /**
837
+ * swagger schema JSON
838
+ */
839
+ spec: swagger_schema_official0.Spec;
840
+ }
841
+ type GenerateApiParams = GenerateApiParamsFromPath | GenerateApiParamsFromUrl | GenerateApiParamsFromSpecLiteral;
777
842
  type BuildRouteParam = {
778
843
  /** {bar} */
779
844
  $match: string;
@@ -822,6 +887,7 @@ interface Hooks {
822
887
  /** customize name of route (operationId), you can do it with using onCreateRouteName too */
823
888
  onFormatRouteName?: (routeInfo: RawRouteInfo, templateRouteName: string) => string | undefined;
824
889
  }
890
+ type RouteNameRouteInfo = Record<string, unknown>;
825
891
  type RouteNameInfo = {
826
892
  usage: string;
827
893
  original: string;
@@ -864,6 +930,12 @@ interface ParsedSchema<C> {
864
930
  isExtractedResponseBody?: boolean;
865
931
  isExtractedResponseError?: boolean;
866
932
  }
933
+ interface PathArgInfo {
934
+ name: string;
935
+ optional: boolean;
936
+ type: string;
937
+ description?: string;
938
+ }
867
939
  interface SchemaComponent {
868
940
  $ref: string;
869
941
  typeName: string;
@@ -1012,18 +1084,45 @@ type ExtractingOptions = {
1012
1084
  };
1013
1085
  interface GenerateApiConfiguration {
1014
1086
  apiConfig: {
1087
+ /** base url from schema */
1015
1088
  baseUrl: string;
1089
+ /** document title */
1016
1090
  title: string;
1091
+ /** document version */
1017
1092
  version: string;
1093
+ /** description split into lines */
1018
1094
  description: string[];
1095
+ /** flag that description is present */
1019
1096
  hasDescription: boolean;
1020
1097
  };
1021
1098
  config: {
1099
+ /** path to swagger schema */
1022
1100
  input: string;
1101
+ /**
1102
+ * generate separated files for http client, data contracts, and routes
1103
+ * @default false
1104
+ */
1105
+ modular: boolean;
1106
+ /**
1107
+ * path to folder where the created api module will be placed.
1108
+ * may be set to `false` to skip writing content to disk; in this case
1109
+ * the `files` array on the return value will contain the generated contents.
1110
+ */
1023
1111
  output: string | false;
1112
+ /** url to swagger schema */
1024
1113
  url: string;
1114
+ /** swagger schema JSON */
1025
1115
  spec: unknown;
1116
+ /**
1117
+ * file name for the generated API module
1118
+ * @default 'Api.ts'
1119
+ */
1026
1120
  fileName: string;
1121
+ /**
1122
+ * path to folder containing custom templates
1123
+ * @default ""
1124
+ */
1125
+ templates: string;
1027
1126
  templatePaths: {
1028
1127
  /** `templates/base` */
1029
1128
  base: string;
@@ -1036,66 +1135,176 @@ interface GenerateApiConfiguration {
1036
1135
  /** custom path to templates (`--templates`) */
1037
1136
  custom: string | null;
1038
1137
  };
1138
+ /** authorisation token for private swagger schema access */
1039
1139
  authorizationToken?: string;
1140
+ /** generate additional information about request responses and error typings */
1040
1141
  generateResponses: boolean;
1142
+ /**
1143
+ * use "default" response status code as success response.
1144
+ * some swagger schemas treat "default" as a successful response.
1145
+ */
1041
1146
  defaultResponseAsSuccess: boolean;
1147
+ /** generate type definitions for API routes */
1042
1148
  generateRouteTypes: boolean;
1149
+ /** generate an API client */
1043
1150
  generateClient: boolean;
1151
+ /** generate all "enum" types as union types (T1 | T2 | TN) */
1044
1152
  generateUnionEnums: boolean;
1153
+ /** parsed swagger schema */
1045
1154
  swaggerSchema: object;
1155
+ /** original swagger schema */
1046
1156
  originalSchema: object;
1157
+ /** map of schema component references */
1047
1158
  componentsMap: Record<string, SchemaComponent>;
1159
+ /** flag indicating the schema was converted from Swagger 2.0 */
1048
1160
  convertedFromSwagger2: boolean;
1161
+ /** determines which path index should be used for routes separation */
1049
1162
  moduleNameIndex: number;
1163
+ /** use the first tag for the module name */
1050
1164
  moduleNameFirstTag: boolean;
1165
+ /** extra templates */
1051
1166
  extraTemplates: {
1052
1167
  name: string;
1053
1168
  path: string;
1054
1169
  }[];
1170
+ /** extract request params to data contract */
1055
1171
  extractRequestParams: boolean;
1172
+ /** unwrap the data item from the response */
1056
1173
  unwrapResponseData: boolean;
1174
+ /** sort data contracts in alphabetical order */
1057
1175
  sortTypes: boolean;
1176
+ /** sort routes in alphabetical order */
1058
1177
  sortRoutes: boolean;
1178
+ /** ability to send HttpClient instance to Api constructor */
1059
1179
  singleHttpClient: boolean;
1180
+ /** prefix string value for type names */
1060
1181
  typePrefix: string;
1182
+ /** suffix string value for type names */
1061
1183
  typeSuffix: string;
1184
+ /** prefix string value for enum keys */
1062
1185
  enumKeyPrefix: string;
1186
+ /** suffix string value for enum keys */
1063
1187
  enumKeySuffix: string;
1188
+ /** fix up small errors in the swagger source definition */
1064
1189
  patch: boolean;
1190
+ /** remove output directory before generating */
1065
1191
  cleanOutput: boolean;
1192
+ /** output debug messages */
1066
1193
  debug: boolean;
1194
+ /**
1195
+ * generate array types as Array<Type>
1196
+ * @default false
1197
+ */
1067
1198
  anotherArrayType: boolean;
1199
+ /** extract request body type to data contract */
1068
1200
  extractRequestBody: boolean;
1201
+ /** generated http client type */
1069
1202
  httpClientType: "axios" | "fetch";
1203
+ /** generate readonly properties */
1070
1204
  addReadonly: boolean;
1205
+ /** customise primitive type mappings */
1206
+ primitiveTypeConstructs?: (struct: PrimitiveTypeStruct) => Partial<PrimitiveTypeStruct>;
1207
+ /** customise code generation constructs */
1208
+ codeGenConstructs?: (struct: CodeGenConstruct) => Partial<CodeGenConstruct>;
1209
+ /** extract response body type to data contract */
1071
1210
  extractResponseBody: boolean;
1211
+ /** extract response error type to data contract */
1072
1212
  extractResponseError: boolean;
1213
+ /** extract all enums from nested types/interfaces to `enum` construction */
1073
1214
  extractEnums: boolean;
1215
+ /** extract all enums from inline interface/type content to typescript enum construction */
1074
1216
  extractResponses: boolean;
1217
+ /**
1218
+ * prefix string value needed to fix invalid type names
1219
+ * @default "Type"
1220
+ */
1075
1221
  fixInvalidTypeNamePrefix: string;
1222
+ /**
1223
+ * prefix string value needed to fix invalid enum keys
1224
+ * @default "Value"
1225
+ */
1076
1226
  fixInvalidEnumKeyPrefix: string;
1227
+ /**
1228
+ * default type for empty response schema
1229
+ * @default "void"
1230
+ */
1077
1231
  defaultResponseType: string;
1232
+ /**
1233
+ * generate js api module with declaration file
1234
+ * @default false
1235
+ */
1078
1236
  toJS: boolean;
1237
+ /** disable throwing on a non-successful response */
1079
1238
  disableThrowOnError: boolean;
1239
+ /**
1240
+ * output only errors to console
1241
+ * @default false
1242
+ */
1080
1243
  silent: boolean;
1244
+ /** hooks for customising the generation process */
1081
1245
  hooks: Partial<Hooks>;
1246
+ /** use enum names as values */
1082
1247
  enumNamesAsValues: boolean;
1248
+ /** package version */
1083
1249
  version: string;
1250
+ /** ts compiler configuration object (for --to-js option) */
1084
1251
  compilerTsConfig: Record<string, unknown>;
1252
+ /** enum key resolver name */
1085
1253
  enumKeyResolverName: string;
1254
+ /** type name resolver name */
1086
1255
  typeNameResolverName: string;
1256
+ /** specific argument name resolver name */
1087
1257
  specificArgNameResolverName: string;
1258
+ /**
1259
+ * custom ts->* translator
1260
+ * do not use constructor args, just send class reference
1261
+ */
1088
1262
  customTranslator?: new () => Translator;
1263
+ /** internal constants */
1264
+ constants: typeof constants_d_exports;
1265
+ /** code generation constructs for TypeScript */
1266
+ Ts: CodeGenConstruct;
1267
+ /**
1268
+ * swagger schema type -> typescript type
1269
+ * https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-times
1270
+ */
1271
+ primitiveTypes: PrimitiveTypeStruct;
1272
+ /** built-in template info */
1273
+ templateInfos: {
1274
+ name: string;
1275
+ fileName: string;
1276
+ }[];
1277
+ /** supported template file extensions */
1278
+ templateExtensions: string[];
1279
+ /** range of HTTP status codes treated as success */
1280
+ successResponseStatusRange: [number, number];
1281
+ /** custom schema parsers */
1282
+ schemaParsers?: {
1283
+ complexOneOf?: MonoSchemaParser;
1284
+ complexAllOf?: MonoSchemaParser;
1285
+ complexAnyOf?: MonoSchemaParser;
1286
+ complexNot?: MonoSchemaParser;
1287
+ enum?: MonoSchemaParser;
1288
+ object?: MonoSchemaParser;
1289
+ complex?: MonoSchemaParser;
1290
+ primitive?: MonoSchemaParser;
1291
+ discriminator?: MonoSchemaParser;
1292
+ array?: MonoSchemaParser;
1293
+ };
1294
+ /** internal options for templates */
1089
1295
  internalTemplateOptions: {
1090
1296
  addUtilRequiredKeysType: boolean;
1091
1297
  };
1298
+ /** resolver for component type names */
1092
1299
  componentTypeNameResolver: ComponentTypeNameResolver;
1300
+ /** generated file names */
1093
1301
  fileNames: {
1094
1302
  dataContracts: string;
1095
1303
  routeTypes: string;
1096
1304
  httpClient: string;
1097
1305
  outOfModuleApi: string;
1098
1306
  };
1307
+ /** Record<templateName, templateContent> */
1099
1308
  templatesToRender: {
1100
1309
  api: string;
1101
1310
  dataContracts: string;
@@ -1108,10 +1317,16 @@ interface GenerateApiConfiguration {
1108
1317
  enumDataContract: string;
1109
1318
  objectFieldJsDoc: string;
1110
1319
  };
1320
+ /** map of duplicate route names */
1111
1321
  routeNameDuplicatesMap: Map<string, string>;
1322
+ /** name of the main exported class */
1112
1323
  apiClassName: string;
1113
- requestOptions?: RequestInit;
1114
- extractingOptions: ExtractingOptions;
1324
+ /** configuration for fetching swagger schema requests */
1325
+ requestOptions?: Partial<RequestInit>;
1326
+ /** extra configuration for extracting type names operations */
1327
+ extractingOptions: Partial<ExtractingOptions>;
1328
+ /** update configuration object during generation */
1329
+ update: (update: Partial<GenerateApiConfiguration["config"]>) => void;
1115
1330
  };
1116
1331
  modelTypes: ModelType[];
1117
1332
  hasFormDataRoutes: boolean;
@@ -1142,7 +1357,7 @@ interface GenerateApiConfiguration {
1142
1357
  fmtToJSDocLine: (line: string, params?: {
1143
1358
  eol?: boolean;
1144
1359
  }) => string;
1145
- _: lodash0$1.LoDashStatic;
1360
+ _: lodash0.LoDashStatic;
1146
1361
  require: (path: string) => unknown;
1147
1362
  };
1148
1363
  }
@@ -1586,7 +1801,7 @@ declare function generateApi(config: Partial<GenerateApiConfiguration["config"]>
1586
1801
  }) => string;
1587
1802
  NameResolver: typeof NameResolver;
1588
1803
  _: lodash0.LoDashStatic;
1589
- require: (packageOrPath: string) => Promise<any>;
1804
+ require: (packageOrPath: string) => any;
1590
1805
  };
1591
1806
  };
1592
1807
  getTemplate: (name: string, fileName: string, path?: string) => string | undefined;
@@ -1611,5 +1826,5 @@ declare function generateApi(config: Partial<GenerateApiConfiguration["config"]>
1611
1826
  }) => Promise<string>;
1612
1827
  }>;
1613
1828
  //#endregion
1614
- export { constants_d_exports as constants, generateApi, generateTemplates };
1829
+ export { ExtractingOptions, GenerateApiConfiguration, GenerateApiOutput, GenerateApiParams, GenerateTemplatesOutput, GenerateTemplatesParams, Hooks, HttpClientType, ModelType, ParsedRoute, ParsedRouteRequest, ParsedRouteResponse, ParsedSchema, PathArgInfo, RawRouteInfo, RequestContentKind, RequestResponseInfo, RouteNameInfo, RouteNameRouteInfo, SCHEMA_TYPES, SchemaComponent, SchemaTypeEnumContent, SchemaTypeObjectContent, SchemaTypePrimitiveContent, constants_d_exports as constants, generateApi, generateTemplates };
1615
1830
  //# sourceMappingURL=lib.d.ts.map
package/dist/lib.js CHANGED
@@ -1,3 +1,3 @@
1
- import { constants_exports, generateApi, generateTemplates } from "./src-4gUT3jPg.js";
1
+ import { RequestContentKind, SCHEMA_TYPES, constants_exports, generateApi, generateTemplates } from "./src-s8addnrG.js";
2
2
 
3
- export { constants_exports as constants, generateApi, generateTemplates };
3
+ export { RequestContentKind, SCHEMA_TYPES, constants_exports as constants, generateApi, generateTemplates };