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
|
@@ -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
|
|
|
@@ -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 ObjectSchemaParser extends MonoSchemaParser {
|
|
6
6
|
parse() {
|
|
@@ -36,7 +36,7 @@ class ObjectSchemaParser extends MonoSchemaParser {
|
|
|
36
36
|
);
|
|
37
37
|
const rawTypeData = _.get(
|
|
38
38
|
this.schemaUtils.getSchemaRefType(property),
|
|
39
|
-
|
|
39
|
+
"rawTypeData",
|
|
40
40
|
{},
|
|
41
41
|
);
|
|
42
42
|
const nullable = !!(rawTypeData.nullable || property.nullable);
|
|
@@ -60,17 +60,17 @@ class ObjectSchemaParser extends MonoSchemaParser {
|
|
|
60
60
|
_.compact(
|
|
61
61
|
_.map(
|
|
62
62
|
property[this.schemaUtils.getComplexType(property)],
|
|
63
|
-
|
|
63
|
+
"description",
|
|
64
64
|
),
|
|
65
65
|
)[0] ||
|
|
66
66
|
rawTypeData.description ||
|
|
67
67
|
_.compact(
|
|
68
68
|
_.map(
|
|
69
69
|
rawTypeData[this.schemaUtils.getComplexType(rawTypeData)],
|
|
70
|
-
|
|
70
|
+
"description",
|
|
71
71
|
),
|
|
72
72
|
)[0] ||
|
|
73
|
-
|
|
73
|
+
"",
|
|
74
74
|
isRequired: required,
|
|
75
75
|
isNullable: nullable,
|
|
76
76
|
name: fieldName,
|
|
@@ -87,7 +87,7 @@ class ObjectSchemaParser extends MonoSchemaParser {
|
|
|
87
87
|
if (additionalProperties) {
|
|
88
88
|
propertiesContent.push({
|
|
89
89
|
$$raw: { additionalProperties },
|
|
90
|
-
description:
|
|
90
|
+
description: "",
|
|
91
91
|
isRequired: false,
|
|
92
92
|
field: this.config.Ts.InterfaceDynamicField(
|
|
93
93
|
this.config.Ts.Keyword.String,
|
|
@@ -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 PrimitiveSchemaParser extends MonoSchemaParser {
|
|
6
6
|
parse() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const { SCHEMA_TYPES } = require(
|
|
2
|
-
const _ = require(
|
|
1
|
+
const { SCHEMA_TYPES } = require("../constants");
|
|
2
|
+
const _ = require("lodash");
|
|
3
3
|
|
|
4
4
|
class SchemaFormatters {
|
|
5
5
|
/** @type {CodeGenConfig} */
|
|
@@ -100,22 +100,22 @@ class SchemaFormatters {
|
|
|
100
100
|
* @param parsedSchema {Record<string, any>}
|
|
101
101
|
* @param formatType {"base" | "inline"}
|
|
102
102
|
*/
|
|
103
|
-
formatSchema = (parsedSchema, formatType =
|
|
103
|
+
formatSchema = (parsedSchema, formatType = "base") => {
|
|
104
104
|
const schemaType =
|
|
105
|
-
_.get(parsedSchema, [
|
|
106
|
-
_.get(parsedSchema, [
|
|
105
|
+
_.get(parsedSchema, ["schemaType"]) ||
|
|
106
|
+
_.get(parsedSchema, ["$parsed", "schemaType"]);
|
|
107
107
|
const formatterFn = _.get(this, [formatType, schemaType]);
|
|
108
108
|
return (formatterFn && formatterFn(parsedSchema)) || parsedSchema;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
formatDescription = (description, inline) => {
|
|
112
|
-
if (!description) return
|
|
112
|
+
if (!description) return "";
|
|
113
113
|
|
|
114
114
|
let prettified = description;
|
|
115
115
|
|
|
116
|
-
prettified = _.replace(prettified, /\*\//g,
|
|
116
|
+
prettified = _.replace(prettified, /\*\//g, "*/");
|
|
117
117
|
|
|
118
|
-
const hasMultipleLines = _.includes(prettified,
|
|
118
|
+
const hasMultipleLines = _.includes(prettified, "\n");
|
|
119
119
|
|
|
120
120
|
if (!hasMultipleLines) return prettified;
|
|
121
121
|
|
|
@@ -124,18 +124,18 @@ class SchemaFormatters {
|
|
|
124
124
|
.split(/\n/g)
|
|
125
125
|
.map((part) => _.trim(part))
|
|
126
126
|
.compact()
|
|
127
|
-
.join(
|
|
127
|
+
.join(" ")
|
|
128
128
|
.valueOf();
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
return _.replace(prettified, /\n$/g,
|
|
131
|
+
return _.replace(prettified, /\n$/g, "");
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
formatObjectContent = (content) => {
|
|
135
135
|
const fields = [];
|
|
136
136
|
|
|
137
137
|
for (const part of content) {
|
|
138
|
-
const extraSpace =
|
|
138
|
+
const extraSpace = " ";
|
|
139
139
|
const result = `${extraSpace}${part.field},\n`;
|
|
140
140
|
|
|
141
141
|
const renderedJsDoc = this.templatesWorker.renderTemplate(
|
|
@@ -146,9 +146,9 @@ class SchemaFormatters {
|
|
|
146
146
|
);
|
|
147
147
|
|
|
148
148
|
const routeNameFromTemplate = renderedJsDoc
|
|
149
|
-
.split(
|
|
149
|
+
.split("\n")
|
|
150
150
|
.map((c) => `${extraSpace}${c}`)
|
|
151
|
-
.join(
|
|
151
|
+
.join("\n");
|
|
152
152
|
|
|
153
153
|
if (routeNameFromTemplate) {
|
|
154
154
|
fields.push(`${routeNameFromTemplate}${result}`);
|
|
@@ -157,7 +157,7 @@ class SchemaFormatters {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
return fields.join(
|
|
160
|
+
return fields.join("");
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const _ = require(
|
|
2
|
-
const { SchemaFormatters } = require(
|
|
3
|
-
const { SchemaUtils } = require(
|
|
4
|
-
const { SchemaParser } = require(
|
|
1
|
+
const _ = require("lodash");
|
|
2
|
+
const { SchemaFormatters } = require("./schema-formatters");
|
|
3
|
+
const { SchemaUtils } = require("./schema-utils");
|
|
4
|
+
const { SchemaParser } = require("./schema-parser");
|
|
5
5
|
|
|
6
6
|
class SchemaParserFabric {
|
|
7
7
|
/** @type {CodeGenConfig} */
|
|
@@ -75,7 +75,7 @@ class SchemaParserFabric {
|
|
|
75
75
|
createParsedComponent = ({ typeName, schema, schemaPath }) => {
|
|
76
76
|
const schemaCopy = _.cloneDeep(schema);
|
|
77
77
|
const customComponent = this.schemaComponentsMap.createComponent(
|
|
78
|
-
this.schemaComponentsMap.createRef([
|
|
78
|
+
this.schemaComponentsMap.createRef(["components", "schemas", typeName]),
|
|
79
79
|
schemaCopy,
|
|
80
80
|
);
|
|
81
81
|
const parsed = this.parseSchema(schemaCopy, null, schemaPath);
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
|
-
const { SCHEMA_TYPES } = require(
|
|
3
|
-
const _ = require(
|
|
4
|
-
const { SchemaFormatters } = require(
|
|
5
|
-
const { SchemaUtils } = require(
|
|
2
|
+
const { SCHEMA_TYPES } = require("../constants.js");
|
|
3
|
+
const _ = require("lodash");
|
|
4
|
+
const { SchemaFormatters } = require("./schema-formatters");
|
|
5
|
+
const { SchemaUtils } = require("./schema-utils");
|
|
6
6
|
const {
|
|
7
7
|
DiscriminatorSchemaParser,
|
|
8
|
-
} = require(
|
|
9
|
-
const { EnumSchemaParser } = require(
|
|
10
|
-
const { ObjectSchemaParser } = require(
|
|
11
|
-
const { PrimitiveSchemaParser } = require(
|
|
12
|
-
const { ComplexSchemaParser } = require(
|
|
13
|
-
const { OneOfSchemaParser } = require(
|
|
14
|
-
const { AllOfSchemaParser } = require(
|
|
15
|
-
const { AnyOfSchemaParser } = require(
|
|
16
|
-
const { NotSchemaParser } = require(
|
|
17
|
-
const { ArraySchemaParser } = require(
|
|
18
|
-
const { sortByProperty } = require(
|
|
8
|
+
} = require("./base-schema-parsers/discriminator");
|
|
9
|
+
const { EnumSchemaParser } = require("./base-schema-parsers/enum");
|
|
10
|
+
const { ObjectSchemaParser } = require("./base-schema-parsers/object");
|
|
11
|
+
const { PrimitiveSchemaParser } = require("./base-schema-parsers/primitive");
|
|
12
|
+
const { ComplexSchemaParser } = require("./base-schema-parsers/complex");
|
|
13
|
+
const { OneOfSchemaParser } = require("./complex-schema-parsers/one-of");
|
|
14
|
+
const { AllOfSchemaParser } = require("./complex-schema-parsers/all-of");
|
|
15
|
+
const { AnyOfSchemaParser } = require("./complex-schema-parsers/any-of");
|
|
16
|
+
const { NotSchemaParser } = require("./complex-schema-parsers/not");
|
|
17
|
+
const { ArraySchemaParser } = require("./base-schema-parsers/array");
|
|
18
|
+
const { sortByProperty } = require("../util/sort-by-property");
|
|
19
19
|
|
|
20
20
|
class SchemaParser {
|
|
21
21
|
/** @type {SchemaParserFabric} */
|
|
@@ -184,7 +184,7 @@ class SchemaParser {
|
|
|
184
184
|
let schemaType = null;
|
|
185
185
|
let parsedSchema = null;
|
|
186
186
|
|
|
187
|
-
if (typeof this.schema ===
|
|
187
|
+
if (typeof this.schema === "string") {
|
|
188
188
|
return this.schema;
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -209,13 +209,13 @@ class SchemaParser {
|
|
|
209
209
|
this.schema.enum.length === 1 &&
|
|
210
210
|
this.schema.enum[0] == null
|
|
211
211
|
) {
|
|
212
|
-
this.logger.debug(
|
|
212
|
+
this.logger.debug("invalid enum schema", this.schema);
|
|
213
213
|
this.schema = { type: this.config.Ts.Keyword.Null };
|
|
214
214
|
}
|
|
215
215
|
// schema is response schema
|
|
216
216
|
if (
|
|
217
|
-
|
|
218
|
-
typeof this.schema[
|
|
217
|
+
"content" in this.schema &&
|
|
218
|
+
typeof this.schema["content"] === "object"
|
|
219
219
|
) {
|
|
220
220
|
const schema = this.extractSchemaFromResponseStruct(this.schema);
|
|
221
221
|
const schemaParser = this.schemaParserFabric.createSchemaParser({
|
|
@@ -254,7 +254,7 @@ class SchemaParser {
|
|
|
254
254
|
Array.isArray(this.schema.$parsed?.content)
|
|
255
255
|
) {
|
|
256
256
|
this.schema.$parsed.content = this.schema.$parsed.content.sort(
|
|
257
|
-
sortByProperty(
|
|
257
|
+
sortByProperty("name"),
|
|
258
258
|
);
|
|
259
259
|
}
|
|
260
260
|
}
|
|
@@ -268,7 +268,7 @@ class SchemaParser {
|
|
|
268
268
|
const parsedSchema = this.parseSchema();
|
|
269
269
|
const formattedSchema = this.schemaFormatters.formatSchema(
|
|
270
270
|
parsedSchema,
|
|
271
|
-
|
|
271
|
+
"inline",
|
|
272
272
|
);
|
|
273
273
|
return formattedSchema.content;
|
|
274
274
|
};
|
|
@@ -277,7 +277,7 @@ class SchemaParser {
|
|
|
277
277
|
const parsedSchema = this.parseSchema();
|
|
278
278
|
const formattedSchema = this.schemaFormatters.formatSchema(
|
|
279
279
|
parsedSchema,
|
|
280
|
-
|
|
280
|
+
"base",
|
|
281
281
|
);
|
|
282
282
|
return formattedSchema.content;
|
|
283
283
|
};
|
|
@@ -286,13 +286,13 @@ class SchemaParser {
|
|
|
286
286
|
const { content, ...extras } = responseStruct;
|
|
287
287
|
|
|
288
288
|
const firstResponse = _.first(_.values(content));
|
|
289
|
-
const firstSchema = _.get(firstResponse,
|
|
289
|
+
const firstSchema = _.get(firstResponse, "schema");
|
|
290
290
|
|
|
291
291
|
if (!firstSchema) return;
|
|
292
292
|
|
|
293
293
|
return {
|
|
294
294
|
...extras,
|
|
295
|
-
..._.omit(firstResponse,
|
|
295
|
+
..._.omit(firstResponse, "schema"),
|
|
296
296
|
...firstSchema,
|
|
297
297
|
};
|
|
298
298
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const _ = require(
|
|
2
|
-
const { SCHEMA_TYPES } = require(
|
|
3
|
-
const { internalCase } = require(
|
|
4
|
-
const { pascalCase } = require(
|
|
5
|
-
const { camelCase } = require(
|
|
1
|
+
const _ = require("lodash");
|
|
2
|
+
const { SCHEMA_TYPES } = require("../constants");
|
|
3
|
+
const { internalCase } = require("../util/internal-case");
|
|
4
|
+
const { pascalCase } = require("../util/pascal-case");
|
|
5
|
+
const { camelCase } = require("lodash");
|
|
6
6
|
|
|
7
7
|
class SchemaUtils {
|
|
8
8
|
/** @type {CodeGenConfig} */
|
|
@@ -33,15 +33,15 @@ class SchemaUtils {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
isRefSchema = (schema) => {
|
|
36
|
-
return !!(schema && schema[
|
|
36
|
+
return !!(schema && schema["$ref"]);
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
getEnumNames = (schema) => {
|
|
40
40
|
return (
|
|
41
|
-
schema[
|
|
42
|
-
schema[
|
|
43
|
-
schema[
|
|
44
|
-
schema[
|
|
41
|
+
schema["x-enumNames"] ||
|
|
42
|
+
schema["xEnumNames"] ||
|
|
43
|
+
schema["x-enumnames"] ||
|
|
44
|
+
schema["x-enum-varnames"]
|
|
45
45
|
);
|
|
46
46
|
};
|
|
47
47
|
|
|
@@ -52,15 +52,15 @@ class SchemaUtils {
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
isPropertyRequired = (name, propertySchema, rootSchema) => {
|
|
55
|
-
if (propertySchema[
|
|
55
|
+
if (propertySchema["x-omitempty"] === false) {
|
|
56
56
|
return true;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const isRequired = _.isBoolean(propertySchema.required)
|
|
60
60
|
? !!propertySchema.required
|
|
61
61
|
: _.isArray(rootSchema.required)
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
? rootSchema.required.includes(name)
|
|
63
|
+
: !!rootSchema.required;
|
|
64
64
|
|
|
65
65
|
if (this.config.convertedFromSwagger2) {
|
|
66
66
|
return typeof propertySchema.nullable === this.config.Ts.Keyword.Undefined
|
|
@@ -74,7 +74,7 @@ class SchemaUtils {
|
|
|
74
74
|
const { nullable, type: schemaType } = schema || {};
|
|
75
75
|
return (
|
|
76
76
|
(nullable ||
|
|
77
|
-
!!_.get(schema,
|
|
77
|
+
!!_.get(schema, "x-nullable") ||
|
|
78
78
|
schemaType === this.config.Ts.Keyword.Null) &&
|
|
79
79
|
_.isString(type) &&
|
|
80
80
|
!type.includes(` ${this.config.Ts.Keyword.Null}`) &&
|
|
@@ -112,7 +112,7 @@ class SchemaUtils {
|
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
checkAndAddRequiredKeys = (schema, resultType) => {
|
|
115
|
-
if (
|
|
115
|
+
if ("$$requiredKeys" in schema && schema.$$requiredKeys.length) {
|
|
116
116
|
this.config.update({
|
|
117
117
|
internalTemplateOptions: {
|
|
118
118
|
addUtilRequiredKeysType: true,
|
|
@@ -261,7 +261,7 @@ class SchemaUtils {
|
|
|
261
261
|
|
|
262
262
|
const typeAlias =
|
|
263
263
|
_.get(this.config.primitiveTypes, [primitiveType, schema.format]) ||
|
|
264
|
-
_.get(this.config.primitiveTypes, [primitiveType,
|
|
264
|
+
_.get(this.config.primitiveTypes, [primitiveType, "$default"]) ||
|
|
265
265
|
this.config.primitiveTypes[primitiveType];
|
|
266
266
|
|
|
267
267
|
if (_.isFunction(typeAlias)) {
|
|
@@ -288,24 +288,24 @@ class SchemaUtils {
|
|
|
288
288
|
|
|
289
289
|
return pascalCase(
|
|
290
290
|
camelCase(
|
|
291
|
-
_.uniq([schemaPath[0], schemaPath[schemaPath.length - 1]]).join(
|
|
291
|
+
_.uniq([schemaPath[0], schemaPath[schemaPath.length - 1]]).join("_"),
|
|
292
292
|
),
|
|
293
293
|
);
|
|
294
294
|
};
|
|
295
295
|
|
|
296
296
|
isConstantSchema(schema) {
|
|
297
|
-
return
|
|
297
|
+
return "const" in schema;
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
formatJsValue = (value) => {
|
|
301
301
|
switch (typeof value) {
|
|
302
|
-
case
|
|
302
|
+
case "string": {
|
|
303
303
|
return this.config.Ts.StringValue(value);
|
|
304
304
|
}
|
|
305
|
-
case
|
|
305
|
+
case "boolean": {
|
|
306
306
|
return this.config.Ts.BooleanValue(value);
|
|
307
307
|
}
|
|
308
|
-
case
|
|
308
|
+
case "number": {
|
|
309
309
|
return this.config.Ts.NumberValue(value);
|
|
310
310
|
}
|
|
311
311
|
default: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { NameResolver } = require(
|
|
1
|
+
const { NameResolver } = require("../../util/name-resolver");
|
|
2
2
|
|
|
3
3
|
class EnumKeyResolver extends NameResolver {
|
|
4
4
|
counter = 1;
|
|
@@ -13,7 +13,7 @@ class EnumKeyResolver extends NameResolver {
|
|
|
13
13
|
(variants[0] && `${variants[0]}${this.counter++}`) ||
|
|
14
14
|
`${this.config.enumKeyResolverName}${this.counter++}`;
|
|
15
15
|
this.logger.debug(
|
|
16
|
-
|
|
16
|
+
"generated fallback type name for enum key - ",
|
|
17
17
|
generatedVariant,
|
|
18
18
|
);
|
|
19
19
|
return generatedVariant;
|