swagger-typescript-api 10.0.0 → 10.0.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.
Files changed (56) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +284 -260
  3. package/index.d.ts +7 -1
  4. package/index.js +115 -115
  5. package/package.json +116 -113
  6. package/src/apiConfig.js +30 -30
  7. package/src/common.js +28 -28
  8. package/src/components.js +3 -5
  9. package/src/config.js +4 -0
  10. package/src/constants.js +7 -0
  11. package/src/filePrefix.js +14 -14
  12. package/src/files.js +6 -6
  13. package/src/formatFileContent.js +13 -6
  14. package/src/index.js +271 -270
  15. package/src/logger.js +59 -59
  16. package/src/modelNames.js +78 -78
  17. package/src/modelTypes.js +31 -30
  18. package/src/output.js +165 -166
  19. package/src/prettierOptions.js +23 -23
  20. package/src/render/utils/fmtToJSDocLine.js +10 -10
  21. package/src/render/utils/index.js +31 -23
  22. package/src/render/utils/templateRequire.js +17 -17
  23. package/src/routeNames.js +46 -46
  24. package/src/routes.js +4 -1
  25. package/src/schema.js +87 -64
  26. package/src/swagger.js +4 -1
  27. package/src/templates.js +155 -132
  28. package/src/translators/JavaScript.js +60 -60
  29. package/src/typeFormatters.js +121 -75
  30. package/src/utils/id.js +9 -9
  31. package/src/utils/random.js +14 -14
  32. package/src/utils/resolveName.js +97 -97
  33. package/templates/README.md +17 -13
  34. package/templates/base/README.md +7 -7
  35. package/templates/base/data-contract-jsdoc.ejs +32 -0
  36. package/templates/base/data-contracts.ejs +28 -0
  37. package/templates/base/enum-data-contract.ejs +15 -0
  38. package/templates/base/{http-client.eta → http-client.ejs} +2 -2
  39. package/templates/base/http-clients/{axios-http-client.eta → axios-http-client.ejs} +133 -145
  40. package/templates/base/http-clients/{fetch-http-client.eta → fetch-http-client.ejs} +222 -222
  41. package/templates/base/interface-data-contract.ejs +10 -0
  42. package/templates/base/object-field-jsdoc.ejs +28 -0
  43. package/templates/base/{route-docs.eta → route-docs.ejs} +31 -31
  44. package/templates/base/{route-name.eta → route-name.ejs} +42 -42
  45. package/templates/base/{route-type.eta → route-type.ejs} +21 -21
  46. package/templates/base/type-data-contract.ejs +15 -0
  47. package/templates/default/README.md +6 -6
  48. package/templates/default/{api.eta → api.ejs} +65 -65
  49. package/templates/default/{procedure-call.eta → procedure-call.ejs} +98 -98
  50. package/templates/default/{route-types.eta → route-types.ejs} +28 -28
  51. package/templates/modular/README.md +6 -6
  52. package/templates/modular/{api.eta → api.ejs} +28 -28
  53. package/templates/modular/{procedure-call.eta → procedure-call.ejs} +98 -98
  54. package/templates/modular/{route-types.eta → route-types.ejs} +18 -18
  55. package/CHANGELOG.md +0 -866
  56. package/templates/base/data-contracts.eta +0 -45
package/index.d.ts CHANGED
@@ -44,6 +44,11 @@ interface GenerateApiParamsBase {
44
44
  */
45
45
  generateResponses?: boolean;
46
46
 
47
+ /**
48
+ * unwrap the data item from the response
49
+ */
50
+ unwrapResponseData?: boolean;
51
+
47
52
  /**
48
53
  * generate js api module with declaration file (default: false)
49
54
  */
@@ -329,6 +334,7 @@ export interface GenerateApiConfiguration {
329
334
  disableStrictSSL: boolean;
330
335
  disableProxy: boolean;
331
336
  extractRequestParams: boolean;
337
+ unwrapResponseData: boolean;
332
338
  fileNames: {
333
339
  dataContracts: string;
334
340
  routeTypes: string;
@@ -343,7 +349,7 @@ export interface GenerateApiConfiguration {
343
349
  routeName: string;
344
350
  };
345
351
  routeNameDuplicatesMap: Map<string, string>;
346
- apiClassName: string
352
+ apiClassName: string;
347
353
  };
348
354
  modelTypes: ModelType[];
349
355
  rawModelTypes: SchemaComponent[];
package/index.js CHANGED
@@ -1,115 +1,115 @@
1
- #!/usr/bin/env node
2
-
3
- // Copyright (c) 2019-present acacode
4
- // Node module: swagger-typescript-api
5
- // This file is licensed under the MIT License.
6
- // License text available at https://opensource.org/licenses/MIT
7
- // Repository https://github.com/acacode/swagger-typescript-api
8
-
9
- const { Command } = require("commander");
10
- const { resolve } = require("path");
11
- const { generateApi } = require("./src");
12
- const { version, name: packageName } = require("./package.json");
13
- const { TS_KEYWORDS, HTTP_CLIENT } = require("./src/constants");
14
-
15
- const program = new Command(packageName);
16
-
17
- program.storeOptionsAsProperties(true);
18
-
19
- program
20
- .version(version, "-v, --version", "output the current version")
21
- .description("Generate api via swagger scheme.\nSupports OA 3.0, 2.0, JSON, yaml.");
22
-
23
- program
24
- .requiredOption("-p, --path <path>", "path/url to swagger scheme")
25
- .option("-o, --output <output>", "output path of typescript api file", "./")
26
- .option("-n, --name <name>", "name of output typescript api file", "Api.ts")
27
- .option("-t, --templates <path>", "path to folder containing templates")
28
- .option(
29
- "-d, --default-as-success",
30
- 'use "default" response status code as success response too.\n' +
31
- 'some swagger schemas use "default" response status code as success response type by default.',
32
- false,
33
- )
34
- .option(
35
- "-r, --responses",
36
- "generate additional information about request responses\n" + "also add typings for bad responses",
37
- false,
38
- )
39
- .option("--union-enums", 'generate all "enum" types as union types (T1 | T2 | TN)', false)
40
- .option("--add-readonly", "generate readonly properties", false)
41
- .option("--route-types", "generate type definitions for API routes", false)
42
- .option("--no-client", "do not generate an API class", false)
43
- .option("--enum-names-as-values", "use values in 'x-enumNames' as enum values (not only as keys)", false)
44
- .option(
45
- "--extract-request-params",
46
- "extract request params to data contract (Also combine path params and query params into one object)",
47
- false,
48
- )
49
- .option("--extract-request-body", "extract request body type to data contract", false)
50
- .option("--extract-response-body", "extract response body type to data contract", false)
51
- .option("--extract-response-error", "extract response error type to data contract", false)
52
- .option("--modular", "generate separated files for http client, data contracts, and routes", false)
53
- .option("--js", "generate js api module with declaration file", false)
54
- .option(
55
- "--module-name-index <number>",
56
- "determines which path index should be used for routes separation (example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites)",
57
- 0,
58
- )
59
- .option("--module-name-first-tag", "splits routes based on the first tag", false)
60
- .option("--disableStrictSSL", "disabled strict SSL", false)
61
- .option("--disableProxy", "disabled proxy", false)
62
- .option("--axios", "generate axios http client", false)
63
- .option("--unwrap-response-data", "unwrap the data item from the response", false)
64
- .option("--disable-throw-on-error", "Do not throw an error when response.ok is not true", false)
65
- .option("--single-http-client", "Ability to send HttpClient instance to Api constructor", false)
66
- .option("--silent", "Output only errors to console", false)
67
- .option("--default-response <type>", "default type for empty response schema", TS_KEYWORDS.VOID)
68
- .option("--type-prefix <string>", "data contract name prefix", "")
69
- .option("--type-suffix <string>", "data contract name suffix", "")
70
- .option("--clean-output", "clean output folder before generate api. WARNING: May cause data loss", false)
71
- .option("--patch", "fix up small errors in the swagger source definition", false);
72
-
73
- program.parse(process.argv);
74
-
75
- generateApi({
76
- name: program.name,
77
- url: program.path,
78
- generateRouteTypes: program.routeTypes,
79
- generateClient: !!(program.axios || program.client),
80
- httpClientType: program.axios ? HTTP_CLIENT.AXIOS : HTTP_CLIENT.FETCH,
81
- defaultResponseAsSuccess: program.defaultAsSuccess,
82
- defaultResponseType: program.defaultResponse,
83
- unwrapResponseData: program.unwrapResponseData,
84
- disableThrowOnError: program.disableThrowOnError,
85
- sortTypes: program.sortTypes,
86
- generateUnionEnums: program.unionEnums,
87
- addReadonly: program.addReadonly,
88
- generateResponses: program.responses,
89
- extractRequestParams: !!program.extractRequestParams,
90
- extractRequestBody: !!program.extractRequestBody,
91
- extractResponseBody: !!program.extractResponseBody,
92
- extractResponseError: !!program.extractResponseError,
93
- input: resolve(process.cwd(), program.path),
94
- output: resolve(process.cwd(), program.output || "."),
95
- templates: program.templates,
96
- modular: !!program.modular,
97
- toJS: !!program.js,
98
- enumNamesAsValues: program.enumNamesAsValues,
99
- moduleNameIndex: +(program.moduleNameIndex || 0),
100
- moduleNameFirstTag: program.moduleNameFirstTag,
101
- disableStrictSSL: !!program.disableStrictSSL,
102
- disableProxy: !!program.disableProxy,
103
- singleHttpClient: !!program.singleHttpClient,
104
- cleanOutput: !!program.cleanOutput,
105
- silent: !!program.silent,
106
- typePrefix: program.typePrefix,
107
- typeSuffix: program.typeSuffix,
108
- patch: !!program.patch,
109
- apiClassName,
110
- }).catch((err) => {
111
- // NOTE collect all errors on top level and shows to users in any case
112
- console.error(err);
113
-
114
- process.exit(1);
115
- });
1
+ #!/usr/bin/env node
2
+
3
+ // Copyright (c) 2019-present acacode
4
+ // Node module: swagger-typescript-api
5
+ // This file is licensed under the MIT License.
6
+ // License text available at https://opensource.org/licenses/MIT
7
+ // Repository https://github.com/acacode/swagger-typescript-api
8
+
9
+ const { Command } = require("commander");
10
+ const { resolve } = require("path");
11
+ const { generateApi } = require("./src");
12
+ const { version, name: packageName } = require("./package.json");
13
+ const { TS_KEYWORDS, HTTP_CLIENT } = require("./src/constants");
14
+
15
+ const program = new Command(packageName);
16
+
17
+ const options = program
18
+ .alias("sta")
19
+ .version(version, "-v, --version", "output the current version")
20
+ .description("Generate api via swagger scheme.\nSupports OA 3.0, 2.0, JSON, yaml.")
21
+ .requiredOption("-p, --path <string>", "path/url to swagger scheme")
22
+ .option("-o, --output <string>", "output path of typescript api file", "./")
23
+ .option("-n, --name <string>", "name of output typescript api file", "Api.ts")
24
+ .option("-t, --templates <string>", "path to folder containing templates")
25
+ .option(
26
+ "-d, --default-as-success",
27
+ 'use "default" response status code as success response too.\n' +
28
+ 'some swagger schemas use "default" response status code as success response type by default.',
29
+ false,
30
+ )
31
+ .option(
32
+ "-r, --responses",
33
+ "generate additional information about request responses\n" + "also add typings for bad responses",
34
+ false,
35
+ )
36
+ .option("--union-enums", 'generate all "enum" types as union types (T1 | T2 | TN)', false)
37
+ .option("--add-readonly", "generate readonly properties", false)
38
+ .option("--route-types", "generate type definitions for API routes", false)
39
+ .option("--no-client", "do not generate an API class", true)
40
+ .option("--enum-names-as-values", "use values in 'x-enumNames' as enum values (not only as keys)", false)
41
+ .option(
42
+ "--extract-request-params",
43
+ "extract request params to data contract (Also combine path params and query params into one object)",
44
+ false,
45
+ )
46
+ .option("--extract-request-body", "extract request body type to data contract", false)
47
+ .option("--extract-response-body", "extract response body type to data contract", false)
48
+ .option("--extract-response-error", "extract response error type to data contract", false)
49
+ .option("--modular", "generate separated files for http client, data contracts, and routes", false)
50
+ .option("--js", "generate js api module with declaration file", false)
51
+ .option(
52
+ "--module-name-index <number>",
53
+ "determines which path index should be used for routes separation (example: GET:/fruites/getFruit -> index:0 -> moduleName -> fruites)",
54
+ 0,
55
+ )
56
+ .option("--module-name-first-tag", "splits routes based on the first tag", false)
57
+ .option("--disableStrictSSL", "disabled strict SSL", false)
58
+ .option("--disableProxy", "disabled proxy", false)
59
+ .option("--axios", "generate axios http client", false)
60
+ .option("--unwrap-response-data", "unwrap the data item from the response", false)
61
+ .option("--disable-throw-on-error", "Do not throw an error when response.ok is not true", false)
62
+ .option("--single-http-client", "Ability to send HttpClient instance to Api constructor", false)
63
+ .option("--silent", "Output only errors to console", false)
64
+ .option("--default-response <type>", "default type for empty response schema", TS_KEYWORDS.VOID)
65
+ .option("--type-prefix <string>", "data contract name prefix", "")
66
+ .option("--type-suffix <string>", "data contract name suffix", "")
67
+ .option("--clean-output", "clean output folder before generate api. WARNING: May cause data loss", false)
68
+ .option("--api-class-name <string>", "name of the api class")
69
+ .option("--patch", "fix up small errors in the swagger source definition", false)
70
+ .option("--debug", "additional information about processes inside this tool", false)
71
+ .parse(process.argv)
72
+ .opts();
73
+
74
+ generateApi({
75
+ name: options.name,
76
+ url: options.path,
77
+ generateRouteTypes: options.routeTypes,
78
+ generateClient: !!(options.axios || options.client),
79
+ httpClientType: options.axios ? HTTP_CLIENT.AXIOS : HTTP_CLIENT.FETCH,
80
+ defaultResponseAsSuccess: options.defaultAsSuccess,
81
+ defaultResponseType: options.defaultResponse,
82
+ unwrapResponseData: options.unwrapResponseData,
83
+ disableThrowOnError: options.disableThrowOnError,
84
+ sortTypes: options.sortTypes,
85
+ generateUnionEnums: options.unionEnums,
86
+ addReadonly: options.addReadonly,
87
+ generateResponses: options.responses,
88
+ extractRequestParams: !!options.extractRequestParams,
89
+ extractRequestBody: !!options.extractRequestBody,
90
+ extractResponseBody: !!options.extractResponseBody,
91
+ extractResponseError: !!options.extractResponseError,
92
+ input: resolve(process.cwd(), options.path),
93
+ output: resolve(process.cwd(), options.output || "."),
94
+ templates: options.templates,
95
+ modular: !!options.modular,
96
+ toJS: !!options.js,
97
+ enumNamesAsValues: options.enumNamesAsValues,
98
+ moduleNameIndex: +(options.moduleNameIndex || 0),
99
+ moduleNameFirstTag: options.moduleNameFirstTag,
100
+ disableStrictSSL: !!options.disableStrictSSL,
101
+ disableProxy: !!options.disableProxy,
102
+ singleHttpClient: !!options.singleHttpClient,
103
+ cleanOutput: !!options.cleanOutput,
104
+ silent: !!options.silent,
105
+ typePrefix: options.typePrefix,
106
+ typeSuffix: options.typeSuffix,
107
+ patch: !!options.patch,
108
+ apiClassName: options.apiClassName,
109
+ debug: options.debug,
110
+ }).catch((err) => {
111
+ // NOTE collect all errors on top level and shows to users in any case
112
+ console.error(err);
113
+
114
+ process.exit(1);
115
+ });
package/package.json CHANGED
@@ -1,113 +1,116 @@
1
- {
2
- "name": "swagger-typescript-api",
3
- "version": "10.0.0",
4
- "description": "Generate typescript/javascript api from swagger schema",
5
- "scripts": {
6
- "cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
7
- "cli:yaml": "node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",
8
- "node": "node swagger-test-cli/generate.js",
9
- "node:debug": "node --nolazy swagger-test-cli/generate.js",
10
- "contributors": "all-contributors generate",
11
- "cli:help": "node index.js -h",
12
- "test-all": "node --unhandled-rejections=strict ./scriptsRunner.js generate validate test:*",
13
- "test-all-extended": "node --unhandled-rejections=strict ./scriptsRunner.js generate-extended validate generate validate test:*",
14
- "test-specific": "node ./scriptsRunner.js generate validate test:*",
15
- "prepare": "npm run test-all-extended",
16
- "generate": "node tests/generate.js",
17
- "generate-extended": "node tests/generate-extended.js",
18
- "generate:debug": "node --nolazy tests/generate.js",
19
- "validate": "node tests/validate.js",
20
- "validate:debug": "node --nolazy tests/validate.js",
21
- "test:--route-types": "node tests/spec/routeTypes/test.js",
22
- "test:--no-client": "node tests/spec/noClient/test.js",
23
- "test:--default-as-success": "node tests/spec/defaultAsSuccess/test.js",
24
- "test:--templates": "node tests/spec/templates/test.js",
25
- "test:--union-enums": "node tests/spec/unionEnums/test.js",
26
- "test:--add-readonly": "node tests/spec/readonly/test.js",
27
- "test:--responses": "node tests/spec/responses/test.js",
28
- "test:specProperty": "node tests/spec/specProperty/test.js",
29
- "test:--module-name-index": "node tests/spec/moduleNameIndex/test.js",
30
- "test:--module-name-first-tag": "node tests/spec/moduleNameFirstTag/test.js",
31
- "test:--modular": "node tests/spec/modular/test.js",
32
- "test:--single-http-client": "node tests/spec/singleHttpClient/test.js",
33
- "test:--extract-request-params": "node tests/spec/extractRequestParams/test.js",
34
- "test:--extract-request-body": "node tests/spec/extractRequestBody/test.js",
35
- "test:--extract-response-body": "node tests/spec/extractResponseBody/test.js",
36
- "test:--extract-response-error": "node tests/spec/extractResponseError/test.js",
37
- "test:--enum-names-as-values": "node tests/spec/enumNamesAsValues/test.js",
38
- "test:--default-response": "node tests/spec/defaultResponse/test.js",
39
- "test:--js": "node tests/spec/js/test.js",
40
- "test:--js--axios": "node tests/spec/jsAxios/test.js",
41
- "test:--axios": "node tests/spec/axios/test.js",
42
- "test:--axios--single-http-client": "node tests/spec/axiosSingleHttpClient/test.js",
43
- "test:--type-suffix--type-prefix": "node tests/spec/typeSuffixPrefix/test.js",
44
- "test:partialBaseTemplate": "node tests/spec/partialBaseTemplate/test.js",
45
- "test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js",
46
- "test:--patch": "node tests/spec/patch/test.js"
47
- },
48
- "author": "acacode",
49
- "license": "MIT",
50
- "typings": "./index.d.ts",
51
- "main": "src/index.js",
52
- "devDependencies": {
53
- "@types/axios": "^0.14.0",
54
- "@types/lodash": "^4.14.182",
55
- "@types/node": "^15.0.2",
56
- "@types/prettier": "^2.7.0",
57
- "all-contributors-cli": "^6.20.0",
58
- "husky": "^4.3.6",
59
- "pretty-quick": "^3.1.0"
60
- },
61
- "dependencies": {
62
- "axios": "^0.27.2",
63
- "@types/swagger-schema-official": "2.0.22",
64
- "commander": "^9.4.0",
65
- "cosmiconfig": "^7.0.1",
66
- "eta": "^1.12.3",
67
- "js-yaml": "^4.1.0",
68
- "lodash": "^4.17.21",
69
- "make-dir": "^3.1.0",
70
- "nanoid": "^3.3.4",
71
- "node-emoji": "^1.11.0",
72
- "prettier": "^2.7.1",
73
- "swagger-schema-official": "2.0.0-bab6bed",
74
- "swagger2openapi": "^7.0.8",
75
- "typescript": "^4.7.4"
76
- },
77
- "bin": {
78
- "swagger-typescript-api": "index.js",
79
- "sta": "index.js"
80
- },
81
- "husky": {
82
- "hooks": {
83
- "pre-commit": "pretty-quick --staged",
84
- "post-commit": "git update-index -g"
85
- }
86
- },
87
- "keywords": [
88
- "openapi",
89
- "swagger",
90
- "typescript",
91
- "api",
92
- "javascript",
93
- "rest",
94
- "codegen",
95
- "generation",
96
- "http"
97
- ],
98
- "files": [
99
- "src",
100
- "index.js",
101
- "index.d.ts",
102
- "templates",
103
- "LICENSE"
104
- ],
105
- "bugs": {
106
- "url": "https://github.com/acacode/swagger-typescript-api/issues"
107
- },
108
- "homepage": "https://github.com/acacode/swagger-typescript-api",
109
- "repository": {
110
- "type": "git",
111
- "url": "git://github.com/acacode/swagger-typescript-api"
112
- }
113
- }
1
+ {
2
+ "name": "swagger-typescript-api",
3
+ "version": "10.0.2",
4
+ "description": "Generate typescript/javascript api from swagger schema",
5
+ "scripts": {
6
+ "cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
7
+ "cli:yaml": "node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",
8
+ "node": "node swagger-test-cli/generate.js",
9
+ "node:debug": "node --nolazy swagger-test-cli/generate.js",
10
+ "contributors": "all-contributors generate",
11
+ "cli:help": "node index.js -h",
12
+ "test-all": "node --unhandled-rejections=strict ./scriptsRunner.js generate validate test:*",
13
+ "test-all-extended": "node --unhandled-rejections=strict ./scriptsRunner.js generate-extended validate generate validate test:*",
14
+ "test-specific": "node ./scriptsRunner.js generate validate test:*",
15
+ "prepare": "npm run test-all-extended",
16
+ "generate": "node tests/generate.js",
17
+ "generate-extended": "node tests/generate-extended.js",
18
+ "generate:debug": "node --nolazy tests/generate.js",
19
+ "validate": "node tests/validate.js",
20
+ "validate:debug": "node --nolazy tests/validate.js",
21
+ "test:--route-types": "node tests/spec/routeTypes/test.js",
22
+ "test:--no-client": "node tests/spec/noClient/test.js",
23
+ "test:--default-as-success": "node tests/spec/defaultAsSuccess/test.js",
24
+ "test:--templates": "node tests/spec/templates/test.js",
25
+ "test:--union-enums": "node tests/spec/unionEnums/test.js",
26
+ "test:--add-readonly": "node tests/spec/readonly/test.js",
27
+ "test:--responses": "node tests/spec/responses/test.js",
28
+ "test:specProperty": "node tests/spec/specProperty/test.js",
29
+ "test:--module-name-index": "node tests/spec/moduleNameIndex/test.js",
30
+ "test:--module-name-first-tag": "node tests/spec/moduleNameFirstTag/test.js",
31
+ "test:--modular": "node tests/spec/modular/test.js",
32
+ "test:--single-http-client": "node tests/spec/singleHttpClient/test.js",
33
+ "test:--extract-request-params": "node tests/spec/extractRequestParams/test.js",
34
+ "test:--extract-request-body": "node tests/spec/extractRequestBody/test.js",
35
+ "test:--extract-response-body": "node tests/spec/extractResponseBody/test.js",
36
+ "test:--extract-response-error": "node tests/spec/extractResponseError/test.js",
37
+ "test:--enum-names-as-values": "node tests/spec/enumNamesAsValues/test.js",
38
+ "test:--default-response": "node tests/spec/defaultResponse/test.js",
39
+ "test:--js": "node tests/spec/js/test.js",
40
+ "test:--js--axios": "node tests/spec/jsAxios/test.js",
41
+ "test:--axios": "node tests/spec/axios/test.js",
42
+ "test:--object-types": "node tests/spec/object-types/test.js",
43
+ "test:--axios--single-http-client": "node tests/spec/axiosSingleHttpClient/test.js",
44
+ "test:--type-suffix--type-prefix": "node tests/spec/typeSuffixPrefix/test.js",
45
+ "test:--cli": "node index.js -p tests/spec/cli/schema.json -o tests/spec/cli -n schema.ts --extract-response-body --extract-response-error --type-prefix Prefix --api-class-name MySuperApi --no-client",
46
+ "test:partialBaseTemplate": "node tests/spec/partialBaseTemplate/test.js",
47
+ "test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js",
48
+ "test:--patch": "node tests/spec/patch/test.js"
49
+ },
50
+ "author": "acacode",
51
+ "license": "MIT",
52
+ "typings": "./index.d.ts",
53
+ "main": "src/index.js",
54
+ "devDependencies": {
55
+ "@types/axios": "^0.14.0",
56
+ "@types/lodash": "^4.14.182",
57
+ "@types/node": "^15.0.2",
58
+ "@types/prettier": "^2.7.0",
59
+ "all-contributors-cli": "^6.20.0",
60
+ "git-diff": "^2.0.6",
61
+ "husky": "^4.3.6",
62
+ "pretty-quick": "^3.1.0"
63
+ },
64
+ "dependencies": {
65
+ "@types/swagger-schema-official": "2.0.22",
66
+ "axios": "0.27.2",
67
+ "commander": "9.4.1",
68
+ "cosmiconfig": "7.0.1",
69
+ "eta": "1.12.3",
70
+ "js-yaml": "4.1.0",
71
+ "lodash": "4.17.21",
72
+ "make-dir": "3.1.0",
73
+ "nanoid": "3.3.4",
74
+ "node-emoji": "1.11.0",
75
+ "prettier": "2.7.1",
76
+ "swagger-schema-official": "2.0.0-bab6bed",
77
+ "swagger2openapi": "7.0.8",
78
+ "typescript": "4.8.4"
79
+ },
80
+ "bin": {
81
+ "swagger-typescript-api": "index.js",
82
+ "sta": "index.js"
83
+ },
84
+ "husky": {
85
+ "hooks": {
86
+ "pre-commit": "pretty-quick --staged",
87
+ "post-commit": "git update-index -g"
88
+ }
89
+ },
90
+ "keywords": [
91
+ "openapi",
92
+ "swagger",
93
+ "typescript",
94
+ "api",
95
+ "javascript",
96
+ "rest",
97
+ "codegen",
98
+ "generation",
99
+ "http"
100
+ ],
101
+ "files": [
102
+ "src",
103
+ "index.js",
104
+ "index.d.ts",
105
+ "templates",
106
+ "LICENSE"
107
+ ],
108
+ "bugs": {
109
+ "url": "https://github.com/acacode/swagger-typescript-api/issues"
110
+ },
111
+ "homepage": "https://github.com/acacode/swagger-typescript-api",
112
+ "repository": {
113
+ "type": "git",
114
+ "url": "git://github.com/acacode/swagger-typescript-api"
115
+ }
116
+ }
package/src/apiConfig.js CHANGED
@@ -1,30 +1,30 @@
1
- const _ = require("lodash");
2
-
3
- const createApiConfig = (swaggerSchema) => {
4
- const { info, servers, host, basePath, externalDocs, tags } = swaggerSchema;
5
- const server = (servers && servers[0]) || { url: "" };
6
- const { title = "No title", version, description: schemaDescription = "" } = info || {};
7
- const { url: serverUrl } = server;
8
-
9
- return {
10
- info: info || {},
11
- servers: servers || [],
12
- basePath,
13
- host,
14
- externalDocs: _.merge(
15
- {
16
- url: "",
17
- description: "",
18
- },
19
- externalDocs,
20
- ),
21
- tags: _.compact(tags),
22
- baseUrl: serverUrl,
23
- title,
24
- version,
25
- };
26
- };
27
-
28
- module.exports = {
29
- createApiConfig,
30
- };
1
+ const _ = require("lodash");
2
+
3
+ const createApiConfig = (swaggerSchema) => {
4
+ const { info, servers, host, basePath, externalDocs, tags } = swaggerSchema;
5
+ const server = (servers && servers[0]) || { url: "" };
6
+ const { title = "No title", version, description: schemaDescription = "" } = info || {};
7
+ const { url: serverUrl } = server;
8
+
9
+ return {
10
+ info: info || {},
11
+ servers: servers || [],
12
+ basePath,
13
+ host,
14
+ externalDocs: _.merge(
15
+ {
16
+ url: "",
17
+ description: "",
18
+ },
19
+ externalDocs,
20
+ ),
21
+ tags: _.compact(tags),
22
+ baseUrl: serverUrl,
23
+ title,
24
+ version,
25
+ };
26
+ };
27
+
28
+ module.exports = {
29
+ createApiConfig,
30
+ };
package/src/common.js CHANGED
@@ -1,28 +1,28 @@
1
- const _ = require("lodash");
2
-
3
- module.exports = {
4
- formatDescription: (description, inline) => {
5
- if (!description) return "";
6
-
7
- let prettified = description;
8
-
9
- prettified = _.replace(prettified, /\*\//g, "*/");
10
-
11
- const hasMultipleLines = _.includes(prettified, "\n");
12
-
13
- if (!hasMultipleLines) return prettified;
14
-
15
- if (inline) {
16
- return _(prettified)
17
- .split(/\n/g)
18
- .map((part) => _.trim(part))
19
- .compact()
20
- .join(" ")
21
- .valueOf();
22
- }
23
-
24
- return _.replace(prettified, /\n$/g, "");
25
- },
26
- internalCase: (value) => _.camelCase(_.lowerCase(value)),
27
- classNameCase: (value) => _.upperFirst(_.camelCase(value)),
28
- };
1
+ const _ = require("lodash");
2
+
3
+ module.exports = {
4
+ formatDescription: (description, inline) => {
5
+ if (!description) return "";
6
+
7
+ let prettified = description;
8
+
9
+ prettified = _.replace(prettified, /\*\//g, "*/");
10
+
11
+ const hasMultipleLines = _.includes(prettified, "\n");
12
+
13
+ if (!hasMultipleLines) return prettified;
14
+
15
+ if (inline) {
16
+ return _(prettified)
17
+ .split(/\n/g)
18
+ .map((part) => _.trim(part))
19
+ .compact()
20
+ .join(" ")
21
+ .valueOf();
22
+ }
23
+
24
+ return _.replace(prettified, /\n$/g, "");
25
+ },
26
+ internalCase: (value) => _.camelCase(_.lowerCase(value)),
27
+ classNameCase: (value) => _.upperFirst(_.camelCase(value)),
28
+ };