Skip to content

Instantly share code, notes, and snippets.

@smoya
Last active October 12, 2022 09:29
Show Gist options
  • Save smoya/895956043828f7ae1b75c0669d062afc to your computer and use it in GitHub Desktop.
Save smoya/895956043828f7ae1b75c0669d062afc to your computer and use it in GitHub Desktop.
AsyncAPI Parser-JS example coded in the CCOSS 2022 Workshop: "Vamos a Generar Código y Documentación con AsyncAPI" - https://www.youtube.com/watch?v=qdHymBvBLZQ
const parser = require('@asyncapi/parser');
const fs = require('fs');
const path = require('path');
async function parse(content) {
const doc = await parser.parse(content);
console.log("Hola! Bienvenida/o a", doc.info().title());
console.log("Servers:");
Object.entries(doc.servers()).forEach((server) => {
console.log(`- ${server[0]}`, `(${server[1].url()})`);
});
console.log("Channels:");
Object.entries(doc.channels()).forEach((channel) => {
console.log(`- ${channel[0]}`);
});
}
const doc = fs.readFileSync(path.resolve(__dirname, './asyncapi.yaml'), 'utf-8');
parse(doc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment