swagger-typescript-api 13.0.7 → 13.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-typescript-api",
3
- "version": "13.0.7",
3
+ "version": "13.0.8",
4
4
  "description": "Generate TypeScript/JavaScript API from Swagger schema",
5
5
  "homepage": "https://github.com/acacode/swagger-typescript-api",
6
6
  "bugs": "https://github.com/acacode/swagger-typescript-api/issues",
@@ -46,12 +46,15 @@
46
46
  "prettier": "~3.3.2",
47
47
  "swagger-schema-official": "2.0.0-bab6bed",
48
48
  "swagger2openapi": "^7.0.8",
49
- "typescript": "~5.4.5"
49
+ "typescript": "~5.5.2"
50
50
  },
51
51
  "devDependencies": {
52
- "@biomejs/biome": "1.8.1",
52
+ "@biomejs/biome": "1.8.2",
53
+ "@types/didyoumean": "1.2.2",
54
+ "@types/js-yaml": "4.0.9",
53
55
  "@types/lodash": "4.17.5",
54
- "@types/node": "20.14.5",
56
+ "@types/node": "20.14.7",
57
+ "@types/swagger2openapi": "7.0.4",
55
58
  "axios": "1.7.2",
56
59
  "shx": "0.3.4",
57
60
  "vitest": "1.6.0"
@@ -23,7 +23,7 @@ class CodeFormatter {
23
23
  { newLineCharacter: ts.sys.newLine },
24
24
  )[0];
25
25
 
26
- if (fileTextChanges && fileTextChanges.textChanges.length) {
26
+ if (fileTextChanges?.textChanges.length) {
27
27
  return _.reduceRight(
28
28
  fileTextChanges.textChanges,
29
29
  (content, { span, newText }) =>
@@ -533,7 +533,7 @@ class CodeGenProcess {
533
533
 
534
534
  createApiConfig = (swaggerSchema) => {
535
535
  const { info, servers, host, basePath, externalDocs, tags } = swaggerSchema;
536
- const server = (servers && servers[0]) || { url: "" };
536
+ const server = servers?.[0] || { url: "" };
537
537
  const { title = "No title", version } = info || {};
538
538
  const { url: serverUrl } = server;
539
539
 
@@ -198,7 +198,7 @@ class CodeGenConfig {
198
198
  };
199
199
 
200
200
  compilerTsConfig = {
201
- module: "ESNext",
201
+ module: ts.ModuleKind.ESNext,
202
202
  noImplicitReturns: true,
203
203
  alwaysStrict: true,
204
204
  target: ts.ScriptTarget.ESNext,
@@ -38,7 +38,7 @@ class EnumSchemaParser extends MonoSchemaParser {
38
38
  }
39
39
 
40
40
  const refType = this.schemaUtils.getSchemaRefType(this.schema);
41
- const $ref = (refType && refType.$ref) || null;
41
+ const $ref = refType?.$ref || null;
42
42
 
43
43
  // fix schema when enum has length 1+ but value is []
44
44
  if (Array.isArray(this.schema.enum)) {
@@ -105,7 +105,7 @@ class SchemaFormatters {
105
105
  _.get(parsedSchema, ["schemaType"]) ||
106
106
  _.get(parsedSchema, ["$parsed", "schemaType"]);
107
107
  const formatterFn = _.get(this, [formatType, schemaType]);
108
- return (formatterFn && formatterFn(parsedSchema)) || parsedSchema;
108
+ return formatterFn?.(parsedSchema) || parsedSchema;
109
109
  };
110
110
 
111
111
  formatDescription = (description, inline) => {
@@ -213,10 +213,7 @@ class SchemaParser {
213
213
  this.schema = { type: this.config.Ts.Keyword.Null };
214
214
  }
215
215
  // schema is response schema
216
- if (
217
- "content" in this.schema &&
218
- typeof this.schema["content"] === "object"
219
- ) {
216
+ if ("content" in this.schema && typeof this.schema.content === "object") {
220
217
  const schema = this.extractSchemaFromResponseStruct(this.schema);
221
218
  const schemaParser = this.schemaParserFabric.createSchemaParser({
222
219
  schema,
@@ -33,13 +33,13 @@ class SchemaUtils {
33
33
  };
34
34
 
35
35
  isRefSchema = (schema) => {
36
- return !!(schema && schema["$ref"]);
36
+ return !!schema?.$ref;
37
37
  };
38
38
 
39
39
  getEnumNames = (schema) => {
40
40
  return (
41
41
  schema["x-enumNames"] ||
42
- schema["xEnumNames"] ||
42
+ schema.xEnumNames ||
43
43
  schema["x-enumnames"] ||
44
44
  schema["x-enum-varnames"]
45
45
  );
@@ -143,9 +143,7 @@ class SchemaUtils {
143
143
  const refData = this.getSchemaRefType(childSchema);
144
144
 
145
145
  if (refData) {
146
- const refObjectProperties = _.keys(
147
- (refData.rawTypeData && refData.rawTypeData.properties) || {},
148
- );
146
+ const refObjectProperties = _.keys(refData.rawTypeData?.properties || {});
149
147
  const existedRequiredKeys = refObjectProperties.filter((key) =>
150
148
  required.includes(key),
151
149
  );
@@ -160,7 +160,7 @@ class SchemaRoutes {
160
160
  const queryParamMatches = fixedRoute.match(/(\{\?.*\})/g);
161
161
  const queryParams = [];
162
162
 
163
- if (queryParamMatches && queryParamMatches.length) {
163
+ if (queryParamMatches?.length) {
164
164
  queryParamMatches.forEach((match) => {
165
165
  fixedRoute = fixedRoute.replace(match, "");
166
166
  });
@@ -220,11 +220,7 @@ class SchemaRoutes {
220
220
  this.schemaParserFabric.schemaUtils.getSchemaRefType(parameter);
221
221
  let routeParam = null;
222
222
 
223
- if (
224
- refTypeInfo &&
225
- refTypeInfo.rawTypeData.in &&
226
- refTypeInfo.rawTypeData
227
- ) {
223
+ if (refTypeInfo?.rawTypeData.in && refTypeInfo.rawTypeData) {
228
224
  if (!routeParams[refTypeInfo.rawTypeData.in]) {
229
225
  routeParams[refTypeInfo.rawTypeData.in] = [];
230
226
  }
@@ -345,7 +341,7 @@ class SchemaRoutes {
345
341
 
346
342
  /* for example: dataType = "multipart/form-data" */
347
343
  for (const dataType in content) {
348
- if (content[dataType] && content[dataType].schema) {
344
+ if (content[dataType]?.schema) {
349
345
  return {
350
346
  ...content[dataType].schema,
351
347
  dataType,
@@ -510,9 +506,7 @@ class SchemaRoutes {
510
506
  responses: responseInfos,
511
507
  success: {
512
508
  schema: successResponse,
513
- type:
514
- (successResponse && successResponse.type) ||
515
- this.config.Ts.Keyword.Any,
509
+ type: successResponse?.type || this.config.Ts.Keyword.Any,
516
510
  },
517
511
  error: {
518
512
  schemas: errorResponses,
@@ -640,10 +634,7 @@ class SchemaRoutes {
640
634
  }
641
635
 
642
636
  return {
643
- paramName:
644
- requestBodyName ||
645
- (requestBody && requestBody.name) ||
646
- DEFAULT_BODY_ARG_NAME,
637
+ paramName: requestBodyName || requestBody?.name || DEFAULT_BODY_ARG_NAME,
647
638
  contentTypes,
648
639
  contentKind,
649
640
  schema,
@@ -892,7 +883,7 @@ class SchemaRoutes {
892
883
  moduleNameFirstTag && firstTag
893
884
  ? _.camelCase(firstTag)
894
885
  : _.camelCase(_.compact(_.split(route, "/"))[moduleNameIndex]);
895
- let hasSecurity = !!(globalSecurity && globalSecurity.length);
886
+ let hasSecurity = !!globalSecurity?.length;
896
887
  if (security) {
897
888
  hasSecurity = security.length > 0;
898
889
  }
@@ -25,7 +25,7 @@ class FileSystem {
25
25
  }
26
26
 
27
27
  getFileContent = (path) => {
28
- return fs.readFileSync(path, { encoding: "UTF-8" });
28
+ return fs.readFileSync(path, { encoding: "utf8" });
29
29
  };
30
30
 
31
31
  readDir = (path) => {