@goast/core 0.2.1 → 0.3.0
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 +65 -11
- package/cjs/lib/codegen/config.js +5 -1
- package/cjs/lib/codegen/generator.js +28 -35
- package/cjs/lib/codegen/internal-utils.js +1 -2
- package/cjs/lib/collect/collector.js +1 -2
- package/cjs/lib/collect/helpers.js +2 -3
- package/cjs/lib/internal-utils.js +1 -2
- package/cjs/lib/parse/deref-proxy.js +1 -2
- package/cjs/lib/parse/parser.js +114 -126
- package/cjs/lib/transform/helpers.js +10 -10
- package/cjs/lib/transform/transform-document.js +5 -3
- package/cjs/lib/transform/transform-endpoint.js +35 -10
- package/cjs/lib/transform/transform-schema.js +5 -3
- package/cjs/lib/transform/transformer.js +1 -2
- package/cjs/lib/utils/array.utils.js +1 -2
- package/cjs/lib/utils/class.utils.js +3 -4
- package/cjs/lib/utils/common.utils.js +12 -13
- package/cjs/lib/utils/condition.js +1 -2
- package/cjs/lib/utils/endpoint.utils.js +1 -2
- package/cjs/lib/utils/error.utils.js +1 -2
- package/cjs/lib/utils/file-system.utils.js +21 -26
- package/cjs/lib/utils/generator.utils.js +1 -2
- package/cjs/lib/utils/object.utils.js +1 -2
- package/cjs/lib/utils/schema.utils.js +67 -5
- package/cjs/lib/utils/source-builder.js +5 -3
- package/cjs/lib/utils/string-builder/options.js +3 -0
- package/cjs/lib/utils/string-builder/string-builder.js +1 -1
- package/cjs/lib/utils/string-builder/utils.js +5 -6
- package/cjs/lib/utils/string.utils.js +27 -28
- package/cjs/lib/utils/type.utils.js +2 -3
- package/esm/lib/codegen/config.js +5 -1
- package/esm/lib/codegen/generator.js +28 -35
- package/esm/lib/parse/parser.js +114 -127
- package/esm/lib/transform/transform-document.js +4 -1
- package/esm/lib/transform/transform-endpoint.js +34 -8
- package/esm/lib/transform/transform-schema.js +4 -1
- package/esm/lib/utils/file-system.utils.js +19 -24
- package/esm/lib/utils/schema.utils.js +65 -2
- package/esm/lib/utils/source-builder.js +6 -4
- package/esm/lib/utils/string-builder/options.js +3 -0
- package/esm/lib/utils/string-builder/string-builder.js +1 -1
- package/esm/lib/utils/string.utils.js +7 -7
- package/package.json +6 -5
- package/types/lib/codegen/config.d.ts +8 -0
- package/types/lib/utils/source-builder.d.ts +11 -1
- package/types/lib/utils/string-builder/options.d.ts +8 -2
- package/types/lib/utils/string.utils.types.d.ts +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformEndpoint =
|
|
3
|
+
exports.transformEndpoint = transformEndpoint;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
const transform_schema_1 = require("./transform-schema");
|
|
6
6
|
const internal_utils_1 = require("../internal-utils");
|
|
@@ -8,7 +8,10 @@ function transformEndpoint(context, endpointInfo) {
|
|
|
8
8
|
var _a, _b, _c, _d;
|
|
9
9
|
const apiPath = transformApiPath(context, endpointInfo.path, endpointInfo.pathItem);
|
|
10
10
|
const endpoint = {
|
|
11
|
-
$src:
|
|
11
|
+
$src: {
|
|
12
|
+
...endpointInfo.operation.$src,
|
|
13
|
+
component: endpointInfo.operation,
|
|
14
|
+
},
|
|
12
15
|
$ref: undefined,
|
|
13
16
|
id: context.idGenerator.generateId('endpoint'),
|
|
14
17
|
name: (0, helpers_1.determineEndpointName)(endpointInfo),
|
|
@@ -46,7 +49,6 @@ function transformEndpoint(context, endpointInfo) {
|
|
|
46
49
|
context.endpoints.set(`${endpointInfo.method}:${endpointInfo.path}`, endpoint);
|
|
47
50
|
return endpoint;
|
|
48
51
|
}
|
|
49
|
-
exports.transformEndpoint = transformEndpoint;
|
|
50
52
|
function transformApiPath(context, path, pathItem, isReference = false) {
|
|
51
53
|
var _a, _b;
|
|
52
54
|
const existingPath = context.paths.get(path);
|
|
@@ -58,7 +60,10 @@ function transformApiPath(context, path, pathItem, isReference = false) {
|
|
|
58
60
|
return existing;
|
|
59
61
|
const ref = pathItem.$ref ? transformApiPath(context, path, pathItem.$ref, true) : undefined;
|
|
60
62
|
const apiPath = {
|
|
61
|
-
$src:
|
|
63
|
+
$src: {
|
|
64
|
+
...pathItem.$src,
|
|
65
|
+
component: pathItem,
|
|
66
|
+
},
|
|
62
67
|
$ref: ref,
|
|
63
68
|
id: context.idGenerator.generateId('path'),
|
|
64
69
|
summary: pathItem.summary,
|
|
@@ -89,7 +94,10 @@ function transformParameter(context, parameter) {
|
|
|
89
94
|
const ref = parameter.$ref ? transformParameter(context, parameter.$ref) : undefined;
|
|
90
95
|
const id = context.idGenerator.generateId('parameter');
|
|
91
96
|
const p = {
|
|
92
|
-
$src:
|
|
97
|
+
$src: {
|
|
98
|
+
...parameter.$src,
|
|
99
|
+
component: parameter,
|
|
100
|
+
},
|
|
93
101
|
$ref: ref,
|
|
94
102
|
id: id,
|
|
95
103
|
name: (_a = parameter.name) !== null && _a !== void 0 ? _a : id,
|
|
@@ -114,7 +122,10 @@ function transformRequestBody(context, requestBody) {
|
|
|
114
122
|
return existing;
|
|
115
123
|
const ref = requestBody.$ref ? transformRequestBody(context, requestBody.$ref) : undefined;
|
|
116
124
|
const rb = {
|
|
117
|
-
$src:
|
|
125
|
+
$src: {
|
|
126
|
+
...requestBody.$src,
|
|
127
|
+
component: requestBody,
|
|
128
|
+
},
|
|
118
129
|
$ref: ref,
|
|
119
130
|
id: context.idGenerator.generateId('requestBody'),
|
|
120
131
|
description: requestBody.description,
|
|
@@ -142,7 +153,10 @@ function transformResponse(context, response, status) {
|
|
|
142
153
|
return existing;
|
|
143
154
|
const ref = response.$ref ? transformResponse(context, response.$ref, status) : undefined;
|
|
144
155
|
const r = {
|
|
145
|
-
$src:
|
|
156
|
+
$src: {
|
|
157
|
+
...response.$src,
|
|
158
|
+
component: response,
|
|
159
|
+
},
|
|
146
160
|
$ref: ref,
|
|
147
161
|
id: context.idGenerator.generateId('response'),
|
|
148
162
|
statusCode: Number(status) || undefined,
|
|
@@ -171,7 +185,10 @@ function transformMediaType(context, mediaType, media) {
|
|
|
171
185
|
return existing;
|
|
172
186
|
const ref = mediaType.$ref ? transformMediaType(context, mediaType.$ref, media) : undefined;
|
|
173
187
|
const mt = {
|
|
174
|
-
$src:
|
|
188
|
+
$src: {
|
|
189
|
+
...mediaType.$src,
|
|
190
|
+
component: mediaType,
|
|
191
|
+
},
|
|
175
192
|
$ref: ref,
|
|
176
193
|
id: context.idGenerator.generateId('content'),
|
|
177
194
|
type: media,
|
|
@@ -218,7 +235,11 @@ function transformHeader(context, header, name) {
|
|
|
218
235
|
const id = context.idGenerator.generateId('header');
|
|
219
236
|
if (isSchema(header)) {
|
|
220
237
|
h = {
|
|
221
|
-
$src:
|
|
238
|
+
$src: {
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
240
|
+
...header.$src,
|
|
241
|
+
component: header,
|
|
242
|
+
},
|
|
222
243
|
$ref: ref,
|
|
223
244
|
id,
|
|
224
245
|
name,
|
|
@@ -234,7 +255,11 @@ function transformHeader(context, header, name) {
|
|
|
234
255
|
}
|
|
235
256
|
else {
|
|
236
257
|
h = {
|
|
237
|
-
$src:
|
|
258
|
+
$src: {
|
|
259
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
260
|
+
...header.$src,
|
|
261
|
+
component: header,
|
|
262
|
+
},
|
|
238
263
|
$ref: ref,
|
|
239
264
|
id,
|
|
240
265
|
name,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformSchema =
|
|
3
|
+
exports.transformSchema = transformSchema;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
function transformSchema(context, schema) {
|
|
@@ -39,7 +39,10 @@ function transformSchema(context, schema) {
|
|
|
39
39
|
const id = context.idGenerator.generateId('schema');
|
|
40
40
|
const nameInfo = (0, helpers_1.determineSchemaName)(schema, id);
|
|
41
41
|
const incompleteSchema = {
|
|
42
|
-
$src:
|
|
42
|
+
$src: {
|
|
43
|
+
...schema.$src,
|
|
44
|
+
component: schema,
|
|
45
|
+
},
|
|
43
46
|
$ref: undefined,
|
|
44
47
|
id,
|
|
45
48
|
name: nameInfo.name,
|
|
@@ -76,7 +79,6 @@ function transformSchema(context, schema) {
|
|
|
76
79
|
context.schemas.set(schemaSource, completeSchema);
|
|
77
80
|
return completeSchema;
|
|
78
81
|
}
|
|
79
|
-
exports.transformSchema = transformSchema;
|
|
80
82
|
const schemaTransformers = {
|
|
81
83
|
oneOf: (schema, context) => {
|
|
82
84
|
var _a, _b;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformOpenApi =
|
|
3
|
+
exports.transformOpenApi = transformOpenApi;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
const transform_document_1 = require("./transform-document");
|
|
6
6
|
const transform_endpoint_1 = require("./transform-endpoint");
|
|
@@ -40,4 +40,3 @@ function transformOpenApi(data) {
|
|
|
40
40
|
schemas: Array.from(context.schemas.values()),
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
exports.transformOpenApi = transformOpenApi;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeItems =
|
|
3
|
+
exports.removeItems = removeItems;
|
|
4
4
|
function removeItems(array, predicate) {
|
|
5
5
|
for (let i = array.length - 1; i >= 0; i--) {
|
|
6
6
|
if (predicate(array[i])) {
|
|
@@ -8,4 +8,3 @@ function removeItems(array, predicate) {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
exports.removeItems = removeItems;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.classifyArray = classifyArray;
|
|
4
|
+
exports.isInstanceOf = isInstanceOf;
|
|
5
|
+
exports.getIsInstanceOf = getIsInstanceOf;
|
|
4
6
|
function classifyArray(items, classification) {
|
|
5
7
|
const result = { rest: [] };
|
|
6
8
|
for (const key in classification) {
|
|
@@ -22,12 +24,9 @@ function classifyArray(items, classification) {
|
|
|
22
24
|
}
|
|
23
25
|
return result;
|
|
24
26
|
}
|
|
25
|
-
exports.classifyArray = classifyArray;
|
|
26
27
|
function isInstanceOf(item, type) {
|
|
27
28
|
return item instanceof type;
|
|
28
29
|
}
|
|
29
|
-
exports.isInstanceOf = isInstanceOf;
|
|
30
30
|
function getIsInstanceOf(type) {
|
|
31
31
|
return (item) => item instanceof type;
|
|
32
32
|
}
|
|
33
|
-
exports.getIsInstanceOf = getIsInstanceOf;
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isNullish = isNullish;
|
|
4
|
+
exports.notNullish = notNullish;
|
|
5
|
+
exports.concatSingleOrMultiple = concatSingleOrMultiple;
|
|
6
|
+
exports.isIterable = isIterable;
|
|
7
|
+
exports.toArray = toArray;
|
|
8
|
+
exports.modify = modify;
|
|
9
|
+
exports.run = run;
|
|
10
|
+
exports.transform = transform;
|
|
11
|
+
exports.modifyEach = modifyEach;
|
|
12
|
+
exports.runEach = runEach;
|
|
13
|
+
exports.transformEach = transformEach;
|
|
14
|
+
exports.asVoid = asVoid;
|
|
4
15
|
function isNullish(value) {
|
|
5
16
|
return value === null || value === undefined;
|
|
6
17
|
}
|
|
7
|
-
exports.isNullish = isNullish;
|
|
8
18
|
function notNullish(value) {
|
|
9
19
|
return !isNullish(value);
|
|
10
20
|
}
|
|
11
|
-
exports.notNullish = notNullish;
|
|
12
21
|
function concatSingleOrMultiple(...values) {
|
|
13
22
|
if (values.length === 1) {
|
|
14
23
|
return values[0];
|
|
@@ -24,11 +33,9 @@ function concatSingleOrMultiple(...values) {
|
|
|
24
33
|
}
|
|
25
34
|
return result;
|
|
26
35
|
}
|
|
27
|
-
exports.concatSingleOrMultiple = concatSingleOrMultiple;
|
|
28
36
|
function isIterable(value) {
|
|
29
37
|
return typeof value === 'object' && value !== null && Symbol.iterator in value;
|
|
30
38
|
}
|
|
31
|
-
exports.isIterable = isIterable;
|
|
32
39
|
function toArray(value) {
|
|
33
40
|
if (Array.isArray(value)) {
|
|
34
41
|
return value;
|
|
@@ -38,23 +45,19 @@ function toArray(value) {
|
|
|
38
45
|
}
|
|
39
46
|
return [value];
|
|
40
47
|
}
|
|
41
|
-
exports.toArray = toArray;
|
|
42
48
|
function modify(value, callback) {
|
|
43
49
|
if (notNullish(value)) {
|
|
44
50
|
callback(value);
|
|
45
51
|
}
|
|
46
52
|
return value;
|
|
47
53
|
}
|
|
48
|
-
exports.modify = modify;
|
|
49
54
|
function run(value, callback) {
|
|
50
55
|
callback(value);
|
|
51
56
|
return value;
|
|
52
57
|
}
|
|
53
|
-
exports.run = run;
|
|
54
58
|
function transform(value, callback) {
|
|
55
59
|
return callback(value);
|
|
56
60
|
}
|
|
57
|
-
exports.transform = transform;
|
|
58
61
|
function modifyEach(values, callback) {
|
|
59
62
|
for (const value of values) {
|
|
60
63
|
if (notNullish(value)) {
|
|
@@ -63,14 +66,12 @@ function modifyEach(values, callback) {
|
|
|
63
66
|
}
|
|
64
67
|
return values;
|
|
65
68
|
}
|
|
66
|
-
exports.modifyEach = modifyEach;
|
|
67
69
|
function runEach(values, callback) {
|
|
68
70
|
for (const value of values) {
|
|
69
71
|
callback(value);
|
|
70
72
|
}
|
|
71
73
|
return values;
|
|
72
74
|
}
|
|
73
|
-
exports.runEach = runEach;
|
|
74
75
|
function transformEach(values, callback) {
|
|
75
76
|
const result = [];
|
|
76
77
|
for (const value of values) {
|
|
@@ -78,8 +79,6 @@ function transformEach(values, callback) {
|
|
|
78
79
|
}
|
|
79
80
|
return result;
|
|
80
81
|
}
|
|
81
|
-
exports.transformEach = transformEach;
|
|
82
82
|
function asVoid(_) {
|
|
83
83
|
// Do nothing
|
|
84
84
|
}
|
|
85
|
-
exports.asVoid = asVoid;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evalCondition =
|
|
3
|
+
exports.evalCondition = evalCondition;
|
|
4
4
|
function evalCondition(condition, ctx) {
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
6
6
|
return typeof condition === 'function' ? condition(ctx) : condition;
|
|
7
7
|
}
|
|
8
|
-
exports.evalCondition = evalCondition;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEndpointUrlPreview =
|
|
3
|
+
exports.getEndpointUrlPreview = getEndpointUrlPreview;
|
|
4
4
|
function getEndpointUrlPreview(endpoint) {
|
|
5
5
|
let url = endpoint.path;
|
|
6
6
|
const queryParams = endpoint.parameters.filter((p) => p.target === 'query');
|
|
@@ -9,4 +9,3 @@ function getEndpointUrlPreview(endpoint) {
|
|
|
9
9
|
}
|
|
10
10
|
return url;
|
|
11
11
|
}
|
|
12
|
-
exports.getEndpointUrlPreview = getEndpointUrlPreview;
|
|
@@ -1,40 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.defaultDirectoryScanOptions = void 0;
|
|
4
|
+
exports.getFiles = getFiles;
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const fs_extra_1 = require("fs-extra");
|
|
7
7
|
exports.defaultDirectoryScanOptions = {
|
|
8
8
|
recursive: false,
|
|
9
9
|
maxDepth: 5,
|
|
10
10
|
};
|
|
11
|
-
function getFiles(dir, options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return files;
|
|
17
|
-
});
|
|
11
|
+
async function getFiles(dir, options) {
|
|
12
|
+
const opts = { ...exports.defaultDirectoryScanOptions, ...options };
|
|
13
|
+
const files = [];
|
|
14
|
+
await getFilesImpl(dir, opts, files, 0);
|
|
15
|
+
return files;
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (options.maxDepth && options.maxDepth > currentDepth) {
|
|
29
|
-
getFilesImpl(filePath, options, files, currentDepth + 1);
|
|
30
|
-
}
|
|
17
|
+
async function getFilesImpl(dir, options, files, currentDepth) {
|
|
18
|
+
const dirFiles = await (0, fs_extra_1.readdir)(dir);
|
|
19
|
+
for (const file of dirFiles) {
|
|
20
|
+
const filePath = (0, path_1.resolve)(dir, file);
|
|
21
|
+
const stat = await (0, fs_extra_1.lstat)(filePath);
|
|
22
|
+
if (stat.isDirectory()) {
|
|
23
|
+
if (options.recursive) {
|
|
24
|
+
if (options.maxDepth && options.maxDepth > currentDepth) {
|
|
25
|
+
getFilesImpl(filePath, options, files, currentDepth + 1);
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (!options.filter || options.filter(file)) {
|
|
31
|
+
files.push(filePath);
|
|
37
32
|
}
|
|
38
33
|
}
|
|
39
|
-
}
|
|
34
|
+
}
|
|
40
35
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInitializedValue =
|
|
3
|
+
exports.getInitializedValue = getInitializedValue;
|
|
4
4
|
function getInitializedValue(value) {
|
|
5
5
|
if (value === undefined) {
|
|
6
6
|
throw new Error('Generator not initialized.');
|
|
7
7
|
}
|
|
8
8
|
return value;
|
|
9
9
|
}
|
|
10
|
-
exports.getInitializedValue = getInitializedValue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createOverwriteProxy =
|
|
3
|
+
exports.createOverwriteProxy = createOverwriteProxy;
|
|
4
4
|
function createOverwriteProxy(target, values) {
|
|
5
5
|
const proxy = new Proxy(target, new OverwriteProxyHandler());
|
|
6
6
|
if (values) {
|
|
@@ -8,7 +8,6 @@ function createOverwriteProxy(target, values) {
|
|
|
8
8
|
}
|
|
9
9
|
return proxy;
|
|
10
10
|
}
|
|
11
|
-
exports.createOverwriteProxy = createOverwriteProxy;
|
|
12
11
|
class OverwriteProxyHandler {
|
|
13
12
|
constructor() {
|
|
14
13
|
this._overwrittenValues = {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveAnyOfAndAllOf = resolveAnyOfAndAllOf;
|
|
4
|
+
exports.getSchemaReference = getSchemaReference;
|
|
4
5
|
const internal_utils_1 = require("../internal-utils");
|
|
5
6
|
function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
|
|
6
7
|
if (!ignoreNonObjectParts && (hasInvalidSubSchema(schema.anyOf) || hasInvalidSubSchema(schema.allOf))) {
|
|
@@ -10,12 +11,24 @@ function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
|
|
|
10
11
|
const properties = new Map();
|
|
11
12
|
collectSubSchemaProperties(schema.allOf, properties, required, false);
|
|
12
13
|
collectSubSchemaProperties(schema.anyOf, properties, required, true);
|
|
13
|
-
|
|
14
|
+
const initialAdditionalProperties = schema.kind === 'object' ? schema.additionalProperties : undefined;
|
|
15
|
+
let additionalProperties = initialAdditionalProperties;
|
|
16
|
+
additionalProperties = combineAdditionalProperties(schema.allOf, additionalProperties);
|
|
17
|
+
additionalProperties = combineAdditionalProperties(schema.anyOf, additionalProperties);
|
|
18
|
+
if (properties.size === 0 && initialAdditionalProperties === additionalProperties) {
|
|
14
19
|
return undefined;
|
|
15
20
|
}
|
|
16
|
-
return
|
|
21
|
+
return {
|
|
22
|
+
...schema,
|
|
23
|
+
kind: 'object',
|
|
24
|
+
type: 'object',
|
|
25
|
+
anyOf: [],
|
|
26
|
+
allOf: [],
|
|
27
|
+
properties: properties,
|
|
28
|
+
required: required,
|
|
29
|
+
additionalProperties,
|
|
30
|
+
};
|
|
17
31
|
}
|
|
18
|
-
exports.resolveAnyOfAndAllOf = resolveAnyOfAndAllOf;
|
|
19
32
|
function collectSubSchemaProperties(subSchemas, properties, required, optional) {
|
|
20
33
|
for (const subSchema of subSchemas) {
|
|
21
34
|
if (subSchema.kind === 'object') {
|
|
@@ -36,6 +49,56 @@ function collectSubSchemaProperties(subSchemas, properties, required, optional)
|
|
|
36
49
|
}
|
|
37
50
|
}
|
|
38
51
|
}
|
|
52
|
+
function combineAdditionalProperties(subSchemas, current) {
|
|
53
|
+
if (current === true)
|
|
54
|
+
return true;
|
|
55
|
+
for (const subSchema of subSchemas) {
|
|
56
|
+
if (subSchema.kind === 'object' && subSchema.additionalProperties) {
|
|
57
|
+
if (subSchema.additionalProperties === true)
|
|
58
|
+
return true;
|
|
59
|
+
if (!current) {
|
|
60
|
+
current = subSchema.additionalProperties;
|
|
61
|
+
}
|
|
62
|
+
else if (current && current.id !== subSchema.additionalProperties.id) {
|
|
63
|
+
if (current.kind === 'oneOf') {
|
|
64
|
+
current.oneOf.push(subSchema.additionalProperties);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const id = `schema-${Math.random().toString(36).substring(2)}`;
|
|
68
|
+
current = {
|
|
69
|
+
$ref: undefined,
|
|
70
|
+
$src: current.$src,
|
|
71
|
+
id,
|
|
72
|
+
kind: 'oneOf',
|
|
73
|
+
name: id,
|
|
74
|
+
isNameGenerated: true,
|
|
75
|
+
description: undefined,
|
|
76
|
+
deprecated: false,
|
|
77
|
+
accessibility: 'all',
|
|
78
|
+
enum: undefined,
|
|
79
|
+
const: undefined,
|
|
80
|
+
default: undefined,
|
|
81
|
+
example: undefined,
|
|
82
|
+
nullable: false,
|
|
83
|
+
required: new Set(),
|
|
84
|
+
custom: {},
|
|
85
|
+
not: undefined,
|
|
86
|
+
discriminator: undefined,
|
|
87
|
+
inheritedSchemas: [],
|
|
88
|
+
oneOf: [current, subSchema.additionalProperties],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (subSchema.kind === 'object' || subSchema.kind === 'combined') {
|
|
94
|
+
current = combineAdditionalProperties(subSchema.allOf, current);
|
|
95
|
+
current = combineAdditionalProperties(subSchema.anyOf, current);
|
|
96
|
+
}
|
|
97
|
+
if (current === true)
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return current;
|
|
101
|
+
}
|
|
39
102
|
function hasInvalidSubSchema(subSchemas) {
|
|
40
103
|
return subSchemas.some((x) => x.kind !== 'object' &&
|
|
41
104
|
(x.kind !== 'combined' || (!hasInvalidSubSchema(x.allOf) && !hasInvalidSubSchema(x.anyOf))));
|
|
@@ -52,4 +115,3 @@ function getSchemaReference(schema, propertiesToIgnore) {
|
|
|
52
115
|
const hasPropertiesDefined = Object.keys(schema.$src.originalComponent).some((key) => (0, internal_utils_1.isOpenApiObjectProperty)(key) && !propertiesToIgnore.includes(key));
|
|
53
116
|
return hasPropertiesDefined ? schema : getSchemaReference(schema.$ref, propertiesToIgnore);
|
|
54
117
|
}
|
|
55
|
-
exports.getSchemaReference = getSchemaReference;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.builderTemplate = exports.SourceBuilder = exports.defaultSourceBuilderOptions = void 0;
|
|
4
|
-
const os_1 = require("os");
|
|
5
4
|
const common_utils_1 = require("./common.utils");
|
|
6
5
|
const condition_1 = require("./condition");
|
|
7
6
|
const string_builder_1 = require("./string-builder");
|
|
8
7
|
const string_utils_1 = require("./string.utils");
|
|
8
|
+
/**
|
|
9
|
+
* Default options for the `SourceBuilder` class.
|
|
10
|
+
*/
|
|
9
11
|
exports.defaultSourceBuilderOptions = {
|
|
12
|
+
...string_builder_1.defaultStringBuilderOptions,
|
|
10
13
|
indent: { type: 'spaces', count: 2 },
|
|
11
|
-
newLine: os_1.EOL,
|
|
12
14
|
};
|
|
13
15
|
/**
|
|
14
16
|
* Represents an in-memory source file.
|
|
@@ -30,7 +32,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
30
32
|
this._isLastLineEmpty = true;
|
|
31
33
|
this._isCurrentLineEmpty = true;
|
|
32
34
|
this._linePrefixNodes = [];
|
|
33
|
-
this.__options =
|
|
35
|
+
this.__options = { ...exports.defaultSourceBuilderOptions, ...options };
|
|
34
36
|
this._indentString = this.__options.indent.type === 'tabs' ? '\t' : ' '.repeat(this.__options.indent.count);
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultStringBuilderOptions = void 0;
|
|
4
4
|
const os_1 = require("os");
|
|
5
|
+
/**
|
|
6
|
+
* Default options for the `StringBuilder` class.
|
|
7
|
+
*/
|
|
5
8
|
exports.defaultStringBuilderOptions = {
|
|
6
9
|
newLine: os_1.EOL,
|
|
7
10
|
};
|
|
@@ -20,7 +20,7 @@ class StringBuilder {
|
|
|
20
20
|
*/
|
|
21
21
|
constructor(options) {
|
|
22
22
|
this.str = '';
|
|
23
|
-
this._options =
|
|
23
|
+
this._options = { ...options_1.defaultStringBuilderOptions, ...options };
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Creates a new StringBuilder instance and appends the specified string to it.
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.basicAppendValueGroup = basicAppendValueGroup;
|
|
4
|
+
exports.appendValueGroup = appendValueGroup;
|
|
5
|
+
exports.isAppendValue = isAppendValue;
|
|
6
|
+
exports.isAppendValueGroup = isAppendValueGroup;
|
|
7
|
+
exports.concatAppendValues = concatAppendValues;
|
|
4
8
|
const common_utils_1 = require("../common.utils");
|
|
5
9
|
function basicAppendValueGroup(values, separator) {
|
|
6
10
|
var _a;
|
|
@@ -10,7 +14,6 @@ function basicAppendValueGroup(values, separator) {
|
|
|
10
14
|
separator: separator !== null && separator !== void 0 ? separator : null,
|
|
11
15
|
};
|
|
12
16
|
}
|
|
13
|
-
exports.basicAppendValueGroup = basicAppendValueGroup;
|
|
14
17
|
function appendValueGroup(values, separator) {
|
|
15
18
|
var _a;
|
|
16
19
|
return {
|
|
@@ -19,7 +22,6 @@ function appendValueGroup(values, separator) {
|
|
|
19
22
|
separator: separator !== null && separator !== void 0 ? separator : null,
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
|
-
exports.appendValueGroup = appendValueGroup;
|
|
23
25
|
function isAppendValue(value) {
|
|
24
26
|
return (typeof value === 'string' ||
|
|
25
27
|
typeof value === 'number' ||
|
|
@@ -27,12 +29,9 @@ function isAppendValue(value) {
|
|
|
27
29
|
typeof value === 'function' ||
|
|
28
30
|
isAppendValueGroup(value));
|
|
29
31
|
}
|
|
30
|
-
exports.isAppendValue = isAppendValue;
|
|
31
32
|
function isAppendValueGroup(value) {
|
|
32
33
|
return typeof value === 'object' && value !== null && '__type' in value && value.__type === 'append-value-group';
|
|
33
34
|
}
|
|
34
|
-
exports.isAppendValueGroup = isAppendValueGroup;
|
|
35
35
|
function concatAppendValues(...values) {
|
|
36
36
|
return (0, common_utils_1.concatSingleOrMultiple)(...values);
|
|
37
37
|
}
|
|
38
|
-
exports.concatAppendValues = concatAppendValues;
|