mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2025-04-17 18:18:11 +00:00
[API] patch swagger host to be relative (#563)
patch swagger host to be relative
This commit is contained in:
parent
5b2c0ca782
commit
755c10b8ca
2 changed files with 17 additions and 3 deletions
server/swagger
|
@ -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`)
|
||||
})
|
|
@ -7,7 +7,7 @@
|
|||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "http:///api/"
|
||||
"url": "/api"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
|
|
Loading…
Add table
Reference in a new issue