swagger-typescript-api 11.1.1 → 11.1.2

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/index.js CHANGED
@@ -308,7 +308,9 @@ const main = async () => {
308
308
  } catch (e) {
309
309
  console.error(e);
310
310
  process.exit(1);
311
+ return;
311
312
  }
313
+ process.exit(0);
312
314
  };
313
315
 
314
316
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-typescript-api",
3
- "version": "11.1.1",
3
+ "version": "11.1.2",
4
4
  "description": "Generate typescript/javascript api from swagger schema",
5
5
  "scripts": {
6
6
  "cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
@@ -38,6 +38,7 @@
38
38
  "test:--enum-names-as-values": "node tests/spec/enumNamesAsValues/test.js",
39
39
  "test:--default-response": "node tests/spec/defaultResponse/test.js",
40
40
  "test:--js": "node tests/spec/js/test.js",
41
+ "test:jsSingleHttpClientModular": "node tests/spec/jsSingleHttpClientModular/test.js",
41
42
  "test:--js--axios": "node tests/spec/jsAxios/test.js",
42
43
  "test:--axios": "node tests/spec/axios/test.js",
43
44
  "test:--another-array-type": "node tests/spec/another-array-type/test.js",
@@ -46,11 +47,15 @@
46
47
  "test:--type-suffix--type-prefix": "node tests/spec/typeSuffixPrefix/test.js",
47
48
  "test:--dot-path-params": "node tests/spec/dot-path-params/test.js",
48
49
  "test:--primitive-type-constructs": "node tests/spec/primitive-type-constructs/test.js",
49
- "test:--cli": "node index.js -p tests/spec/cli/schema.json -o tests/spec/cli -n schema.ts --extract-response-body --extract-response-error --api-class-name MySuperApi --type-prefix Prefix",
50
+ "test:--cli": "node index.js -p tests/spec/cli/schema.json -o tests/spec/cli -n schema.ts --extract-response-body --extract-response-error --api-class-name MySuperApi --type-prefix Prefix && node tests/spec/cli/test.js",
50
51
  "test:partialBaseTemplate": "node tests/spec/partialBaseTemplate/test.js",
51
52
  "test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js",
52
53
  "test:--patch": "node tests/spec/patch/test.js",
53
- "test:deprecated": "node tests/spec/deprecated/test.js"
54
+ "test:deprecated": "node tests/spec/deprecated/test.js",
55
+ "test:nullableRefTest3.0": "node tests/spec/nullable-3.0/test.js",
56
+ "test:nullableRefTest2.0": "node tests/spec/nullable-2.0/test.js",
57
+ "test:additionalProperties2.0": "node tests/spec/additional-properties-2.0/test.js",
58
+ "test:enums2.0": "node tests/spec/enums-2.0/test.js"
54
59
  },
55
60
  "author": "acacode",
56
61
  "license": "MIT",
@@ -61,6 +66,7 @@
61
66
  "@types/node": "^18.11.7",
62
67
  "@types/prettier": "^2.7.1",
63
68
  "all-contributors-cli": "^6.20.0",
69
+ "axios": "^1.1.3",
64
70
  "cross-env": "^7.0.3",
65
71
  "git-diff": "^2.0.6",
66
72
  "husky": "^4.3.6",
@@ -149,7 +149,7 @@ class SchemaParser {
149
149
  });
150
150
  },
151
151
  [SCHEMA_TYPES.OBJECT]: (schema, typeName) => {
152
- const content = this.getObjectSchemaContent(schema);
152
+ const contentProperties = this.getObjectSchemaContent(schema);
153
153
 
154
154
  return this.attachParsedRef(schema, {
155
155
  ...(_.isObject(schema) ? schema : {}),
@@ -159,8 +159,8 @@ class SchemaParser {
159
159
  typeIdentifier: this.config.Ts.Keyword.Interface,
160
160
  name: typeName,
161
161
  description: this.schemaFormatters.formatDescription(schema.description),
162
- allFieldsAreOptional: !_.some(_.values(content), (part) => part.isRequired),
163
- content: content,
162
+ allFieldsAreOptional: !_.some(_.values(contentProperties), (part) => part.isRequired),
163
+ content: contentProperties,
164
164
  });
165
165
  },
166
166
  [SCHEMA_TYPES.COMPLEX]: (schema, typeName) => {
@@ -424,7 +424,7 @@ class SchemaParser {
424
424
  };
425
425
  });
426
426
 
427
- if (additionalProperties === true) {
427
+ if (additionalProperties) {
428
428
  propertiesContent.push({
429
429
  $$raw: { additionalProperties },
430
430
  description: "",
@@ -1,49 +1,60 @@
1
- const ts = require("typescript");
2
-
3
- function translate(fileName, content, options) {
4
- const output = {};
5
- const host = ts.createCompilerHost(options, true);
6
- const fileNames = [fileName];
7
- const originalSourceFileGet = host.getSourceFile.bind(host);
8
- host.getSourceFile = (sourceFileName, languageVersion, onError, shouldCreateNewSourceFile) => {
9
- if (sourceFileName !== fileName)
10
- return originalSourceFileGet(sourceFileName, languageVersion, onError, shouldCreateNewSourceFile);
11
-
12
- return ts.createSourceFile(sourceFileName, content, languageVersion, true, ts.ScriptKind.External);
13
- };
14
-
15
- host.writeFile = (fileName, contents) => {
16
- output[fileName] = contents;
17
- };
18
-
19
- ts.createProgram(fileNames, options, host).emit();
20
-
21
- return output;
22
- }
23
-
24
- module.exports = {
25
- translate: (fileName, sourceTypeScript) => {
26
- const translated = translate(fileName, sourceTypeScript, {
27
- module: "ESNext",
28
- noImplicitReturns: true,
29
- alwaysStrict: true,
30
- target: ts.ScriptTarget.ESNext,
31
- declaration: true,
32
- noImplicitAny: false,
33
- sourceMap: false,
34
- removeComments: false,
35
- disableSizeLimit: true,
36
- esModuleInterop: true,
37
- emitDecoratorMetadata: true,
38
- skipLibCheck: true,
39
- });
40
-
41
- const sourceFileName = fileName.replace(ts.Extension.Ts, ts.Extension.Js);
42
- const declarationFileName = fileName.replace(ts.Extension.Ts, ts.Extension.Dts);
43
-
44
- return {
45
- sourceContent: translated[sourceFileName],
46
- declarationContent: translated[declarationFileName],
47
- };
48
- },
49
- };
1
+ const ts = require("typescript");
2
+
3
+ function translate(fileName, content, options) {
4
+ const output = {};
5
+ const host = ts.createCompilerHost(options, true);
6
+ const fileNames = [fileName];
7
+ const originalSourceFileGet = host.getSourceFile.bind(host);
8
+ host.getSourceFile = (sourceFileName, languageVersion, onError, shouldCreateNewSourceFile) => {
9
+ if (sourceFileName !== fileName)
10
+ return originalSourceFileGet(sourceFileName, languageVersion, onError, shouldCreateNewSourceFile);
11
+
12
+ return ts.createSourceFile(sourceFileName, content, languageVersion, true, ts.ScriptKind.External);
13
+ };
14
+
15
+ host.writeFile = (fileName, contents) => {
16
+ output[fileName] = contents;
17
+ };
18
+
19
+ ts.createProgram(fileNames, options, host).emit();
20
+
21
+ return output;
22
+ }
23
+
24
+ module.exports = {
25
+ translate: (fileName, sourceTypeScript) => {
26
+ const translated = translate(fileName, sourceTypeScript, {
27
+ module: "ESNext",
28
+ noImplicitReturns: true,
29
+ alwaysStrict: true,
30
+ target: ts.ScriptTarget.ESNext,
31
+ declaration: true,
32
+ noImplicitAny: false,
33
+ sourceMap: false,
34
+ removeComments: false,
35
+ disableSizeLimit: true,
36
+ esModuleInterop: true,
37
+ emitDecoratorMetadata: true,
38
+ skipLibCheck: true,
39
+ });
40
+
41
+ const sourceFileName = fileName.replace(ts.Extension.Ts, ts.Extension.Js);
42
+ const declarationFileName = fileName.replace(ts.Extension.Ts, ts.Extension.Dts);
43
+ const sourceContent = translated[sourceFileName];
44
+ const tsImportRows = sourceTypeScript.split("\n").filter((line) => line.startsWith("import "));
45
+ const declarationContent = translated[declarationFileName]
46
+ .split("\n")
47
+ .map((line) => {
48
+ if (line.startsWith("import ")) {
49
+ return tsImportRows.shift();
50
+ }
51
+ return line;
52
+ })
53
+ .join("\n");
54
+
55
+ return {
56
+ sourceContent: sourceContent,
57
+ declarationContent: declarationContent,
58
+ };
59
+ },
60
+ };