@ivamuno/nestjs-openapi
Version:
52 lines (51 loc) • 2.36 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncApiExplorer = void 0;
const core_1 = require("@nestjs/core");
const _1 = require(".");
const explorers_1 = require("./explorers");
class AsyncApiExplorer {
constructor() {
this.metadataScanner = new core_1.MetadataScanner();
this.schemas = [];
this.schemaRefsStack = [];
this.operationIdFactory = (controllerKey, methodKey) => (controllerKey ? `${controllerKey}_${methodKey}` : methodKey);
}
exploreChannel(wrapper, modulePath, globalPrefix, operationIdFactory) {
if (operationIdFactory) {
this.operationIdFactory = operationIdFactory;
}
const { instance, metatype } = wrapper;
if (!instance || !metatype || !Reflect.getMetadataKeys(metatype).find(x => x === _1.DECORATORS.ASYNCAPI_CHANNEL)) {
return [];
}
const prototype = Object.getPrototypeOf(instance);
const documentResolvers = {
root: [explorers_1.exploreAsyncapiChannelMetadata],
security: [],
tags: [],
operations: [explorers_1.exploreAsyncapiOperationMetadata],
};
return this.generateDenormalizedDocument(metatype, prototype, instance, documentResolvers, modulePath, globalPrefix);
}
getSchemas() {
return this.schemas;
}
generateDenormalizedDocument(metatype, prototype, instance, documentResolvers, _modulePath, _globalPrefix) {
const denormalizedChannels = this.metadataScanner.scanFromPrototype(instance, prototype, name => {
const targetCallback = prototype[name];
const methodMetadata = documentResolvers.root.reduce((_metadata, fn) => {
const channelMetadata = fn(metatype);
return {
root: Object.assign(channelMetadata, { name: channelMetadata.name }),
operations: documentResolvers.operations.reduce((_metadata2, fn2) => {
return fn2(this.schemas, this.schemaRefsStack, instance, prototype, targetCallback);
}, {}),
};
}, {});
return methodMetadata;
});
return denormalizedChannels;
}
}
exports.AsyncApiExplorer = AsyncApiExplorer;
;