Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asyncapi/parser

Package Overview
Dependencies
Maintainers
3
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asyncapi/parser - npm Package Compare versions

Comparing version 0.16.1 to 0.16.2

test/nested-schemas.json

56

lib/models/asyncapi.js

@@ -143,2 +143,3 @@ const { createMapOfType, getMapKeyOfType, addExtensions } = require('../utils');

const messages = new Map();
if (this.hasChannels()) {

@@ -159,2 +160,3 @@ this.channelNames().forEach(channelName => {

}
if (this.hasComponents()) {

@@ -165,2 +167,3 @@ Object.values(this.components().messages()).forEach(m => {

}
return messages;

@@ -174,41 +177,14 @@ }

const schemas = new Map();
if (this.hasChannels()) {
this.channelNames().forEach(channelName => {
const channel = this.channel(channelName);
Object.values(channel.parameters()).forEach(p => {
if (p.schema()) {
schemas.set(p.schema().uid(), p.schema());
}
});
if (channel.hasPublish()) {
channel.publish().messages().forEach(m => {
if (m.headers()) {
schemas.set(m.headers().uid(), m.headers());
}
if (m.payload()) {
schemas.set(m.payload().uid(), m.payload());
}
});
}
if (channel.hasSubscribe()) {
channel.subscribe().messages().forEach(m => {
if (m.headers()) {
schemas.set(m.headers().uid(), m.headers());
}
if (m.payload()) {
schemas.set(m.payload().uid(), m.payload());
}
});
}
});
}
const callback = (schema) => {
if (schema.uid()) {
schemas.set(schema.uid(), schema);
}
};
schemaDocument(this, callback);
if (this.hasComponents()) {
Object.values(this.components().schemas()).forEach(s => {
schemas.set(s.uid(), s);
recursiveSchema(s, callback);
});
}
return schemas;

@@ -218,3 +194,2 @@ }

function assignNameToComponentMessages(doc) {

@@ -256,2 +231,8 @@ if (doc.hasComponents()) {

}
/**
* Assign anonymous names to nameless messages.
*
* @param {AsyncAPIDocument} doc
*/
function assignNameToAnonymousMessages(doc) {

@@ -292,3 +273,4 @@ let anonymousMessageCounter = 0;

callback(schema);
if (schema.type() !== null) {
if (schema.type() !== undefined) {
switch (schema.type()) {

@@ -295,0 +277,0 @@ case 'object':

{
"name": "@asyncapi/parser",
"version": "0.16.1",
"version": "0.16.2",
"description": "JavaScript AsyncAPI parser.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

const { expect } = require('chai');
const AsyncAPIDocument = require('../../lib/models/asyncapi');
const fs = require('fs');
const path = require("path");
describe('AsyncAPIDocument', () => {

@@ -17,5 +18,5 @@ describe('assignUidToParameterSchemas()', () => {

const d = new AsyncAPIDocument(doc);
expect(d.ext('x-test')).to.be.equal(doc['x-test']);
expect(d.ext('x-test')).to.be.equal(doc['x-test']);
expect(d.extension('x-test')).to.be.equal(doc['x-test']);
expect(d.extensions()).to.be.deep.equal({'x-test': 'testing'});
expect(d.extensions()).to.be.deep.equal({ 'x-test': 'testing' });
});

@@ -26,3 +27,3 @@ });

it('should return an info object', () => {
const doc = { info: { title: 'Test', version: '1.2.3', license: { name: 'Apache 2.0', url: 'https://www.apache.org/licenses/LICENSE-2.0' } }};
const doc = { info: { title: 'Test', version: '1.2.3', license: { name: 'Apache 2.0', url: 'https://www.apache.org/licenses/LICENSE-2.0' } } };
const d = new AsyncAPIDocument(doc);

@@ -33,3 +34,3 @@ expect(d.info().constructor.name).to.be.equal('Info');

});
describe('#id()', function () {

@@ -65,3 +66,3 @@ it('should return the id string', () => {

});
describe('#server()', function () {

@@ -74,3 +75,3 @@ it('should return a specific server object', () => {

});
it('should return null if a server name is not provided', () => {

@@ -81,3 +82,3 @@ const doc = { servers: { test1: { url: 'test1' }, test2: { url: 'test2' } } };

});
it('should return null if a server name is not found', () => {

@@ -173,3 +174,3 @@ const doc = { servers: { test1: { url: 'test1' }, test2: { url: 'test2' } } };

});
describe('#allMessages()', function () {

@@ -194,5 +195,5 @@ it('should return an array with all the messages used in the document and overwrite the message from channel', () => {

});
describe('#allSchemas()', function () {
it('should return an array with all the schemas used in the document', () => {
it('should return a map with all the schemas used in the document', () => {
const doc = { channels: { test: { parameters: { testParam1: { schema: { $id: 'testParamSchema', test: true, k: 0 } } }, publish: { message: { headers: { test: true, k: 1 }, payload: { test: true, k: 2 } } } }, test2: { subscribe: { message: { payload: { $id: 'testPayload', test: true, k: 2 } } } } }, components: { schemas: { testSchema: { test: true, k: 3 } } } };

@@ -212,3 +213,3 @@ const d = new AsyncAPIDocument(doc);

])
for(const t of schemas.values()){
for (const t of schemas.values()) {
expect(t.constructor.name).to.be.equal('Schema');

@@ -218,3 +219,41 @@ expect(t.json().test).to.be.equal(true);

});
it('should return a map with all the nested schemas', () => {
const doc = JSON.parse(fs.readFileSync(path.resolve(__dirname, "../nested-schemas.json"), 'utf8'));
const d = new AsyncAPIDocument(doc);
const schemas = d.allSchemas();
//Ensure the actual keys are as expected
const schemaKeys = Array.from(schemas.keys());
console.log(schemaKeys);
expect(schemaKeys).to.deep.equal([
"testParamSchema",
"testParamNestedSchemaProp",
"testParamNestedNestedSchemaProp2",
"testHeaderSchema",
"testHeaderNestedSchemaProp",
"testHeaderNestedNestedSchemaProp1",
"testHeaderNestedSchemaPropArray",
"testHeaderNestedSchemaPropArrayProp1",
"testPayloadSchema",
"testPayloadNestedSchemaProp",
"testPayloadNestedNestedSchemaProp1",
"testPayloadNestedSchemaPropArray",
"testPayloadNestedSchemaPropArrayProp1",
"testPayload",
"testComponentSchemaSchema",
"testComponentSchemaNestedSchemaPropAllOf",
"testComponentSchemaNestedSchemaPropAllOfSchema1",
"testComponentSchemaNestedSchemaPropAllOfSchema1Prop1",
"testComponentSchemaNestedSchemaPropAllOfSchema2",
"testComponentSchemaNestedSchemaPropAllOfSchema2Prop1",
"testComponentSchemaNestedSchemaPropArray",
"testComponentSchemaNestedSchemaPropArrayProp1",
"testComponentSchemaNestedSchemaPropArrayProp2"
])
for (const t of schemas.values()) {
expect(t.constructor.name).to.be.equal('Schema');
expect(t.json().test).to.be.equal(true);
}
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc