Files
fielderp-server/documentation/index.js
T

68 lines
1.4 KiB
JavaScript

import path from "path";
import fs from "fs";
import upload from "./upload.js";
import user from "./user.js";
import profile from "./profile.js";
import admin from "./admin.js";
import location from "./location.js"
const GENERAL_CONFIG = {
openapi: "3.0.1",
info: {
title: "Attica Server Application v1",
description: "Version 1 of Attica Server Application API",
license: {
name: "MIT",
url: "https://opensource.org/licenses/MIT",
},
version: "1.0.0",
},
servers: [
{
url: "http://localhost:3000/v0/",
},
{
url: "https://erp-server.triadkube.com/v0/",
},
],
security: [
{
bearerAuth: [],
},
],
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
},
},
};
let paths = {
...user,
...profile,
...location,
...upload,
...admin,
};
const getSwaggerDocument = () => {
const swaggerDocument = {
...GENERAL_CONFIG,
paths,
};
const fileContent = JSON.stringify(swaggerDocument, null, 2);
const docPath = path.resolve(path.join(__dirname, "documentation.json"));
const existingContent = fs.readFileSync(docPath, "utf8");
if (existingContent !== fileContent) {
console.log("Swagger documentation updated");
fs.writeFileSync(docPath, fileContent);
}
};
export default getSwaggerDocument;