@goast/core 0.2.1 → 0.2.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.
|
@@ -10,10 +10,14 @@ function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
|
|
|
10
10
|
const properties = new Map();
|
|
11
11
|
collectSubSchemaProperties(schema.allOf, properties, required, false);
|
|
12
12
|
collectSubSchemaProperties(schema.anyOf, properties, required, true);
|
|
13
|
-
|
|
13
|
+
const initialAdditionalProperties = schema.kind === 'object' ? schema.additionalProperties : undefined;
|
|
14
|
+
let additionalProperties = initialAdditionalProperties;
|
|
15
|
+
additionalProperties = combineAdditionalProperties(schema.allOf, additionalProperties);
|
|
16
|
+
additionalProperties = combineAdditionalProperties(schema.anyOf, additionalProperties);
|
|
17
|
+
if (properties.size === 0 && initialAdditionalProperties === additionalProperties) {
|
|
14
18
|
return undefined;
|
|
15
19
|
}
|
|
16
|
-
return Object.assign(Object.assign({}, schema), { kind: 'object', type: 'object', anyOf: [], allOf: [], properties: properties, required: required, additionalProperties
|
|
20
|
+
return Object.assign(Object.assign({}, schema), { kind: 'object', type: 'object', anyOf: [], allOf: [], properties: properties, required: required, additionalProperties });
|
|
17
21
|
}
|
|
18
22
|
exports.resolveAnyOfAndAllOf = resolveAnyOfAndAllOf;
|
|
19
23
|
function collectSubSchemaProperties(subSchemas, properties, required, optional) {
|
|
@@ -36,6 +40,56 @@ function collectSubSchemaProperties(subSchemas, properties, required, optional)
|
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
}
|
|
43
|
+
function combineAdditionalProperties(subSchemas, current) {
|
|
44
|
+
if (current === true)
|
|
45
|
+
return true;
|
|
46
|
+
for (const subSchema of subSchemas) {
|
|
47
|
+
if (subSchema.kind === 'object' && subSchema.additionalProperties) {
|
|
48
|
+
if (subSchema.additionalProperties === true)
|
|
49
|
+
return true;
|
|
50
|
+
if (!current) {
|
|
51
|
+
current = subSchema.additionalProperties;
|
|
52
|
+
}
|
|
53
|
+
else if (current && current.id !== subSchema.additionalProperties.id) {
|
|
54
|
+
if (current.kind === 'oneOf') {
|
|
55
|
+
current.oneOf.push(subSchema.additionalProperties);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const id = `schema-${Math.random().toString(36).substring(2)}`;
|
|
59
|
+
current = {
|
|
60
|
+
$ref: undefined,
|
|
61
|
+
$src: current.$src,
|
|
62
|
+
id,
|
|
63
|
+
kind: 'oneOf',
|
|
64
|
+
name: id,
|
|
65
|
+
isNameGenerated: true,
|
|
66
|
+
description: undefined,
|
|
67
|
+
deprecated: false,
|
|
68
|
+
accessibility: 'all',
|
|
69
|
+
enum: undefined,
|
|
70
|
+
const: undefined,
|
|
71
|
+
default: undefined,
|
|
72
|
+
example: undefined,
|
|
73
|
+
nullable: false,
|
|
74
|
+
required: new Set(),
|
|
75
|
+
custom: {},
|
|
76
|
+
not: undefined,
|
|
77
|
+
discriminator: undefined,
|
|
78
|
+
inheritedSchemas: [],
|
|
79
|
+
oneOf: [current, subSchema.additionalProperties],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (subSchema.kind === 'object' || subSchema.kind === 'combined') {
|
|
85
|
+
current = combineAdditionalProperties(subSchema.allOf, current);
|
|
86
|
+
current = combineAdditionalProperties(subSchema.anyOf, current);
|
|
87
|
+
}
|
|
88
|
+
if (current === true)
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return current;
|
|
92
|
+
}
|
|
39
93
|
function hasInvalidSubSchema(subSchemas) {
|
|
40
94
|
return subSchemas.some((x) => x.kind !== 'object' &&
|
|
41
95
|
(x.kind !== 'combined' || (!hasInvalidSubSchema(x.allOf) && !hasInvalidSubSchema(x.anyOf))));
|
|
@@ -7,10 +7,14 @@ export function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
|
|
|
7
7
|
const properties = new Map();
|
|
8
8
|
collectSubSchemaProperties(schema.allOf, properties, required, false);
|
|
9
9
|
collectSubSchemaProperties(schema.anyOf, properties, required, true);
|
|
10
|
-
|
|
10
|
+
const initialAdditionalProperties = schema.kind === 'object' ? schema.additionalProperties : undefined;
|
|
11
|
+
let additionalProperties = initialAdditionalProperties;
|
|
12
|
+
additionalProperties = combineAdditionalProperties(schema.allOf, additionalProperties);
|
|
13
|
+
additionalProperties = combineAdditionalProperties(schema.anyOf, additionalProperties);
|
|
14
|
+
if (properties.size === 0 && initialAdditionalProperties === additionalProperties) {
|
|
11
15
|
return undefined;
|
|
12
16
|
}
|
|
13
|
-
return Object.assign(Object.assign({}, schema), { kind: 'object', type: 'object', anyOf: [], allOf: [], properties: properties, required: required, additionalProperties
|
|
17
|
+
return Object.assign(Object.assign({}, schema), { kind: 'object', type: 'object', anyOf: [], allOf: [], properties: properties, required: required, additionalProperties });
|
|
14
18
|
}
|
|
15
19
|
function collectSubSchemaProperties(subSchemas, properties, required, optional) {
|
|
16
20
|
for (const subSchema of subSchemas) {
|
|
@@ -32,6 +36,56 @@ function collectSubSchemaProperties(subSchemas, properties, required, optional)
|
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
}
|
|
39
|
+
function combineAdditionalProperties(subSchemas, current) {
|
|
40
|
+
if (current === true)
|
|
41
|
+
return true;
|
|
42
|
+
for (const subSchema of subSchemas) {
|
|
43
|
+
if (subSchema.kind === 'object' && subSchema.additionalProperties) {
|
|
44
|
+
if (subSchema.additionalProperties === true)
|
|
45
|
+
return true;
|
|
46
|
+
if (!current) {
|
|
47
|
+
current = subSchema.additionalProperties;
|
|
48
|
+
}
|
|
49
|
+
else if (current && current.id !== subSchema.additionalProperties.id) {
|
|
50
|
+
if (current.kind === 'oneOf') {
|
|
51
|
+
current.oneOf.push(subSchema.additionalProperties);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const id = `schema-${Math.random().toString(36).substring(2)}`;
|
|
55
|
+
current = {
|
|
56
|
+
$ref: undefined,
|
|
57
|
+
$src: current.$src,
|
|
58
|
+
id,
|
|
59
|
+
kind: 'oneOf',
|
|
60
|
+
name: id,
|
|
61
|
+
isNameGenerated: true,
|
|
62
|
+
description: undefined,
|
|
63
|
+
deprecated: false,
|
|
64
|
+
accessibility: 'all',
|
|
65
|
+
enum: undefined,
|
|
66
|
+
const: undefined,
|
|
67
|
+
default: undefined,
|
|
68
|
+
example: undefined,
|
|
69
|
+
nullable: false,
|
|
70
|
+
required: new Set(),
|
|
71
|
+
custom: {},
|
|
72
|
+
not: undefined,
|
|
73
|
+
discriminator: undefined,
|
|
74
|
+
inheritedSchemas: [],
|
|
75
|
+
oneOf: [current, subSchema.additionalProperties],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (subSchema.kind === 'object' || subSchema.kind === 'combined') {
|
|
81
|
+
current = combineAdditionalProperties(subSchema.allOf, current);
|
|
82
|
+
current = combineAdditionalProperties(subSchema.anyOf, current);
|
|
83
|
+
}
|
|
84
|
+
if (current === true)
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return current;
|
|
88
|
+
}
|
|
35
89
|
function hasInvalidSubSchema(subSchemas) {
|
|
36
90
|
return subSchemas.some((x) => x.kind !== 'object' &&
|
|
37
91
|
(x.kind !== 'combined' || (!hasInvalidSubSchema(x.allOf) && !hasInvalidSubSchema(x.anyOf))));
|