Skip to content
Snippets Groups Projects
Unverified Commit 755c10b8 authored by Timothy Carambat's avatar Timothy Carambat Committed by GitHub
Browse files

[API] patch swagger host to be relative (#563)

patch swagger host to be relative
parent 5b2c0ca7
No related branches found
No related tags found
No related merge requests found
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)
\ No newline at end of file
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`)
})
\ No newline at end of file
......@@ -7,7 +7,7 @@
},
"servers": [
{
"url": "http:///api/"
"url": "/api"
}
],
"paths": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment