Last active
July 17, 2023 03:16
-
-
Save dansp89/37130ea4c40aee8e303e717fca80694c to your computer and use it in GitHub Desktop.
Swagger Authorize Button Error on Strapi 4. After installation it will be fixed and the swagger authorization button will be ready for use.. add the swaggerFix.js file to the root of your strapi project
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