Skip to content

Instantly share code, notes, and snippets.

@dansp89
Created July 17, 2023 03:15
Show Gist options
  • Save dansp89/57a716b4ab373af3cbefad3b0a3f2d2e to your computer and use it in GitHub Desktop.
Save dansp89/57a716b4ab373af3cbefad3b0a3f2d2e to your computer and use it in GitHub Desktop.
Swagger Authorize Button Error on Strapi 4
{
// other here
"scripts": {
"postinstall": "node swaggerFix.js",
// others here
}
}
/**
* Fix bug in Strapi 4
* Swagger Authorize Button Error
* Source: <https://github.com/strapi/strapi/pull/16788/commits/23de7e699cb88de94dbf87c9ea9f265a1415fe7a>
*/
const fs = require('fs');
const path = require('path');
const filePath = path.resolve(__dirname, '../node_modules/@strapi/plugin-documentation/server/services/documentation.js');
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
const newString = data.replace(
/if \(generatedSchemas\) \{\s+draft\.components = \{\s+schemas: \{ \.\.\.draft\.components\.schemas, \.\.\.generatedSchemas \},\s+\};\s+\}/,
'draft.components.schemas = { ...draft.components.schemas, ...generatedSchemas };'
);
fs.writeFile(filePath, newString, 'utf8', (err) => {
if (err) {
console.error(err);
return;
}
console.log('Fixed with success!');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment