mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
fix(tests): handle nested allOf blocks
This commit is contained in:
20
test/api.js
20
test/api.js
@@ -117,7 +117,7 @@ describe('API', async () => {
|
|||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
meta.config.allowTopicsThumbnail = 1;
|
meta.config.allowTopicsThumbnail = 1;
|
||||||
meta.config.termsOfUse = 'I, for one, welcome our new test-drive overlords';
|
meta.config.termsOfUse = 'I, for one, welcome our new test-driven overlords';
|
||||||
|
|
||||||
// Create a category
|
// Create a category
|
||||||
const testCategory = await categories.create({ name: 'test' });
|
const testCategory = await categories.create({ name: 'test' });
|
||||||
@@ -446,12 +446,20 @@ describe('API', async () => {
|
|||||||
let required = [];
|
let required = [];
|
||||||
const additionalProperties = schema.hasOwnProperty('additionalProperties');
|
const additionalProperties = schema.hasOwnProperty('additionalProperties');
|
||||||
|
|
||||||
if (schema.allOf) {
|
function flattenAllOf(obj) {
|
||||||
schema = schema.allOf.reduce((memo, obj) => {
|
return obj.reduce((memo, obj) => {
|
||||||
required = required.concat(obj.required ? obj.required : Object.keys(obj.properties));
|
if (obj.allOf) {
|
||||||
memo = { ...memo, ...obj.properties };
|
obj = { properties: flattenAllOf(obj.allOf) };
|
||||||
return memo;
|
} else {
|
||||||
|
required = required.concat(obj.required ? obj.required : Object.keys(obj.properties));
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...memo, ...obj.properties };
|
||||||
}, {});
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema.allOf) {
|
||||||
|
schema = flattenAllOf(schema.allOf);
|
||||||
} else if (schema.properties) {
|
} else if (schema.properties) {
|
||||||
required = schema.required || Object.keys(schema.properties);
|
required = schema.required || Object.keys(schema.properties);
|
||||||
schema = schema.properties;
|
schema = schema.properties;
|
||||||
|
|||||||
Reference in New Issue
Block a user