documentation icon indicating copy to clipboard operation
documentation copied to clipboard

[Bug]: Why is the documentation extension (OpenAPI) generating the wrong data type?

Open tigfamon opened this issue 3 years ago • 4 comments

Link to the documentation page or resource

https://forum.strapi.io/t/why-is-the-documentation-extension-openapi-generating-the-wrong-data-type/5750

Describe the bug

See https://forum.strapi.io/t/why-is-the-documentation-extension-openapi-generating-the-wrong-data-type/5750

Additional context

  "dependencies": {
    "@strapi/plugin-documentation": "4.1.8",
    "@strapi/plugin-i18n": "4.1.8",
    "@strapi/plugin-seo": "1.7.2",
    "@strapi/plugin-users-permissions": "4.1.8",
    "@strapi/strapi": "4.1.8",
    "pg": "8.6.0",
    "strapi-plugin-react-editorjs": "2.0.0"
  },

Suggested improvements or fixes

No response

Related issue(s)/PR(s)

No response

tigfamon avatar Apr 19 '22 14:04 tigfamon

For correct work of types generate (https://github.com/acacode/swagger-typescript-api) I have written a function that I run before codegenerator:

const fs = require('fs');
const path = require('path');

const schemaPath = path.resolve(__dirname, './schema.json');
const pathsToFix = ['/some-single-type-path-1', '/some-single-type-path-2'];

function fixSchemaManual() {
  const jsonContent = fs.readFileSync(schemaPath);
  const data = JSON.parse(jsonContent);

  Object.keys(data.paths).forEach((key) => {
    if (pathsToFix.includes(key)) {
      const prev = {
        ...data.paths[key].get.responses['200'].content['application/json']
          .schema.properties.data,
      };
      data.paths[key].get.responses['200'].content[
        'application/json'
      ].schema.properties.data = {
        type: 'object',
        properties: prev.items.properties,
      };
    }
  });

  fs.writeFileSync(schemaPath, JSON.stringify(data));
}

module.exports = fixSchemaManual;

And use this function:

const path = require('path');
const { generateApi } = require('swagger-typescript-api');
const fixSchemaManual = require('./fix_schema_manual');

fixSchemaManual();
generateApi({...});

tigfamon avatar Apr 20 '22 09:04 tigfamon

Hello @tigfamon, I am a technical writer at Strapi. I am a bit confused by your post because it has v4 dependencies but the linked issue on the forum has v3 system information listed. Could you clarify that you are having a problem with the v4 Documentation plugin? Thanks!

stb13579 avatar Apr 20 '22 16:04 stb13579

Hi @StrapiShaun ! Sorry for a confuse. This bug is relevant for the 4.1.8 version.

tigfamon avatar Apr 21 '22 11:04 tigfamon

@tigfamon, I have passed this to one of our devs that was already working on improving the Documentation plugin. I will leave this issue open and update you once there is a pull request covering the topic. Thanks for reporting the problem, it helps us improve the documentation for the whole community.

stb13579 avatar Apr 21 '22 13:04 stb13579

Closing this one as the API Documentation plugin docs were updated by Strapi core developers. https://github.com/strapi/documentation/pull/1622

pwizla avatar Jul 21 '23 13:07 pwizla