@tsed/schema 8.15.0 → 8.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/utils/mergeSchema.js +49 -29
- package/package.json +7 -7
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cleanObject } from "@tsed/core/utils/cleanObject.js";
|
|
2
|
+
import { isObject } from "@tsed/core/utils/isObject.js";
|
|
3
|
+
import { uniq } from "@tsed/core/utils/uniq.js";
|
|
2
4
|
function mergeProps(properties1, properties2) {
|
|
3
5
|
if (!properties1 || !properties2) {
|
|
4
6
|
return properties1 || properties2 || {};
|
|
@@ -17,40 +19,58 @@ function mergeProps(properties1, properties2) {
|
|
|
17
19
|
return acc;
|
|
18
20
|
}, {});
|
|
19
21
|
}
|
|
22
|
+
function getSchemaType(schema) {
|
|
23
|
+
return schema.type || (schema.items && "array") || ((schema.properties || schema.additionalProperties) && "object") || "$any";
|
|
24
|
+
}
|
|
20
25
|
function mergeManyOf(kind, schema1, schema2) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
const { [kind]: kind1, ...$rest1 } = schema1;
|
|
27
|
+
const { [kind]: kind2, ...$rest2 } = schema2;
|
|
28
|
+
let hasRef = false;
|
|
29
|
+
const map = [kind1, $rest1, kind2, $rest2]
|
|
30
|
+
.flat()
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
.reduce((map, schema, index) => {
|
|
33
|
+
schema = cleanObject(schema);
|
|
34
|
+
if (schema.$ref) {
|
|
35
|
+
hasRef = true;
|
|
36
|
+
return map.set(schema.$ref, schema);
|
|
37
|
+
}
|
|
38
|
+
if (Object.keys(schema).length === 0) {
|
|
39
|
+
return map;
|
|
33
40
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
of = of.reduce((current, item, index) => {
|
|
38
|
-
if (item.$ref) {
|
|
39
|
-
return current.concat(item);
|
|
41
|
+
if (schema.type === "object" && Object.keys(schema).length === 2) {
|
|
42
|
+
if ("writeOnly" in schema || "readOnly" in schema || "deprecated" in schema) {
|
|
43
|
+
schema = { ...schema, type: undefined };
|
|
40
44
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
}
|
|
46
|
+
const type = getSchemaType(schema);
|
|
47
|
+
if (type === "array") {
|
|
48
|
+
map.set("array_" + index, schema);
|
|
49
|
+
return map;
|
|
50
|
+
}
|
|
51
|
+
if (map.has(type)) {
|
|
52
|
+
if (kind === "allOf") {
|
|
53
|
+
// we can merge allOf schemas to optimize the schema
|
|
54
|
+
map.set(type, mergeSchema(map.get(type), schema));
|
|
55
|
+
return map;
|
|
44
56
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
map.set(type + "_" + index, schema);
|
|
58
|
+
return map;
|
|
59
|
+
}
|
|
60
|
+
return map.set(type, schema);
|
|
61
|
+
}, new Map());
|
|
62
|
+
const rest = map.get("$any");
|
|
63
|
+
map.delete("$any");
|
|
64
|
+
const of = Array.from(map.values());
|
|
65
|
+
return cleanObject(of.length > 1 || (hasRef && rest)
|
|
49
66
|
? {
|
|
50
|
-
|
|
51
|
-
|
|
67
|
+
...rest,
|
|
68
|
+
[kind]: of
|
|
52
69
|
}
|
|
53
|
-
:
|
|
70
|
+
: {
|
|
71
|
+
...rest,
|
|
72
|
+
...of[0]
|
|
73
|
+
});
|
|
54
74
|
}
|
|
55
75
|
export function mergeSchema(schema1, schema2) {
|
|
56
76
|
if (schema1.$ref && schema2.$ref && schema1.$ref === schema2.$ref) {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/schema",
|
|
3
3
|
"description": "JsonSchema module for Ts.ED Framework",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.15.
|
|
5
|
+
"version": "8.15.2",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"tsed"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@tsed/openspec": "8.15.
|
|
37
|
+
"@tsed/openspec": "8.15.2",
|
|
38
38
|
"change-case": "^5.4.4",
|
|
39
39
|
"json-schema": "0.4.0",
|
|
40
40
|
"picomatch": "4.0.2",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@apidevtools/swagger-parser": "10.1.0",
|
|
46
|
-
"@tsed/barrels": "8.15.
|
|
47
|
-
"@tsed/core": "8.15.
|
|
48
|
-
"@tsed/hooks": "8.15.
|
|
49
|
-
"@tsed/openspec": "8.15.
|
|
50
|
-
"@tsed/typescript": "8.15.
|
|
46
|
+
"@tsed/barrels": "8.15.2",
|
|
47
|
+
"@tsed/core": "8.15.2",
|
|
48
|
+
"@tsed/hooks": "8.15.2",
|
|
49
|
+
"@tsed/openspec": "8.15.2",
|
|
50
|
+
"@tsed/typescript": "8.15.2",
|
|
51
51
|
"@types/fs-extra": "11.0.4",
|
|
52
52
|
"@types/json-schema": "7.0.15",
|
|
53
53
|
"@types/picomatch": "3.0.2",
|