-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
Describe the bug
Every time strapi-plugin-documentation/config/functions/bootstrap.js runs, it will write to full_documentation.json even if no update is created.
Steps to reproduce the behavior
- create a new project with users-permissions and documentation plugin installed
- start the server
- it should edit full_documentation.json but only changing the
x-generation-dateinfo
Expected behavior
If no update has been made, it should not write to the file
Screenshots
Code snippets
when bootstrap.js runs, it will almost always enter this condition
// strapi-plugin-documentation/config/functions/bootstrap.js: line 101
if (!isMergedDocumentationExists || shouldUpdateFullDoc) {
// Create the folder
services.createDocumentationDirectory(documentationPath);
// Write the file
fs.writeFileSync(
path.resolve(documentationPath, 'full_documentation.json'),
JSON.stringify(fullDoc, null, 2),
'utf8'
);
}as caused by checkIfPluginDocNeedsUpdate returning true when checking the "users-permissions" plugin, as it has 2 tags: UsersPermissions - User and UsersPermissions - Role
// strapi-plugin-documentation/config/functions/bootstrap.js: line 38
const needToUpdatePluginDoc = services.checkIfPluginDocNeedsUpdate(plugin);this happens because createDocObject() uses _.merge() which doesnt work if there is a property that contains an array, as it will override the array. Thus only one tag can appear in the object. To fix that the function should be changed to mergeWith that has a customizer for array values
// strapi-plugin-documentation/services/Documentation.js
// from
createDocObject: array => {
return array.reduce((acc, curr) => _.merge(acc, curr), {});
},
// to
createDocObject: array => {
function forArray(objValue, srcValue) {
if (_.isArray(objValue)) {
return objValue.concat(srcValue);
}
}
return array.reduce((acc, curr) => _.mergeWith(acc, curr,forArray), {});
},however this raises another error in the areObjectsEquals() function as it simply does return JSON.stringify(obj1) === JSON.stringify(obj2); to check for equality and will fail if the arrays don't have the exact same order
System
- Docker image: strapi/strapi:3.1.3
- Node.js version: v12
- NPM version:
- Strapi version: 3.1.3
- Database: MongoDB
- Operating system: Linux

