swagger-typescript-api 13.0.2 → 13.0.4
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/README.md +310 -369
- package/cli/constants.js +3 -3
- package/cli/execute.js +12 -12
- package/cli/index.js +16 -16
- package/cli/operations/display-help.js +25 -25
- package/cli/parse-args.js +3 -3
- package/cli/process-option.js +11 -11
- package/index.d.ts +140 -45
- package/index.js +110 -111
- package/package.json +93 -108
- package/src/code-formatter.js +6 -6
- package/src/code-gen-process.js +45 -45
- package/src/commands/generate-templates/configuration.js +2 -2
- package/src/commands/generate-templates/index.js +1 -1
- package/src/commands/generate-templates/templates-gen-process.js +21 -21
- package/src/component-type-name-resolver.js +4 -4
- package/src/configuration.js +107 -107
- package/src/constants.js +26 -26
- package/src/index.js +3 -3
- package/src/schema-components-map.js +3 -3
- package/src/schema-parser/base-schema-parsers/array.js +3 -3
- package/src/schema-parser/base-schema-parsers/complex.js +5 -5
- package/src/schema-parser/base-schema-parsers/discriminator.js +16 -13
- package/src/schema-parser/base-schema-parsers/enum.js +12 -12
- package/src/schema-parser/base-schema-parsers/object.js +8 -8
- package/src/schema-parser/base-schema-parsers/primitive.js +3 -3
- package/src/schema-parser/complex-schema-parsers/all-of.js +2 -2
- package/src/schema-parser/complex-schema-parsers/any-of.js +2 -2
- package/src/schema-parser/complex-schema-parsers/not.js +1 -1
- package/src/schema-parser/complex-schema-parsers/one-of.js +2 -2
- package/src/schema-parser/mono-schema-parser.js +1 -1
- package/src/schema-parser/schema-formatters.js +14 -14
- package/src/schema-parser/schema-parser-fabric.js +5 -5
- package/src/schema-parser/schema-parser.js +24 -24
- package/src/schema-parser/schema-utils.js +21 -21
- package/src/schema-parser/util/enum-key-resolver.js +2 -2
- package/src/schema-routes/schema-routes.js +68 -68
- package/src/schema-routes/util/specific-arg-name-resolver.js +2 -2
- package/src/schema-walker.js +7 -7
- package/src/swagger-schema-resolver.js +16 -16
- package/src/templates-worker.js +21 -18
- package/src/translators/javascript.js +7 -7
- package/src/translators/translator.js +1 -1
- package/src/type-name-formatter.js +16 -16
- package/src/util/file-system.js +13 -14
- package/src/util/id.js +2 -2
- package/src/util/internal-case.js +1 -1
- package/src/util/logger.js +27 -27
- package/src/util/name-resolver.js +5 -5
- package/src/util/object-assign.js +2 -2
- package/src/util/pascal-case.js +1 -1
- package/src/util/request.js +15 -10
- package/templates/README.md +15 -14
- package/templates/base/README.md +4 -5
- package/templates/base/http-clients/fetch-http-client.ejs +1 -1
- package/templates/base/route-name.ejs +4 -4
- package/templates/default/README.md +4 -4
- package/templates/modular/README.md +4 -4
package/package.json
CHANGED
|
@@ -1,138 +1,123 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swagger-typescript-api",
|
|
3
|
-
"version": "13.0.
|
|
4
|
-
"description": "Generate
|
|
3
|
+
"version": "13.0.4",
|
|
4
|
+
"description": "Generate TypeScript/JavaScript API from Swagger schema",
|
|
5
|
+
"homepage": "https://github.com/acacode/swagger-typescript-api",
|
|
6
|
+
"bugs": "https://github.com/acacode/swagger-typescript-api/issues",
|
|
7
|
+
"repository": "github:acacode/swagger-typescript-api",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": "Sergey Volkov <js2me@outlook.com>",
|
|
10
|
+
"contributors": [
|
|
11
|
+
"Sora Morimoto <sora@morimoto.io>"
|
|
12
|
+
],
|
|
13
|
+
"main": "./src/index.js",
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"bin": {
|
|
16
|
+
"sta": "./index.js",
|
|
17
|
+
"swagger-typescript-api": "./index.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"cli",
|
|
21
|
+
"src",
|
|
22
|
+
"templates",
|
|
23
|
+
"index.d.ts",
|
|
24
|
+
"index.js"
|
|
25
|
+
],
|
|
5
26
|
"scripts": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"lint:fix": "eslint . --fix",
|
|
27
|
+
"ci": "biome ci .",
|
|
28
|
+
"cli:help": "node index.js -h",
|
|
9
29
|
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
|
|
10
30
|
"cli:yaml": "node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",
|
|
31
|
+
"format": "biome format --write .",
|
|
32
|
+
"format:check": "biome format .",
|
|
33
|
+
"generate": "node tests/generate.js",
|
|
34
|
+
"generate-extended": "node tests/generate-extended.js",
|
|
11
35
|
"node": "node swagger-test-cli/generate.js",
|
|
12
36
|
"node:debug": "node --nolazy swagger-test-cli/generate.js",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"test-all": "npm run test-extended && npm run test-simple && npm run test-specific",
|
|
16
|
-
"test-all(update-snapshots)": "cross-env UPDATE_SNAPSHOTS=true npm run test-all",
|
|
17
|
-
"test-simple": "node --unhandled-rejections=strict scripts_runner.js generate validate",
|
|
37
|
+
"test-all": "yarn test-extended && yarn test-simple && yarn test-specific",
|
|
38
|
+
"test-all(update-snapshots)": "cross-env UPDATE_SNAPSHOTS=true yarn test-all",
|
|
18
39
|
"test-extended": "node --unhandled-rejections=strict scripts_runner.js generate-extended validate",
|
|
19
|
-
"test-
|
|
20
|
-
"test-specific
|
|
21
|
-
"
|
|
22
|
-
"generate-extended": "node tests/generate-extended.js",
|
|
23
|
-
"validate": "node tests/validate.js",
|
|
24
|
-
"validate:debug": "node --nolazy tests/validate.js",
|
|
25
|
-
"test:--route-types": "node tests/spec/routeTypes/test.js",
|
|
26
|
-
"test:--no-client": "node tests/spec/noClient/test.js",
|
|
27
|
-
"test:--default-as-success": "node tests/spec/defaultAsSuccess/test.js",
|
|
28
|
-
"test:--templates": "node tests/spec/templates/test.js",
|
|
29
|
-
"test:--union-enums": "node tests/spec/unionEnums/test.js",
|
|
40
|
+
"test-simple": "node --unhandled-rejections=strict scripts_runner.js generate validate",
|
|
41
|
+
"test-specific": "node --unhandled-rejections=strict scripts_runner.js \"test:*\"",
|
|
42
|
+
"test-specific(update-snapshots)": "cross-env UPDATE_SNAPSHOTS=true node --unhandled-rejections=strict scripts_runner.js \"test:*\"",
|
|
30
43
|
"test:--add-readonly": "node tests/spec/readonly/test.js",
|
|
31
|
-
"test:--
|
|
32
|
-
"test
|
|
33
|
-
"test:--
|
|
34
|
-
"test:--
|
|
35
|
-
"test:--
|
|
36
|
-
"test:--
|
|
37
|
-
"test:--
|
|
44
|
+
"test:--another-array-type": "node tests/spec/another-array-type/test.js",
|
|
45
|
+
"test:--axios": "node tests/spec/axios/test.js",
|
|
46
|
+
"test:--axios--single-http-client": "node tests/spec/axiosSingleHttpClient/test.js",
|
|
47
|
+
"test:--cli": "shx rm -rf tests/spec/cli/schema.ts && 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",
|
|
48
|
+
"test:--default-as-success": "node tests/spec/defaultAsSuccess/test.js",
|
|
49
|
+
"test:--default-response": "node tests/spec/defaultResponse/test.js",
|
|
50
|
+
"test:--dot-path-params": "node tests/spec/dot-path-params/test.js",
|
|
51
|
+
"test:--enum-names-as-values": "node tests/spec/enumNamesAsValues/test.js",
|
|
38
52
|
"test:--extract-request-body": "node tests/spec/extractRequestBody/test.js",
|
|
53
|
+
"test:--extract-request-params": "node tests/spec/extractRequestParams/test.js",
|
|
39
54
|
"test:--extract-response-body": "node tests/spec/extractResponseBody/test.js",
|
|
40
55
|
"test:--extract-response-error": "node tests/spec/extractResponseError/test.js",
|
|
41
|
-
"test:--enum-names-as-values": "node tests/spec/enumNamesAsValues/test.js",
|
|
42
|
-
"test:--default-response": "node tests/spec/defaultResponse/test.js",
|
|
43
|
-
"test:const-keyword": "node tests/spec/const-keyword/test.js",
|
|
44
56
|
"test:--js": "node tests/spec/js/test.js",
|
|
45
|
-
"test:jsSingleHttpClientModular": "node tests/spec/jsSingleHttpClientModular/test.js",
|
|
46
57
|
"test:--js--axios": "node tests/spec/jsAxios/test.js",
|
|
47
|
-
"test:--
|
|
48
|
-
"test:--
|
|
58
|
+
"test:--modular": "node tests/spec/modular/test.js",
|
|
59
|
+
"test:--module-name-first-tag": "node tests/spec/moduleNameFirstTag/test.js",
|
|
60
|
+
"test:--module-name-index": "node tests/spec/moduleNameIndex/test.js",
|
|
61
|
+
"test:--no-client": "node tests/spec/noClient/test.js",
|
|
49
62
|
"test:--object-types": "node tests/spec/object-types/test.js",
|
|
50
|
-
"test:--axios--single-http-client": "node tests/spec/axiosSingleHttpClient/test.js",
|
|
51
|
-
"test:--type-suffix--type-prefix": "node tests/spec/typeSuffixPrefix/test.js",
|
|
52
|
-
"test:--dot-path-params": "node tests/spec/dot-path-params/test.js",
|
|
53
|
-
"test:--primitive-type-constructs": "node tests/spec/primitive-type-constructs/test.js",
|
|
54
|
-
"test:--cli": "rimraf tests/spec/cli/schema.ts && 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",
|
|
55
|
-
"test:partialBaseTemplate": "node tests/spec/partialBaseTemplate/test.js",
|
|
56
|
-
"test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js",
|
|
57
63
|
"test:--patch": "node tests/spec/patch/test.js",
|
|
58
|
-
"test
|
|
59
|
-
"test
|
|
60
|
-
"test
|
|
64
|
+
"test:--primitive-type-constructs": "node tests/spec/primitive-type-constructs/test.js",
|
|
65
|
+
"test:--responses": "node tests/spec/responses/test.js",
|
|
66
|
+
"test:--route-types": "node tests/spec/routeTypes/test.js",
|
|
67
|
+
"test:--single-http-client": "node tests/spec/singleHttpClient/test.js",
|
|
68
|
+
"test:--templates": "node tests/spec/templates/test.js",
|
|
69
|
+
"test:--type-suffix--type-prefix": "node tests/spec/typeSuffixPrefix/test.js",
|
|
70
|
+
"test:--union-enums": "node tests/spec/unionEnums/test.js",
|
|
61
71
|
"test:additionalProperties2.0": "node tests/spec/additional-properties-2.0/test.js",
|
|
62
|
-
"test:enums2.0": "node tests/spec/enums-2.0/test.js",
|
|
63
72
|
"test:another-query-params": "node tests/spec/another-query-params/test.js",
|
|
64
|
-
"test:
|
|
73
|
+
"test:const-keyword": "node tests/spec/const-keyword/test.js",
|
|
74
|
+
"test:deprecated": "node tests/spec/deprecated/test.js",
|
|
75
|
+
"test:discriminator": "node tests/spec/discriminator/test.js",
|
|
76
|
+
"test:enums2.0": "node tests/spec/enums-2.0/test.js",
|
|
65
77
|
"test:extra-templates": "node tests/spec/extra-templates/test.js",
|
|
66
78
|
"test:extract-enums": "node tests/spec/extract-enums/test.js",
|
|
67
|
-
"test:
|
|
79
|
+
"test:jsSingleHttpClientModular": "node tests/spec/jsSingleHttpClientModular/test.js",
|
|
80
|
+
"test:nullableRefTest2.0": "node tests/spec/nullable-2.0/test.js",
|
|
81
|
+
"test:nullableRefTest3.0": "node tests/spec/nullable-3.0/test.js",
|
|
82
|
+
"test:on-insert-path-param": "node tests/spec/on-insert-path-param/test.js",
|
|
83
|
+
"test:partialBaseTemplate": "node tests/spec/partialBaseTemplate/test.js",
|
|
84
|
+
"test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js",
|
|
68
85
|
"test:sort-types": "node tests/spec/sortTypes/test.js",
|
|
69
|
-
"test:sort-types-false": "node tests/spec/sortTypes-false/test.js"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"typings": "./index.d.ts",
|
|
74
|
-
"main": "src/index.js",
|
|
75
|
-
"devDependencies": {
|
|
76
|
-
"eslint": "^8.44.0",
|
|
77
|
-
"eslint-config-prettier": "^8.8.0",
|
|
78
|
-
"eslint-plugin-prettier": "^5.0.0",
|
|
79
|
-
"@types/lodash": "^4.14.195",
|
|
80
|
-
"@types/node": "^20.4.1",
|
|
81
|
-
"@types/prettier": "^2.7.3",
|
|
82
|
-
"all-contributors-cli": "^6.26.1",
|
|
83
|
-
"axios": "^1.4.0",
|
|
84
|
-
"cross-env": "^7.0.3",
|
|
85
|
-
"dotenv": "^16.3.1",
|
|
86
|
-
"git-diff": "^2.0.6",
|
|
87
|
-
"husky": "^8.0.3",
|
|
88
|
-
"pretty-quick": "^3.1.3",
|
|
89
|
-
"rimraf": "^5.0.1"
|
|
86
|
+
"test:sort-types-false": "node tests/spec/sortTypes-false/test.js",
|
|
87
|
+
"test:specProperty": "node tests/spec/specProperty/test.js",
|
|
88
|
+
"validate": "node tests/validate.js",
|
|
89
|
+
"validate:debug": "node --nolazy tests/validate.js"
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"@types/swagger-schema-official": "2.0.
|
|
93
|
-
"cosmiconfig": "
|
|
92
|
+
"@types/swagger-schema-official": "^2.0.25",
|
|
93
|
+
"cosmiconfig": "^9.0.0",
|
|
94
94
|
"didyoumean": "^1.2.2",
|
|
95
95
|
"eta": "^2.2.0",
|
|
96
|
-
"js-yaml": "4.1.0",
|
|
97
|
-
"lodash": "4.17.21",
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"node-fetch": "^3.3.1",
|
|
102
|
-
"prettier": "3.0.0",
|
|
96
|
+
"js-yaml": "^4.1.0",
|
|
97
|
+
"lodash": "^4.17.21",
|
|
98
|
+
"nanoid": "^3.3.7",
|
|
99
|
+
"node-emoji": "^2.1.3",
|
|
100
|
+
"prettier": "3.3.0",
|
|
103
101
|
"swagger-schema-official": "2.0.0-bab6bed",
|
|
104
|
-
"swagger2openapi": "7.0.8",
|
|
105
|
-
"typescript": "5.
|
|
102
|
+
"swagger2openapi": "^7.0.8",
|
|
103
|
+
"typescript": "5.4.5"
|
|
106
104
|
},
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
105
|
+
"devDependencies": {
|
|
106
|
+
"@biomejs/biome": "1.7.3",
|
|
107
|
+
"@types/lodash": "4.17.4",
|
|
108
|
+
"@types/node": "20.13.0",
|
|
109
|
+
"axios": "1.7.2",
|
|
110
|
+
"cross-env": "7.0.3",
|
|
111
|
+
"dotenv": "16.4.5",
|
|
112
|
+
"git-diff": "2.0.6",
|
|
113
|
+
"shx": "0.3.4"
|
|
110
114
|
},
|
|
111
|
-
"
|
|
112
|
-
|
|
113
|
-
"
|
|
114
|
-
"typescript",
|
|
115
|
-
"api",
|
|
116
|
-
"javascript",
|
|
117
|
-
"rest",
|
|
118
|
-
"codegen",
|
|
119
|
-
"generation",
|
|
120
|
-
"http"
|
|
121
|
-
],
|
|
122
|
-
"files": [
|
|
123
|
-
"src",
|
|
124
|
-
"index.js",
|
|
125
|
-
"index.d.ts",
|
|
126
|
-
"templates",
|
|
127
|
-
"cli",
|
|
128
|
-
"LICENSE"
|
|
129
|
-
],
|
|
130
|
-
"bugs": {
|
|
131
|
-
"url": "https://github.com/acacode/swagger-typescript-api/issues"
|
|
115
|
+
"packageManager": "yarn@4.2.2",
|
|
116
|
+
"engines": {
|
|
117
|
+
"node": ">=18.0.0"
|
|
132
118
|
},
|
|
133
|
-
"
|
|
134
|
-
|
|
135
|
-
"
|
|
136
|
-
"url": "git://github.com/acacode/swagger-typescript-api"
|
|
119
|
+
"publishConfig": {
|
|
120
|
+
"access": "public",
|
|
121
|
+
"registry": "https://registry.npmjs.org"
|
|
137
122
|
}
|
|
138
|
-
}
|
|
123
|
+
}
|
package/src/code-formatter.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const _ = require(
|
|
2
|
-
const ts = require(
|
|
3
|
-
const prettier = require(
|
|
1
|
+
const _ = require("lodash");
|
|
2
|
+
const ts = require("typescript");
|
|
3
|
+
const prettier = require("prettier");
|
|
4
4
|
|
|
5
5
|
class CodeFormatter {
|
|
6
6
|
/**
|
|
@@ -13,13 +13,13 @@ class CodeFormatter {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
removeUnusedImports = (content) => {
|
|
16
|
-
const tempFileName =
|
|
16
|
+
const tempFileName = "file.ts";
|
|
17
17
|
|
|
18
18
|
const host = new TsLanguageServiceHost(tempFileName, content);
|
|
19
19
|
const languageService = ts.createLanguageService(host);
|
|
20
20
|
|
|
21
21
|
const fileTextChanges = languageService.organizeImports(
|
|
22
|
-
{ type:
|
|
22
|
+
{ type: "file", fileName: tempFileName },
|
|
23
23
|
{ newLineCharacter: ts.sys.newLine },
|
|
24
24
|
)[0];
|
|
25
25
|
|
|
@@ -79,7 +79,7 @@ class TsLanguageServiceHost {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
getNewLine() {
|
|
82
|
-
return
|
|
82
|
+
return "newLine" in ts.sys ? ts.sys.newLine : "\n";
|
|
83
83
|
}
|
|
84
84
|
getScriptFileNames() {
|
|
85
85
|
return [this.fileName];
|
package/src/code-gen-process.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
const { SwaggerSchemaResolver } = require(
|
|
2
|
-
const { SchemaComponentsMap } = require(
|
|
3
|
-
const { NameResolver } = require(
|
|
4
|
-
const { Logger } = require(
|
|
5
|
-
const { TypeNameFormatter } = require(
|
|
6
|
-
const _ = require(
|
|
7
|
-
const { SchemaParserFabric } = require(
|
|
8
|
-
const { SchemaRoutes } = require(
|
|
9
|
-
const { CodeGenConfig } = require(
|
|
10
|
-
const { SchemaWalker } = require(
|
|
11
|
-
const { FileSystem } = require(
|
|
12
|
-
const { TemplatesWorker } = require(
|
|
13
|
-
const { JavascriptTranslator } = require(
|
|
14
|
-
const ts = require(
|
|
15
|
-
const { CodeFormatter } = require(
|
|
16
|
-
const { pascalCase } = require(
|
|
17
|
-
const { internalCase } = require(
|
|
18
|
-
const { sortByProperty } = require(
|
|
1
|
+
const { SwaggerSchemaResolver } = require("./swagger-schema-resolver.js");
|
|
2
|
+
const { SchemaComponentsMap } = require("./schema-components-map.js");
|
|
3
|
+
const { NameResolver } = require("./util/name-resolver");
|
|
4
|
+
const { Logger } = require("./util/logger.js");
|
|
5
|
+
const { TypeNameFormatter } = require("./type-name-formatter.js");
|
|
6
|
+
const _ = require("lodash");
|
|
7
|
+
const { SchemaParserFabric } = require("./schema-parser/schema-parser-fabric");
|
|
8
|
+
const { SchemaRoutes } = require("./schema-routes/schema-routes.js");
|
|
9
|
+
const { CodeGenConfig } = require("./configuration.js");
|
|
10
|
+
const { SchemaWalker } = require("./schema-walker");
|
|
11
|
+
const { FileSystem } = require("./util/file-system");
|
|
12
|
+
const { TemplatesWorker } = require("./templates-worker");
|
|
13
|
+
const { JavascriptTranslator } = require("./translators/javascript");
|
|
14
|
+
const ts = require("typescript");
|
|
15
|
+
const { CodeFormatter } = require("./code-formatter");
|
|
16
|
+
const { pascalCase } = require("./util/pascal-case");
|
|
17
|
+
const { internalCase } = require("./util/internal-case");
|
|
18
|
+
const { sortByProperty } = require("./util/sort-by-property");
|
|
19
19
|
|
|
20
20
|
const PATCHABLE_INSTANCES = [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
"schemaWalker",
|
|
22
|
+
"swaggerSchemaResolver",
|
|
23
|
+
"schemaComponentsMap",
|
|
24
|
+
"typeNameFormatter",
|
|
25
|
+
"templatesWorker",
|
|
26
|
+
"codeFormatter",
|
|
27
|
+
"schemaParserFabric",
|
|
28
|
+
"schemaRoutes",
|
|
29
|
+
"javascriptTranslator",
|
|
30
30
|
];
|
|
31
31
|
|
|
32
32
|
class CodeGenProcess {
|
|
@@ -92,10 +92,10 @@ class CodeGenProcess {
|
|
|
92
92
|
originalSchema: swagger.originalSchema,
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
this.schemaWalker.addSchema(
|
|
96
|
-
this.schemaWalker.addSchema(
|
|
95
|
+
this.schemaWalker.addSchema("$usage", swagger.usageSchema);
|
|
96
|
+
this.schemaWalker.addSchema("$original", swagger.originalSchema);
|
|
97
97
|
|
|
98
|
-
this.logger.event(
|
|
98
|
+
this.logger.event("start generating your typescript api");
|
|
99
99
|
|
|
100
100
|
this.config.update(
|
|
101
101
|
this.config.hooks.onInit(this.config, this) || this.config,
|
|
@@ -107,7 +107,7 @@ class CodeGenProcess {
|
|
|
107
107
|
_.each(component, (rawTypeData, typeName) => {
|
|
108
108
|
this.schemaComponentsMap.createComponent(
|
|
109
109
|
this.schemaComponentsMap.createRef([
|
|
110
|
-
|
|
110
|
+
"components",
|
|
111
111
|
componentName,
|
|
112
112
|
typeName,
|
|
113
113
|
]),
|
|
@@ -120,7 +120,7 @@ class CodeGenProcess {
|
|
|
120
120
|
* @type {SchemaComponent[]}
|
|
121
121
|
*/
|
|
122
122
|
const componentsToParse = this.schemaComponentsMap.filter(
|
|
123
|
-
_.compact([
|
|
123
|
+
_.compact(["schemas", this.config.extractResponses && "responses"]),
|
|
124
124
|
);
|
|
125
125
|
|
|
126
126
|
const parsedSchemas = componentsToParse.map((schemaComponent) => {
|
|
@@ -186,7 +186,7 @@ class CodeGenProcess {
|
|
|
186
186
|
});
|
|
187
187
|
|
|
188
188
|
this.logger.success(
|
|
189
|
-
|
|
189
|
+
"api file",
|
|
190
190
|
`"${file.fileName}${file.fileExtension}"`,
|
|
191
191
|
`created in ${this.config.output}`,
|
|
192
192
|
);
|
|
@@ -225,7 +225,7 @@ class CodeGenProcess {
|
|
|
225
225
|
formatters: this.schemaParserFabric.schemaFormatters.base,
|
|
226
226
|
formatModelName: this.typeNameFormatter.format,
|
|
227
227
|
fmtToJSDocLine: function fmtToJSDocLine(line, { eol = true }) {
|
|
228
|
-
return ` * ${line}${eol ?
|
|
228
|
+
return ` * ${line}${eol ? "\n" : ""}`;
|
|
229
229
|
},
|
|
230
230
|
NameResolver: NameResolver,
|
|
231
231
|
_,
|
|
@@ -240,8 +240,8 @@ class CodeGenProcess {
|
|
|
240
240
|
let modelTypes = [];
|
|
241
241
|
|
|
242
242
|
const modelTypeComponents = _.compact([
|
|
243
|
-
|
|
244
|
-
this.config.extractResponses &&
|
|
243
|
+
"schemas",
|
|
244
|
+
this.config.extractResponses && "responses",
|
|
245
245
|
]);
|
|
246
246
|
|
|
247
247
|
const getSchemaComponentsCount = () =>
|
|
@@ -266,7 +266,7 @@ class CodeGenProcess {
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
if (this.config.sortTypes) {
|
|
269
|
-
return modelTypes.sort(sortByProperty(
|
|
269
|
+
return modelTypes.sort(sortByProperty("name"));
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
return modelTypes;
|
|
@@ -487,7 +487,7 @@ class CodeGenProcess {
|
|
|
487
487
|
templatesToRender.api,
|
|
488
488
|
configuration,
|
|
489
489
|
),
|
|
490
|
-
]).join(
|
|
490
|
+
]).join("\n"),
|
|
491
491
|
);
|
|
492
492
|
};
|
|
493
493
|
|
|
@@ -503,7 +503,7 @@ class CodeGenProcess {
|
|
|
503
503
|
const fileExtension = ts.Extension.Ts;
|
|
504
504
|
|
|
505
505
|
if (configuration.translateToJavaScript) {
|
|
506
|
-
this.logger.debug(
|
|
506
|
+
this.logger.debug("using js translator for", fileName);
|
|
507
507
|
return await this.javascriptTranslator.translate({
|
|
508
508
|
fileName: fileName,
|
|
509
509
|
fileExtension: fileExtension,
|
|
@@ -512,7 +512,7 @@ class CodeGenProcess {
|
|
|
512
512
|
}
|
|
513
513
|
|
|
514
514
|
if (configuration.customTranslator) {
|
|
515
|
-
this.logger.debug(
|
|
515
|
+
this.logger.debug("using custom translator for", fileName);
|
|
516
516
|
return await configuration.customTranslator.translate({
|
|
517
517
|
fileName: fileName,
|
|
518
518
|
fileExtension: fileExtension,
|
|
@@ -520,7 +520,7 @@ class CodeGenProcess {
|
|
|
520
520
|
});
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
-
this.logger.debug(
|
|
523
|
+
this.logger.debug("generating output for", `${fileName}${fileExtension}`);
|
|
524
524
|
|
|
525
525
|
return [
|
|
526
526
|
{
|
|
@@ -533,8 +533,8 @@ 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:
|
|
537
|
-
const { title =
|
|
536
|
+
const server = (servers && servers[0]) || { url: "" };
|
|
537
|
+
const { title = "No title", version } = info || {};
|
|
538
538
|
const { url: serverUrl } = server;
|
|
539
539
|
|
|
540
540
|
return {
|
|
@@ -544,8 +544,8 @@ class CodeGenProcess {
|
|
|
544
544
|
host,
|
|
545
545
|
externalDocs: _.merge(
|
|
546
546
|
{
|
|
547
|
-
url:
|
|
548
|
-
description:
|
|
547
|
+
url: "",
|
|
548
|
+
description: "",
|
|
549
549
|
},
|
|
550
550
|
externalDocs,
|
|
551
551
|
),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { objectAssign } = require(
|
|
2
|
-
const { HTTP_CLIENT, PROJECT_VERSION } = require(
|
|
1
|
+
const { objectAssign } = require("../../util/object-assign");
|
|
2
|
+
const { HTTP_CLIENT, PROJECT_VERSION } = require("../../constants");
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @type {GenerateTemplatesParams}}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// License text available at https://opensource.org/licenses/MIT
|
|
7
7
|
// Repository https://github.com/acacode/swagger-typescript-api
|
|
8
8
|
|
|
9
|
-
const { TemplatesGenProcess } = require(
|
|
9
|
+
const { TemplatesGenProcess } = require("./templates-gen-process");
|
|
10
10
|
|
|
11
11
|
module.exports = {
|
|
12
12
|
generateTemplates: async (config) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const { TemplatesGenConfig } = require(
|
|
2
|
-
const { FileSystem } = require(
|
|
3
|
-
const { Logger } = require(
|
|
4
|
-
const path = require(
|
|
1
|
+
const { TemplatesGenConfig } = require("./configuration");
|
|
2
|
+
const { FileSystem } = require("../../util/file-system");
|
|
3
|
+
const { Logger } = require("../../util/logger");
|
|
4
|
+
const path = require("node:path");
|
|
5
5
|
|
|
6
6
|
class TemplatesGenProcess {
|
|
7
7
|
/**
|
|
@@ -17,16 +17,16 @@ class TemplatesGenProcess {
|
|
|
17
17
|
*/
|
|
18
18
|
logger;
|
|
19
19
|
|
|
20
|
-
rootDir = path.resolve(__dirname,
|
|
20
|
+
rootDir = path.resolve(__dirname, "../../../");
|
|
21
21
|
|
|
22
22
|
paths = {
|
|
23
|
-
baseTemplates:
|
|
24
|
-
httpClientTemplates:
|
|
25
|
-
moduleApiTemplates:
|
|
26
|
-
defaultApiTemplates:
|
|
23
|
+
baseTemplates: "templates/base",
|
|
24
|
+
httpClientTemplates: "templates/base/http-clients",
|
|
25
|
+
moduleApiTemplates: "templates/modular",
|
|
26
|
+
defaultApiTemplates: "templates/default",
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
importTemplatePrefixes = [
|
|
29
|
+
importTemplatePrefixes = ["@base", "@modular", "@default"];
|
|
30
30
|
|
|
31
31
|
constructor(config) {
|
|
32
32
|
this.config = new TemplatesGenConfig(config);
|
|
@@ -45,7 +45,7 @@ class TemplatesGenProcess {
|
|
|
45
45
|
const templates = this.getTemplates();
|
|
46
46
|
|
|
47
47
|
if (this.config.output) {
|
|
48
|
-
this.logger.log(
|
|
48
|
+
this.logger.log("preparing output directory for source templates");
|
|
49
49
|
const outputPath = path.resolve(process.cwd(), this.config.output);
|
|
50
50
|
|
|
51
51
|
if (this.fileSystem.pathIsExist(outputPath)) {
|
|
@@ -122,7 +122,7 @@ class TemplatesGenProcess {
|
|
|
122
122
|
template.startsWith(`${this.config.httpClientType}-`),
|
|
123
123
|
);
|
|
124
124
|
|
|
125
|
-
let httpClientTemplateContent =
|
|
125
|
+
let httpClientTemplateContent = "";
|
|
126
126
|
|
|
127
127
|
if (usingHttpClientTemplate) {
|
|
128
128
|
httpClientTemplateContent = this.fixTemplateContent(
|
|
@@ -134,7 +134,7 @@ class TemplatesGenProcess {
|
|
|
134
134
|
|
|
135
135
|
for (const fileName of baseTemplates) {
|
|
136
136
|
const templateContent =
|
|
137
|
-
(fileName ===
|
|
137
|
+
(fileName === "http-client.ejs" && httpClientTemplateContent) ||
|
|
138
138
|
this.fixTemplateContent(
|
|
139
139
|
this.getTemplateContent(`${this.paths.baseTemplates}/${fileName}`),
|
|
140
140
|
);
|
|
@@ -162,34 +162,34 @@ class TemplatesGenProcess {
|
|
|
162
162
|
const importsRegExp1 = new RegExp(
|
|
163
163
|
`includeFile\\("(${this.importTemplatePrefixes
|
|
164
164
|
.map((v) => `(${v})`)
|
|
165
|
-
.join(
|
|
166
|
-
|
|
165
|
+
.join("|")})/`,
|
|
166
|
+
"g",
|
|
167
167
|
);
|
|
168
168
|
// includeFile(`@base/
|
|
169
169
|
const importsRegExp2 = new RegExp(
|
|
170
170
|
`includeFile\\(\`(${this.importTemplatePrefixes
|
|
171
171
|
.map((v) => `(${v})`)
|
|
172
|
-
.join(
|
|
173
|
-
|
|
172
|
+
.join("|")})/`,
|
|
173
|
+
"g",
|
|
174
174
|
);
|
|
175
175
|
// includeFile('@base/
|
|
176
176
|
const importsRegExp3 = new RegExp(
|
|
177
177
|
`includeFile\\('(${this.importTemplatePrefixes
|
|
178
178
|
.map((v) => `(${v})`)
|
|
179
|
-
.join(
|
|
180
|
-
|
|
179
|
+
.join("|")})/`,
|
|
180
|
+
"g",
|
|
181
181
|
);
|
|
182
182
|
|
|
183
183
|
return content
|
|
184
184
|
.replace(importsRegExp1, 'includeFile("./')
|
|
185
|
-
.replace(importsRegExp2,
|
|
185
|
+
.replace(importsRegExp2, "includeFile(`./")
|
|
186
186
|
.replace(importsRegExp3, "includeFile('./");
|
|
187
187
|
};
|
|
188
188
|
|
|
189
189
|
getTemplateNamesFromDir = (dir) => {
|
|
190
190
|
return this.fileSystem
|
|
191
191
|
.readDir(path.resolve(this.rootDir, dir))
|
|
192
|
-
.filter((file) => file.endsWith(
|
|
192
|
+
.filter((file) => file.endsWith(".ejs"));
|
|
193
193
|
};
|
|
194
194
|
|
|
195
195
|
getTemplateContent = (pathToFile) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { getRandomInt } = require(
|
|
2
|
-
const { NameResolver } = require(
|
|
1
|
+
const { getRandomInt } = require("./util/random");
|
|
2
|
+
const { NameResolver } = require("./util/name-resolver");
|
|
3
3
|
|
|
4
4
|
class ComponentTypeNameResolver extends NameResolver {
|
|
5
5
|
counter = 1;
|
|
@@ -22,7 +22,7 @@ class ComponentTypeNameResolver extends NameResolver {
|
|
|
22
22
|
this.countersByVariant.set(randomVariant, variantCounter);
|
|
23
23
|
const dirtyResolvedName = `${randomVariant}${variantCounter}`;
|
|
24
24
|
this.logger.debug(
|
|
25
|
-
|
|
25
|
+
"generated dirty resolved type name for component - ",
|
|
26
26
|
dirtyResolvedName,
|
|
27
27
|
);
|
|
28
28
|
return dirtyResolvedName;
|
|
@@ -31,7 +31,7 @@ class ComponentTypeNameResolver extends NameResolver {
|
|
|
31
31
|
const fallbackName = `${this.config.componentTypeNameResolver}${this
|
|
32
32
|
.fallbackNameCounter++}`;
|
|
33
33
|
this.logger.debug(
|
|
34
|
-
|
|
34
|
+
"generated fallback type name for component - ",
|
|
35
35
|
fallbackName,
|
|
36
36
|
);
|
|
37
37
|
return fallbackName;
|