Created
July 17, 2023 03:15
-
-
Save dansp89/57a716b4ab373af3cbefad3b0a3f2d2e to your computer and use it in GitHub Desktop.
Swagger Authorize Button Error on Strapi 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// other here | |
"scripts": { | |
"postinstall": "node swaggerFix.js", | |
// others here | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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