swagger-typescript-api 13.0.3 → 13.0.5
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 +12 -12
- 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/src/configuration.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
|
-
const { objectAssign } = require(
|
|
3
|
-
const _ = require(
|
|
4
|
-
const CONSTANTS = require(
|
|
5
|
-
const { ComponentTypeNameResolver } = require(
|
|
6
|
-
const { cosmiconfigSync } = require(
|
|
7
|
-
const ts = require(
|
|
2
|
+
const { objectAssign } = require("./util/object-assign");
|
|
3
|
+
const _ = require("lodash");
|
|
4
|
+
const CONSTANTS = require("./constants");
|
|
5
|
+
const { ComponentTypeNameResolver } = require("./component-type-name-resolver");
|
|
6
|
+
const { cosmiconfigSync } = require("cosmiconfig");
|
|
7
|
+
const ts = require("typescript");
|
|
8
8
|
|
|
9
9
|
const TsKeyword = {
|
|
10
|
-
Number:
|
|
11
|
-
String:
|
|
12
|
-
Boolean:
|
|
13
|
-
Any:
|
|
14
|
-
Void:
|
|
15
|
-
Unknown:
|
|
16
|
-
Null:
|
|
17
|
-
Undefined:
|
|
18
|
-
Object:
|
|
19
|
-
File:
|
|
20
|
-
Date:
|
|
21
|
-
Type:
|
|
22
|
-
Enum:
|
|
23
|
-
Interface:
|
|
24
|
-
Array:
|
|
25
|
-
Record:
|
|
26
|
-
Intersection:
|
|
27
|
-
Union:
|
|
10
|
+
Number: "number",
|
|
11
|
+
String: "string",
|
|
12
|
+
Boolean: "boolean",
|
|
13
|
+
Any: "any",
|
|
14
|
+
Void: "void",
|
|
15
|
+
Unknown: "unknown",
|
|
16
|
+
Null: "null",
|
|
17
|
+
Undefined: "undefined",
|
|
18
|
+
Object: "object",
|
|
19
|
+
File: "File",
|
|
20
|
+
Date: "Date",
|
|
21
|
+
Type: "type",
|
|
22
|
+
Enum: "enum",
|
|
23
|
+
Interface: "interface",
|
|
24
|
+
Array: "Array",
|
|
25
|
+
Record: "Record",
|
|
26
|
+
Intersection: "&",
|
|
27
|
+
Union: "|",
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const TsCodeGenKeyword = {
|
|
31
|
-
UtilRequiredKeys:
|
|
31
|
+
UtilRequiredKeys: "UtilRequiredKeys",
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -37,7 +37,7 @@ const TsCodeGenKeyword = {
|
|
|
37
37
|
class CodeGenConfig {
|
|
38
38
|
version = CONSTANTS.PROJECT_VERSION;
|
|
39
39
|
/** CLI flag */
|
|
40
|
-
templates =
|
|
40
|
+
templates = "";
|
|
41
41
|
/** CLI flag */
|
|
42
42
|
generateResponses = false;
|
|
43
43
|
/** CLI flag */
|
|
@@ -60,7 +60,7 @@ class CodeGenConfig {
|
|
|
60
60
|
|
|
61
61
|
/** { "#/components/schemas/Foo": @TypeInfo, ... } */
|
|
62
62
|
componentsMap = {};
|
|
63
|
-
/** flag for catching
|
|
63
|
+
/** flag for catching conversion from swagger 2.0 */
|
|
64
64
|
convertedFromSwagger2 = false;
|
|
65
65
|
|
|
66
66
|
/** url index from paths used for merging into modules */
|
|
@@ -77,10 +77,10 @@ class CodeGenConfig {
|
|
|
77
77
|
extractResponses = false;
|
|
78
78
|
extractEnums = false;
|
|
79
79
|
fileNames = {
|
|
80
|
-
dataContracts:
|
|
81
|
-
routeTypes:
|
|
82
|
-
httpClient:
|
|
83
|
-
outOfModuleApi:
|
|
80
|
+
dataContracts: "data-contracts",
|
|
81
|
+
routeTypes: "route-types",
|
|
82
|
+
httpClient: "http-client",
|
|
83
|
+
outOfModuleApi: "Common",
|
|
84
84
|
};
|
|
85
85
|
routeNameDuplicatesMap = new Map();
|
|
86
86
|
prettierOptions = { ...CONSTANTS.PRETTIER_OPTIONS };
|
|
@@ -108,28 +108,28 @@ class CodeGenConfig {
|
|
|
108
108
|
sortRoutes = false;
|
|
109
109
|
templatePaths = {
|
|
110
110
|
/** `templates/base` */
|
|
111
|
-
base:
|
|
111
|
+
base: "",
|
|
112
112
|
/** `templates/default` */
|
|
113
|
-
default:
|
|
113
|
+
default: "",
|
|
114
114
|
/** `templates/modular` */
|
|
115
|
-
modular:
|
|
115
|
+
modular: "",
|
|
116
116
|
/** usage path if `--templates` option is not set */
|
|
117
|
-
original:
|
|
117
|
+
original: "",
|
|
118
118
|
/** custom path to templates (`--templates`) */
|
|
119
|
-
custom:
|
|
119
|
+
custom: "",
|
|
120
120
|
};
|
|
121
121
|
/** Record<templateName, templateContent> */
|
|
122
122
|
templatesToRender = {
|
|
123
|
-
api:
|
|
124
|
-
dataContracts:
|
|
125
|
-
dataContractJsDoc:
|
|
126
|
-
interfaceDataContract:
|
|
127
|
-
typeDataContract:
|
|
128
|
-
enumDataContract:
|
|
129
|
-
objectFieldJsDoc:
|
|
130
|
-
httpClient:
|
|
131
|
-
routeTypes:
|
|
132
|
-
routeName:
|
|
123
|
+
api: "",
|
|
124
|
+
dataContracts: "",
|
|
125
|
+
dataContractJsDoc: "",
|
|
126
|
+
interfaceDataContract: "",
|
|
127
|
+
typeDataContract: "",
|
|
128
|
+
enumDataContract: "",
|
|
129
|
+
objectFieldJsDoc: "",
|
|
130
|
+
httpClient: "",
|
|
131
|
+
routeTypes: "",
|
|
132
|
+
routeName: "",
|
|
133
133
|
};
|
|
134
134
|
/**
|
|
135
135
|
* @type {Record<string, (...args: any[]) => MonoSchemaParser>}
|
|
@@ -137,68 +137,68 @@ class CodeGenConfig {
|
|
|
137
137
|
schemaParsers = {};
|
|
138
138
|
toJS = false;
|
|
139
139
|
silent = false;
|
|
140
|
-
typePrefix =
|
|
141
|
-
typeSuffix =
|
|
142
|
-
enumKeyPrefix =
|
|
143
|
-
enumKeySuffix =
|
|
140
|
+
typePrefix = "";
|
|
141
|
+
typeSuffix = "";
|
|
142
|
+
enumKeyPrefix = "";
|
|
143
|
+
enumKeySuffix = "";
|
|
144
144
|
patch = false;
|
|
145
145
|
/** @type {ComponentTypeNameResolver} */
|
|
146
146
|
componentTypeNameResolver;
|
|
147
147
|
/** name of the main exported class */
|
|
148
|
-
apiClassName =
|
|
148
|
+
apiClassName = "Api";
|
|
149
149
|
debug = false;
|
|
150
150
|
anotherArrayType = false;
|
|
151
151
|
internalTemplateOptions = {
|
|
152
152
|
addUtilRequiredKeysType: false,
|
|
153
153
|
};
|
|
154
154
|
extraTemplates = [];
|
|
155
|
-
input =
|
|
155
|
+
input = "";
|
|
156
156
|
modular = false;
|
|
157
|
-
output =
|
|
158
|
-
url =
|
|
157
|
+
output = "";
|
|
158
|
+
url = "";
|
|
159
159
|
cleanOutput = false;
|
|
160
160
|
spec = null;
|
|
161
|
-
fileName =
|
|
161
|
+
fileName = "Api.ts";
|
|
162
162
|
authorizationToken = void 0;
|
|
163
163
|
requestOptions = null;
|
|
164
164
|
|
|
165
165
|
jsPrimitiveTypes = [];
|
|
166
166
|
jsEmptyTypes = [];
|
|
167
|
-
fixInvalidTypeNamePrefix =
|
|
168
|
-
fixInvalidEnumKeyPrefix =
|
|
167
|
+
fixInvalidTypeNamePrefix = "Type";
|
|
168
|
+
fixInvalidEnumKeyPrefix = "Value";
|
|
169
169
|
|
|
170
|
-
enumKeyResolverName =
|
|
171
|
-
typeNameResolverName =
|
|
172
|
-
specificArgNameResolverName =
|
|
170
|
+
enumKeyResolverName = "Value";
|
|
171
|
+
typeNameResolverName = "ComponentType";
|
|
172
|
+
specificArgNameResolverName = "arg";
|
|
173
173
|
|
|
174
174
|
successResponseStatusRange = [200, 299];
|
|
175
175
|
|
|
176
176
|
/** @type {ExtractingOptions} */
|
|
177
177
|
extractingOptions = {
|
|
178
|
-
requestBodySuffix: [
|
|
179
|
-
requestParamsSuffix: [
|
|
180
|
-
responseBodySuffix: [
|
|
178
|
+
requestBodySuffix: ["Payload", "Body", "Input"],
|
|
179
|
+
requestParamsSuffix: ["Params"],
|
|
180
|
+
responseBodySuffix: ["Data", "Result", "Output"],
|
|
181
181
|
responseErrorSuffix: [
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
182
|
+
"Error",
|
|
183
|
+
"Fail",
|
|
184
|
+
"Fails",
|
|
185
|
+
"ErrorData",
|
|
186
|
+
"HttpError",
|
|
187
|
+
"BadResponse",
|
|
188
188
|
],
|
|
189
|
-
enumSuffix: [
|
|
190
|
-
discriminatorMappingSuffix: [
|
|
189
|
+
enumSuffix: ["Enum"],
|
|
190
|
+
discriminatorMappingSuffix: ["Mapping", "Mapper", "MapType"],
|
|
191
191
|
discriminatorAbstractPrefix: [
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
"Base",
|
|
193
|
+
"Abstract",
|
|
194
|
+
"Discriminator",
|
|
195
|
+
"Internal",
|
|
196
|
+
"Polymorph",
|
|
197
197
|
],
|
|
198
198
|
};
|
|
199
199
|
|
|
200
200
|
compilerTsConfig = {
|
|
201
|
-
module:
|
|
201
|
+
module: "ESNext",
|
|
202
202
|
noImplicitReturns: true,
|
|
203
203
|
alwaysStrict: true,
|
|
204
204
|
target: ts.ScriptTarget.ESNext,
|
|
@@ -241,7 +241,7 @@ class CodeGenConfig {
|
|
|
241
241
|
/**
|
|
242
242
|
* $A
|
|
243
243
|
*/
|
|
244
|
-
NullValue: (content) =>
|
|
244
|
+
NullValue: (content) => "null",
|
|
245
245
|
/**
|
|
246
246
|
* $A1 | $A2
|
|
247
247
|
*/
|
|
@@ -250,7 +250,7 @@ class CodeGenConfig {
|
|
|
250
250
|
/**
|
|
251
251
|
* ($A1)
|
|
252
252
|
*/
|
|
253
|
-
ExpressionGroup: (content) => (content ? `(${content})` :
|
|
253
|
+
ExpressionGroup: (content) => (content ? `(${content})` : ""),
|
|
254
254
|
/**
|
|
255
255
|
* $A1 & $A2
|
|
256
256
|
*/
|
|
@@ -266,12 +266,12 @@ class CodeGenConfig {
|
|
|
266
266
|
*/
|
|
267
267
|
TypeField: ({ readonly, key, optional, value }) =>
|
|
268
268
|
_.compact([
|
|
269
|
-
readonly &&
|
|
269
|
+
readonly && "readonly ",
|
|
270
270
|
key,
|
|
271
|
-
optional &&
|
|
272
|
-
|
|
271
|
+
optional && "?",
|
|
272
|
+
": ",
|
|
273
273
|
value,
|
|
274
|
-
]).join(
|
|
274
|
+
]).join(""),
|
|
275
275
|
/**
|
|
276
276
|
* [key: $A1]: $A2
|
|
277
277
|
*/
|
|
@@ -294,7 +294,7 @@ class CodeGenConfig {
|
|
|
294
294
|
_.map(
|
|
295
295
|
contents,
|
|
296
296
|
({ key, value }) => ` ${this.Ts.EnumField(key, value)}`,
|
|
297
|
-
).join(
|
|
297
|
+
).join(",\n"),
|
|
298
298
|
/**
|
|
299
299
|
* {\n $A \n}
|
|
300
300
|
*/
|
|
@@ -306,21 +306,21 @@ class CodeGenConfig {
|
|
|
306
306
|
[
|
|
307
307
|
...(contents.length === 1
|
|
308
308
|
? [`/** ${contents[0]} */`]
|
|
309
|
-
: [
|
|
309
|
+
: ["/**", ...contents.map((content) => ` * ${content}`), " */"]),
|
|
310
310
|
].map((part) => `${formatFn ? formatFn(part) : part}\n`),
|
|
311
311
|
/**
|
|
312
312
|
* $A1<...$A2.join(,)>
|
|
313
313
|
*/
|
|
314
314
|
TypeWithGeneric: (typeName, genericArgs) => {
|
|
315
315
|
return `${typeName}${
|
|
316
|
-
genericArgs.length ? `<${genericArgs.join(
|
|
316
|
+
genericArgs.length ? `<${genericArgs.join(",")}>` : ""
|
|
317
317
|
}`;
|
|
318
318
|
},
|
|
319
319
|
/**
|
|
320
320
|
* [$A1, $A2, ...$AN]
|
|
321
321
|
*/
|
|
322
322
|
Tuple: (values) => {
|
|
323
|
-
return `[${values.join(
|
|
323
|
+
return `[${values.join(", ")}]`;
|
|
324
324
|
},
|
|
325
325
|
};
|
|
326
326
|
|
|
@@ -341,39 +341,39 @@ class CodeGenConfig {
|
|
|
341
341
|
/** formats */
|
|
342
342
|
binary: () => this.Ts.Keyword.File,
|
|
343
343
|
file: () => this.Ts.Keyword.File,
|
|
344
|
-
|
|
344
|
+
"date-time": () => this.Ts.Keyword.String,
|
|
345
345
|
time: () => this.Ts.Keyword.String,
|
|
346
346
|
date: () => this.Ts.Keyword.String,
|
|
347
347
|
duration: () => this.Ts.Keyword.String,
|
|
348
348
|
email: () => this.Ts.Keyword.String,
|
|
349
|
-
|
|
350
|
-
|
|
349
|
+
"idn-email": () => this.Ts.Keyword.String,
|
|
350
|
+
"idn-hostname": () => this.Ts.Keyword.String,
|
|
351
351
|
ipv4: () => this.Ts.Keyword.String,
|
|
352
352
|
ipv6: () => this.Ts.Keyword.String,
|
|
353
353
|
uuid: () => this.Ts.Keyword.String,
|
|
354
354
|
uri: () => this.Ts.Keyword.String,
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
355
|
+
"uri-reference": () => this.Ts.Keyword.String,
|
|
356
|
+
"uri-template": () => this.Ts.Keyword.String,
|
|
357
|
+
"json-pointer": () => this.Ts.Keyword.String,
|
|
358
|
+
"relative-json-pointer": () => this.Ts.Keyword.String,
|
|
359
359
|
regex: () => this.Ts.Keyword.String,
|
|
360
360
|
},
|
|
361
361
|
};
|
|
362
362
|
|
|
363
363
|
templateInfos = [
|
|
364
|
-
{ name:
|
|
365
|
-
{ name:
|
|
366
|
-
{ name:
|
|
367
|
-
{ name:
|
|
368
|
-
{ name:
|
|
369
|
-
{ name:
|
|
370
|
-
{ name:
|
|
371
|
-
{ name:
|
|
372
|
-
{ name:
|
|
373
|
-
{ name:
|
|
364
|
+
{ name: "api", fileName: "api" },
|
|
365
|
+
{ name: "dataContracts", fileName: "data-contracts" },
|
|
366
|
+
{ name: "dataContractJsDoc", fileName: "data-contract-jsdoc" },
|
|
367
|
+
{ name: "interfaceDataContract", fileName: "interface-data-contract" },
|
|
368
|
+
{ name: "typeDataContract", fileName: "type-data-contract" },
|
|
369
|
+
{ name: "enumDataContract", fileName: "enum-data-contract" },
|
|
370
|
+
{ name: "objectFieldJsDoc", fileName: "object-field-jsdoc" },
|
|
371
|
+
{ name: "httpClient", fileName: "http-client" },
|
|
372
|
+
{ name: "routeTypes", fileName: "route-types" },
|
|
373
|
+
{ name: "routeName", fileName: "route-name" },
|
|
374
374
|
];
|
|
375
375
|
|
|
376
|
-
templateExtensions = [
|
|
376
|
+
templateExtensions = [".eta", ".ejs"];
|
|
377
377
|
|
|
378
378
|
/**
|
|
379
379
|
* @param config {Partial<GenerateApiConfiguration['config']>}
|
|
@@ -429,12 +429,12 @@ class CodeGenConfig {
|
|
|
429
429
|
}
|
|
430
430
|
|
|
431
431
|
const getDefaultPrettierOptions = () => {
|
|
432
|
-
const prettier = cosmiconfigSync(
|
|
432
|
+
const prettier = cosmiconfigSync("prettier").search();
|
|
433
433
|
|
|
434
434
|
if (prettier) {
|
|
435
435
|
return {
|
|
436
436
|
...prettier.config,
|
|
437
|
-
parser:
|
|
437
|
+
parser: "typescript",
|
|
438
438
|
};
|
|
439
439
|
}
|
|
440
440
|
|
package/src/constants.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
const packageJson = require(
|
|
2
|
-
const RESERVED_QUERY_ARG_NAMES = [
|
|
3
|
-
const RESERVED_BODY_ARG_NAMES = [
|
|
1
|
+
const packageJson = require("../package.json");
|
|
2
|
+
const RESERVED_QUERY_ARG_NAMES = ["query", "queryParams", "queryArg"];
|
|
3
|
+
const RESERVED_BODY_ARG_NAMES = ["data", "body", "reqBody"];
|
|
4
4
|
const RESERVED_REQ_PARAMS_ARG_NAMES = [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
"params",
|
|
6
|
+
"requestParams",
|
|
7
|
+
"reqParams",
|
|
8
|
+
"httpParams",
|
|
9
9
|
];
|
|
10
|
-
const RESERVED_PATH_ARG_NAMES = [
|
|
11
|
-
const RESERVED_HEADER_ARG_NAMES = [
|
|
10
|
+
const RESERVED_PATH_ARG_NAMES = ["path", "pathParams"];
|
|
11
|
+
const RESERVED_HEADER_ARG_NAMES = ["headers", "headersParams"];
|
|
12
12
|
|
|
13
13
|
const SCHEMA_TYPES = {
|
|
14
|
-
ARRAY:
|
|
15
|
-
OBJECT:
|
|
16
|
-
ENUM:
|
|
17
|
-
REF:
|
|
18
|
-
PRIMITIVE:
|
|
19
|
-
COMPLEX:
|
|
20
|
-
DISCRIMINATOR:
|
|
21
|
-
COMPLEX_ONE_OF:
|
|
22
|
-
COMPLEX_ANY_OF:
|
|
23
|
-
COMPLEX_ALL_OF:
|
|
24
|
-
COMPLEX_NOT:
|
|
25
|
-
COMPLEX_UNKNOWN:
|
|
14
|
+
ARRAY: "array",
|
|
15
|
+
OBJECT: "object",
|
|
16
|
+
ENUM: "enum",
|
|
17
|
+
REF: "$ref",
|
|
18
|
+
PRIMITIVE: "primitive",
|
|
19
|
+
COMPLEX: "complex",
|
|
20
|
+
DISCRIMINATOR: "discriminator",
|
|
21
|
+
COMPLEX_ONE_OF: "oneOf",
|
|
22
|
+
COMPLEX_ANY_OF: "anyOf",
|
|
23
|
+
COMPLEX_ALL_OF: "allOf",
|
|
24
|
+
COMPLEX_NOT: "not",
|
|
25
|
+
COMPLEX_UNKNOWN: "__unknown",
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
const HTTP_CLIENT = {
|
|
29
|
-
FETCH:
|
|
30
|
-
AXIOS:
|
|
29
|
+
FETCH: "fetch",
|
|
30
|
+
AXIOS: "axios",
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const PROJECT_VERSION = packageJson.version;
|
|
@@ -47,7 +47,7 @@ const FILE_PREFIX = `/* eslint-disable */
|
|
|
47
47
|
|
|
48
48
|
module.exports = {
|
|
49
49
|
FILE_PREFIX,
|
|
50
|
-
DEFAULT_BODY_ARG_NAME:
|
|
50
|
+
DEFAULT_BODY_ARG_NAME: "data",
|
|
51
51
|
PROJECT_VERSION,
|
|
52
52
|
SCHEMA_TYPES,
|
|
53
53
|
HTTP_CLIENT,
|
|
@@ -59,7 +59,7 @@ module.exports = {
|
|
|
59
59
|
PRETTIER_OPTIONS: {
|
|
60
60
|
printWidth: 120,
|
|
61
61
|
tabWidth: 2,
|
|
62
|
-
trailingComma:
|
|
63
|
-
parser:
|
|
62
|
+
trailingComma: "all",
|
|
63
|
+
parser: "typescript",
|
|
64
64
|
},
|
|
65
65
|
};
|
package/src/index.js
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
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 constants = require(
|
|
10
|
-
const { CodeGenProcess } = require(
|
|
11
|
-
const { generateTemplates } = require(
|
|
9
|
+
const constants = require("./constants");
|
|
10
|
+
const { CodeGenProcess } = require("./code-gen-process.js");
|
|
11
|
+
const { generateTemplates } = require("./commands/generate-templates");
|
|
12
12
|
|
|
13
13
|
module.exports = {
|
|
14
14
|
constants: constants,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _ = require(
|
|
1
|
+
const _ = require("lodash");
|
|
2
2
|
|
|
3
3
|
class SchemaComponentsMap {
|
|
4
4
|
/** @type {SchemaComponent[]} */
|
|
@@ -15,11 +15,11 @@ class SchemaComponentsMap {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
createRef = (paths) => {
|
|
18
|
-
return [
|
|
18
|
+
return ["#", ...paths].join("/");
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
parseRef = (ref) => {
|
|
22
|
-
return ref.split(
|
|
22
|
+
return ref.split("/");
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
createComponent($ref, rawTypeData) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const { MonoSchemaParser } = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const { SCHEMA_TYPES } = require(
|
|
1
|
+
const { MonoSchemaParser } = require("../mono-schema-parser");
|
|
2
|
+
const _ = require("lodash");
|
|
3
|
+
const { SCHEMA_TYPES } = require("../../constants");
|
|
4
4
|
|
|
5
5
|
class ArraySchemaParser extends MonoSchemaParser {
|
|
6
6
|
parse() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const { MonoSchemaParser } = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const { SCHEMA_TYPES } = require(
|
|
1
|
+
const { MonoSchemaParser } = require("../mono-schema-parser");
|
|
2
|
+
const _ = require("lodash");
|
|
3
|
+
const { SCHEMA_TYPES } = require("../../constants");
|
|
4
4
|
|
|
5
5
|
class ComplexSchemaParser extends MonoSchemaParser {
|
|
6
6
|
parse() {
|
|
@@ -23,8 +23,8 @@ class ComplexSchemaParser extends MonoSchemaParser {
|
|
|
23
23
|
name: this.typeName,
|
|
24
24
|
description: this.schemaFormatters.formatDescription(
|
|
25
25
|
this.schema.description ||
|
|
26
|
-
_.compact(_.map(this.schema[complexType],
|
|
27
|
-
|
|
26
|
+
_.compact(_.map(this.schema[complexType], "description"))[0] ||
|
|
27
|
+
"",
|
|
28
28
|
),
|
|
29
29
|
content:
|
|
30
30
|
this.config.Ts.IntersectionType(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const _ = require(
|
|
2
|
-
const { SCHEMA_TYPES } = require(
|
|
3
|
-
const { MonoSchemaParser } = require(
|
|
1
|
+
const _ = require("lodash");
|
|
2
|
+
const { SCHEMA_TYPES } = require("../../constants");
|
|
3
|
+
const { MonoSchemaParser } = require("../mono-schema-parser");
|
|
4
4
|
|
|
5
5
|
class DiscriminatorSchemaParser extends MonoSchemaParser {
|
|
6
6
|
parse() {
|
|
@@ -54,8 +54,8 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
|
|
|
54
54
|
const ts = this.config.Ts;
|
|
55
55
|
|
|
56
56
|
const refPath = this.schemaComponentsMap.createRef([
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
"components",
|
|
58
|
+
"schemas",
|
|
59
59
|
this.typeName,
|
|
60
60
|
]);
|
|
61
61
|
const { discriminator } = this.schema;
|
|
@@ -85,18 +85,18 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
|
|
|
85
85
|
ts.ObjectWrapper(
|
|
86
86
|
ts.TypeField({
|
|
87
87
|
key: ts.StringValue(discriminator.propertyName),
|
|
88
|
-
value:
|
|
88
|
+
value: "Key",
|
|
89
89
|
}),
|
|
90
90
|
),
|
|
91
|
-
|
|
91
|
+
"Type",
|
|
92
92
|
]);
|
|
93
93
|
|
|
94
94
|
const component = this.schemaParserFabric.createParsedComponent({
|
|
95
95
|
typeName: generatedTypeName,
|
|
96
96
|
schema: {
|
|
97
|
-
type:
|
|
97
|
+
type: "object",
|
|
98
98
|
properties: {},
|
|
99
|
-
genericArgs: [{ name:
|
|
99
|
+
genericArgs: [{ name: "Key" }, { name: "Type" }],
|
|
100
100
|
internal: true,
|
|
101
101
|
},
|
|
102
102
|
});
|
|
@@ -138,7 +138,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
|
|
|
138
138
|
|
|
139
139
|
for (const [mappingKey, schema] of mappingEntries) {
|
|
140
140
|
const mappingSchema =
|
|
141
|
-
typeof schema ===
|
|
141
|
+
typeof schema === "string" ? { $ref: schema } : schema;
|
|
142
142
|
|
|
143
143
|
this.mutateMappingDependentSchema({
|
|
144
144
|
discPropertyName: discriminator.propertyName,
|
|
@@ -169,7 +169,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
|
|
|
169
169
|
let mappingPropertySchemaEnumKeysMap = {};
|
|
170
170
|
let mappingPropertySchema = _.get(
|
|
171
171
|
abstractSchemaStruct?.component?.rawTypeData,
|
|
172
|
-
[
|
|
172
|
+
["properties", discPropertyName],
|
|
173
173
|
);
|
|
174
174
|
if (this.schemaUtils.isRefSchema(mappingPropertySchema)) {
|
|
175
175
|
mappingPropertySchema = this.schemaUtils.getSchemaRefType(
|
|
@@ -271,7 +271,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser {
|
|
|
271
271
|
resolver: this.config.extractingOptions.discriminatorAbstractResolver,
|
|
272
272
|
});
|
|
273
273
|
const component = this.schemaComponentsMap.createComponent(
|
|
274
|
-
this.schemaComponentsMap.createRef([
|
|
274
|
+
this.schemaComponentsMap.createRef(["components", "schemas", typeName]),
|
|
275
275
|
{
|
|
276
276
|
...schema,
|
|
277
277
|
internal: true,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const { MonoSchemaParser } = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const { SCHEMA_TYPES } = require(
|
|
4
|
-
const { EnumKeyResolver } = require(
|
|
1
|
+
const { MonoSchemaParser } = require("../mono-schema-parser");
|
|
2
|
+
const _ = require("lodash");
|
|
3
|
+
const { SCHEMA_TYPES } = require("../../constants");
|
|
4
|
+
const { EnumKeyResolver } = require("../util/enum-key-resolver");
|
|
5
5
|
|
|
6
6
|
class EnumSchemaParser extends MonoSchemaParser {
|
|
7
7
|
/** @type {EnumKeyResolver} */
|
|
@@ -19,8 +19,8 @@ class EnumSchemaParser extends MonoSchemaParser {
|
|
|
19
19
|
});
|
|
20
20
|
const customComponent = this.schemaComponentsMap.createComponent(
|
|
21
21
|
this.schemaComponentsMap.createRef([
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
"components",
|
|
23
|
+
"schemas",
|
|
24
24
|
generatedTypeName,
|
|
25
25
|
]),
|
|
26
26
|
{
|
|
@@ -49,9 +49,9 @@ class EnumSchemaParser extends MonoSchemaParser {
|
|
|
49
49
|
return this.schemaParserFabric.parseSchema(
|
|
50
50
|
{
|
|
51
51
|
oneOf: this.schema.enum.map((enumNames) => ({
|
|
52
|
-
type:
|
|
52
|
+
type: "array",
|
|
53
53
|
items: enumNames.map((enumName) => ({
|
|
54
|
-
type:
|
|
54
|
+
type: "string",
|
|
55
55
|
enum: [enumName],
|
|
56
56
|
})),
|
|
57
57
|
})),
|
|
@@ -70,12 +70,12 @@ class EnumSchemaParser extends MonoSchemaParser {
|
|
|
70
70
|
return this.config.Ts.NullValue(value);
|
|
71
71
|
}
|
|
72
72
|
if (
|
|
73
|
-
_.includes(keyType, this.schemaUtils.getSchemaType({ type:
|
|
73
|
+
_.includes(keyType, this.schemaUtils.getSchemaType({ type: "number" }))
|
|
74
74
|
) {
|
|
75
75
|
return this.config.Ts.NumberValue(value);
|
|
76
76
|
}
|
|
77
77
|
if (
|
|
78
|
-
_.includes(keyType, this.schemaUtils.getSchemaType({ type:
|
|
78
|
+
_.includes(keyType, this.schemaUtils.getSchemaType({ type: "boolean" }))
|
|
79
79
|
) {
|
|
80
80
|
return this.config.Ts.BooleanValue(value);
|
|
81
81
|
}
|
|
@@ -139,13 +139,13 @@ class EnumSchemaParser extends MonoSchemaParser {
|
|
|
139
139
|
|
|
140
140
|
if (key) {
|
|
141
141
|
formatted = this.typeNameFormatter.format(key, {
|
|
142
|
-
type:
|
|
142
|
+
type: "enum-key",
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
if (!formatted) {
|
|
147
147
|
formatted = this.typeNameFormatter.format(`${value}`, {
|
|
148
|
-
type:
|
|
148
|
+
type: "enum-key",
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
|