diff --git a/src/adapters/mqtt/index.ts b/src/adapters/mqtt/index.ts index fe1ec54d6..40b9453ff 100644 --- a/src/adapters/mqtt/index.ts +++ b/src/adapters/mqtt/index.ts @@ -43,19 +43,22 @@ class MqttAdapter extends Adapter { private getSecurityReqs() { - const parsedSecurityScehemes = this.parsedAsyncAPI.components().securitySchemes().all() - let userAndPasswordSecurityReq let X509SecurityReq - for (const security of parsedSecurityScehemes) { - if (security.type() === 'userPassword') { - userAndPasswordSecurityReq = security - } - if (security.type() === 'x509') { - X509SecurityReq = security + const securityRequirements = this.AsyncAPIServer.security().map(e => e.map(e => e.scheme())) + + securityRequirements.forEach(sec => { + for (const security of sec) { + if(security.type() === 'userPassword') { + userAndPasswordSecurityReq = security + } + + if (security.type() === 'x509') { + X509SecurityReq = security + } } - } + }) return { userAndPasswordSecurityReq, diff --git a/src/index.ts b/src/index.ts index 0d6cd42b7..1c08c499f 100755 --- a/src/index.ts +++ b/src/index.ts @@ -79,34 +79,33 @@ export default async function GleeAppInitializer() { channelNames.forEach((channelName) => { const channel = parsedAsyncAPI.channels().get(channelName) - if (channel.operations().filterBySend().length !==0) { - const operationId = channel.operations()[0].operationId() - const publishOperation = channel.operations().filterBySend()[0] - if (operationId) { - const schema = { - oneOf: publishOperation - .messages() - .map(m => m.payload().json()), - } as any - app.use(channelName, validate(schema), (event, next) => { - triggerFunction({ - app, - operationId, - message: event, + if (channel.operations().filterByReceive().length !==0) { + + channel.operations().filterByReceive().forEach(operation => { + const receiveOperation = operation + const operationId = operation.operationId() + if (operationId) { + const schema = { + onOf: receiveOperation.messages().filterByReceive().map(m => m.payload()) + } as any + app.use(channelName, validate(schema), (event, next) => { + triggerFunction({ + app, + operationId, + message: event + }).then(next).catch(next) }) - .then(next) - .catch(next) - }) - } + } + }) } - if (channel.operations().filterByReceive().length !== 0) { - const subscribeOperation = channel.operations().filterByReceive()[0] - const schema = { - oneOf: subscribeOperation - .messages() - .map(m => m.payload().json()), - } as any - app.useOutbound(channelName, validate(schema), json2string) + if (channel.operations().filterBySend().length !== 0) { + channel.operations().filterBySend().forEach(operation => { + const sendOperation = operation + const schema = { + onOf: sendOperation.messages().filterBySend().map(m => m.payload()) + } as any + app.useOutbound(channelName, validate(schema), json2string) + }) } }) diff --git a/src/lib/servers.ts b/src/lib/servers.ts index 947d9b50a..3626bc833 100644 --- a/src/lib/servers.ts +++ b/src/lib/servers.ts @@ -8,7 +8,7 @@ export async function getSelectedServerNames(): Promise { } const arrayOfNames = process.env.GLEE_SERVER_NAMES.split(',') - return parsedAsyncAPI.servers().all().map(e => e.url()).filter((name) => { + return parsedAsyncAPI.servers().all().map(e => e.id()).filter((name) => { return arrayOfNames.includes(name) }) }