θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content

Conversation

@timothycarambat
Copy link
Member

Pull Request Type

  • ✨ feat
  • πŸ› fix
  • ♻️ refactor
  • πŸ’„ style
  • πŸ”¨ chore
  • πŸ“ docs

Relevant Issues

resolves #561

What is in this change?

Update API to use relative hostname

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

@review-agent-prime
Copy link

server/swagger/init.js

It'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.
Create Issue
See the diff
Checkout the fix

    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`);
    }
git fetch origin && git checkout -b ReviewBot/Impro-0ch3ngp origin/ReviewBot/Impro-0ch3ngp

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.
Create Issue
See the diff
Checkout the fix

    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`);
    });
git fetch origin && git checkout -b ReviewBot/Impro-9npy1k5 origin/ReviewBot/Impro-9npy1k5

Comment on lines +41 to +51
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`)
})

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.

Suggested change
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);
})

Comment on lines +49 to +50
fs.writeFileSync(outputFile, JSON.stringify(openApiSpec, null, 2), { encoding: 'utf-8', flag: 'w' });
console.log(`Swagger-autogen: \x1b[32mPatched servers.url βœ”\x1b[0m`)

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.

Suggested change
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`);
});

@timothycarambat timothycarambat merged commit 755c10b into master Jan 10, 2024
@timothycarambat timothycarambat deleted the 561-relative-api-docs-url branch January 10, 2024 03:49
cabwds pushed a commit to cabwds/anything-llm that referenced this pull request Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Documentation URL incorrect on remote hosting

2 participants