adonis5-swagger
Version:
Swagger provider for AdonisJS 5
34 lines (33 loc) • 1.49 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const standalone_1 = require("@adonisjs/core/build/standalone");
const buildJsDocConfig_1 = __importDefault(require("../src/Utils/buildJsDocConfig"));
const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
const fs_1 = require("fs");
const path_1 = require("path");
class GenerateSwaggerFile extends standalone_1.BaseCommand {
constructor(application, kernel) {
super(application, kernel);
this.config = application.container.use('Adonis/Core/Config');
}
/**
* Execute command
*/
async run() {
const swaggerFileContent = (0, swagger_jsdoc_1.default)((0, buildJsDocConfig_1.default)(this.config.get('swagger.options', {})));
if (!this.config.get('swagger.specFilePath')) {
throw new Error("Config option 'swagger.specFilePath' should be specified for using this command");
}
const filePath = (0, path_1.join)(this.application.appRoot, this.config.get('swagger.specFilePath'));
await fs_1.promises.writeFile(filePath, JSON.stringify(swaggerFileContent));
}
}
exports.default = GenerateSwaggerFile;
GenerateSwaggerFile.commandName = 'swagger:generate';
GenerateSwaggerFile.description = 'Generate swagger file';
GenerateSwaggerFile.settings = {
loadApp: true,
};