-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[API] patch swagger host to be relative #563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
server/swagger/init.jsIt's a good practice to separate the logic into smaller, more manageable functions. This makes the code easier to read and maintain. In this case, the logic of writing to the file can be extracted into a separate function. function writeToFile(outputFile, data) {
fs.writeFileSync(outputFile, JSON.stringify(data, null, 2), { encoding: 'utf-8', flag: 'w' });
console.log(`Swagger-autogen: \x1b[32mPatched servers.url β\x1b[0m`);
}Using synchronous file operations can block the event loop and negatively impact the performance of your application. It's recommended to use asynchronous file operations whenever possible. fs.writeFile(outputFile, JSON.stringify(openApiSpec, null, 2), { encoding: 'utf-8', flag: 'w' }, (err) => {
if (err) throw err;
console.log(`Swagger-autogen: \x1b[32mPatched servers.url β\x1b[0m`);
}); |
| swaggerAutogen(outputFile, endpointsFiles, doc) | ||
| .then(({ data }) => { | ||
| const openApiSpec = { | ||
| ...data, | ||
| servers: [{ | ||
| url: "/api" | ||
| }] | ||
| } | ||
| fs.writeFileSync(outputFile, JSON.stringify(openApiSpec, null, 2), { encoding: 'utf-8', flag: 'w' }); | ||
| console.log(`Swagger-autogen: \x1b[32mPatched servers.url β\x1b[0m`) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted the logic of writing to the file into a separate function to improve the readability and maintainability of the code.
| swaggerAutogen(outputFile, endpointsFiles, doc) | |
| .then(({ data }) => { | |
| const openApiSpec = { | |
| ...data, | |
| servers: [{ | |
| url: "/api" | |
| }] | |
| } | |
| fs.writeFileSync(outputFile, JSON.stringify(openApiSpec, null, 2), { encoding: 'utf-8', flag: 'w' }); | |
| console.log(`Swagger-autogen: \x1b[32mPatched servers.url β\x1b[0m`) | |
| }) | |
| function writeToFile(outputFile, data) { | |
| fs.writeFileSync(outputFile, JSON.stringify(data, null, 2), { encoding: 'utf-8', flag: 'w' }); | |
| console.log(`Swagger-autogen: \x1b[32mPatched servers.url β\x1b[0m`); | |
| } | |
| swaggerAutogen(outputFile, endpointsFiles, doc) | |
| .then(({ data }) => { | |
| const openApiSpec = { | |
| ...data, | |
| servers: [{ | |
| url: "/api" | |
| }] | |
| } | |
| writeToFile(outputFile, openApiSpec); | |
| }) |
| fs.writeFileSync(outputFile, JSON.stringify(openApiSpec, null, 2), { encoding: 'utf-8', flag: 'w' }); | ||
| console.log(`Swagger-autogen: \x1b[32mPatched servers.url β\x1b[0m`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The synchronous file writing operation has been replaced with an asynchronous one to improve the performance of the application.
| fs.writeFileSync(outputFile, JSON.stringify(openApiSpec, null, 2), { encoding: 'utf-8', flag: 'w' }); | |
| console.log(`Swagger-autogen: \x1b[32mPatched servers.url β\x1b[0m`) | |
| fs.writeFile(outputFile, JSON.stringify(openApiSpec, null, 2), { encoding: 'utf-8', flag: 'w' }, (err) => { | |
| if (err) throw err; | |
| console.log(`Swagger-autogen: \x1b[32mPatched servers.url β\x1b[0m`); | |
| }); |
patch swagger host to be relative
Pull Request Type
Relevant Issues
resolves #561
What is in this change?
Update API to use relative hostname
Developer Validations
yarn lintfrom the root of the repo & committed changes