@dooboostore/simple-boot-http-server
Version:
back end http server frameworks
57 lines • 2.52 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { HttpStatus } from '../codes/HttpStatus';
import { getUrlMappings } from '../decorators/MethodMapping';
const DefulatData = {
openapi: '3.0.1',
info: {
title: 'SimpleBootHttpServer OpenApi3',
description: 'SimpleBootHttpServer OpenApi3',
}
};
export class OpenApi3Filter {
constructor(config, openApiConfig) {
this.config = config;
this.openApiConfig = Object.assign(Object.assign({}, DefulatData), openApiConfig !== null && openApiConfig !== void 0 ? openApiConfig : {});
}
onInit(app) {
return __awaiter(this, void 0, void 0, function* () {
});
}
proceedBefore(_a) {
return __awaiter(this, arguments, void 0, function* ({ rr, app }) {
if (rr.reqUrl === this.config.path) {
const map = app.routerManager.routingMap();
const data = {
paths: {}
};
Object.entries(map).filter(([k, v]) => typeof v !== 'string').forEach(([k, v]) => {
var _a;
const method = data.paths[k] = {};
(_a = getUrlMappings(v)) === null || _a === void 0 ? void 0 : _a.forEach(it => {
method[it.config.method] = {
summary: it.propertyKey,
description: it.propertyKey
};
});
});
rr.resWriteJson(Object.assign(Object.assign({}, this.openApiConfig), data)).resStatusCode(HttpStatus.Ok).resEnd();
return false;
}
return true;
});
}
proceedAfter(_a) {
return __awaiter(this, arguments, void 0, function* ({ rr, app }) {
return true;
});
}
}
//# sourceMappingURL=OpenApi3Filter.js.map