[API] patch swagger host to be relative ()

patch swagger host to be relative
This commit is contained in:
Timothy Carambat 2024-01-09 19:49:51 -08:00 committed by GitHub
parent 5b2c0ca782
commit 755c10b8ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions
server/swagger

View file

@ -1,4 +1,6 @@
const swaggerAutogen = require('swagger-autogen')({ openapi: '3.0.0' });
const fs = require('fs')
const path = require('path')
const doc = {
info: {
@ -6,6 +8,8 @@ const doc = {
title: 'AnythingLLM Developer API',
description: 'API endpoints that enable programmatic reading, writing, and updating of your AnythingLLM instance. UI supplied by Swagger.io.',
},
// Swagger-autogen does not allow us to use relative paths as these will resolve to
// http:///api in the openapi.json file, so we need to monkey-patch this post-generation.
host: '/api',
schemes: ['http'],
securityDefinitions: {
@ -25,7 +29,7 @@ const doc = {
}
};
const outputFile = './openapi.json';
const outputFile = path.resolve(__dirname, './openapi.json');
const endpointsFiles = [
'../endpoints/api/auth/index.js',
'../endpoints/api/admin/index.js',
@ -34,4 +38,14 @@ const endpointsFiles = [
'../endpoints/api/system/index.js',
];
swaggerAutogen(outputFile, endpointsFiles, doc)
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`)
})

View file

@ -7,7 +7,7 @@
},
"servers": [
{
"url": "http:///api/"
"url": "/api"
}
],
"paths": {