Skip to content

Documentation plugin will always write to full_documentation.json #7399

@gh0stsh0t

Description

@gh0stsh0t

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

  1. create a new project with users-permissions and documentation plugin installed
  2. start the server
  3. it should edit full_documentation.json but only changing thex-generation-date info

Expected behavior
If no update has been made, it should not write to the file

Screenshots

image
image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: enhancementIssue suggesting an enhancement to an existing featureseverity: lowIf the issue only affects a very niche base of users and an easily implemented workaround can solvesource: plugin:documentationSource is plugin/documentation package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions