47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const yaml = require('yaml');
|
|
|
|
|
|
const definition = {
|
|
openapi: '3.0.0',
|
|
info: {
|
|
title: 'ERP API',
|
|
version: '1.0.0',
|
|
description: 'Phase 1 - PO, GRN, Vendor, Assets, Masters, Users & RBAC',
|
|
},
|
|
servers: [{ url: '/api/v1' }],
|
|
components: {
|
|
securitySchemes: { bearerAuth: { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' } },
|
|
schemas: {},
|
|
},
|
|
security: [{ bearerAuth: [] }],
|
|
tags: [],
|
|
paths: {},
|
|
};
|
|
|
|
const docsDir = path.join(__dirname, '../docs');
|
|
|
|
if (fs.existsSync(docsDir)) {
|
|
for (const file of fs.readdirSync(docsDir)) {
|
|
if (!/\.ya?ml$/i.test(file)) continue;
|
|
|
|
const doc = yaml.parse(fs.readFileSync(path.join(docsDir, file), 'utf8'));
|
|
if (!doc) continue;
|
|
|
|
if (doc.tags?.length) {
|
|
definition.tags.push(...doc.tags);
|
|
}
|
|
|
|
if (doc.components?.schemas) {
|
|
Object.assign(definition.components.schemas, doc.components.schemas);
|
|
}
|
|
|
|
if (doc.paths) {
|
|
Object.assign(definition.paths, doc.paths);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = definition;
|