Skip to content

Commit 64a1336

Browse files
authored
feat: release for version 2.3.0 of the spec (#433)
1 parent 6a964ec commit 64a1336

File tree

8 files changed

+230
-25
lines changed

8 files changed

+230
-25
lines changed

API.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
* [.hasExt(key)](#module_@asyncapi/parser+Channel+hasExt) ⇒ <code>boolean</code>
8383
* [.ext(key)](#module_@asyncapi/parser+Channel+ext) ⇒ <code>any</code>
8484
* [.Components](#module_@asyncapi/parser+Components) ⇐ <code>Base</code>
85+
* [.channels()](#module_@asyncapi/parser+Components+channels) ⇒ <code>Object.&lt;string, Channel&gt;</code>
86+
* [.hasChannels()](#module_@asyncapi/parser+Components+hasChannels) ⇒ <code>boolean</code>
87+
* [.channel(name)](#module_@asyncapi/parser+Components+channel) ⇒ <code>Channel</code>
8588
* [.messages()](#module_@asyncapi/parser+Components+messages) ⇒ <code>Object.&lt;string, Message&gt;</code>
8689
* [.hasMessages()](#module_@asyncapi/parser+Components+hasMessages) ⇒ <code>boolean</code>
8790
* [.message(name)](#module_@asyncapi/parser+Components+message) ⇒ <code>Message</code>
@@ -91,6 +94,9 @@
9194
* [.securitySchemes()](#module_@asyncapi/parser+Components+securitySchemes) ⇒ <code>Object.&lt;string, SecurityScheme&gt;</code>
9295
* [.hasSecuritySchemes()](#module_@asyncapi/parser+Components+hasSecuritySchemes) ⇒ <code>boolean</code>
9396
* [.securityScheme(name)](#module_@asyncapi/parser+Components+securityScheme) ⇒ <code>SecurityScheme</code>
97+
* [.servers()](#module_@asyncapi/parser+Components+servers) ⇒ <code>Object.&lt;string, Server&gt;</code>
98+
* [.hasServers()](#module_@asyncapi/parser+Components+hasServers) ⇒ <code>boolean</code>
99+
* [.server(name)](#module_@asyncapi/parser+Components+server) ⇒ <code>Server</code>
94100
* [.parameters()](#module_@asyncapi/parser+Components+parameters) ⇒ <code>Object.&lt;string, ChannelParameter&gt;</code>
95101
* [.hasParameters()](#module_@asyncapi/parser+Components+hasParameters) ⇒ <code>boolean</code>
96102
* [.parameter(name)](#module_@asyncapi/parser+Components+parameter) ⇒ <code>ChannelParameter</code>
@@ -787,6 +793,9 @@ Implements functions to deal with a Components object.
787793
**Mixes**: [<code>MixinSpecificationExtensions</code>](#MixinSpecificationExtensions)
788794

789795
* [.Components](#module_@asyncapi/parser+Components) ⇐ <code>Base</code>
796+
* [.channels()](#module_@asyncapi/parser+Components+channels) ⇒ <code>Object.&lt;string, Channel&gt;</code>
797+
* [.hasChannels()](#module_@asyncapi/parser+Components+hasChannels) ⇒ <code>boolean</code>
798+
* [.channel(name)](#module_@asyncapi/parser+Components+channel) ⇒ <code>Channel</code>
790799
* [.messages()](#module_@asyncapi/parser+Components+messages) ⇒ <code>Object.&lt;string, Message&gt;</code>
791800
* [.hasMessages()](#module_@asyncapi/parser+Components+hasMessages) ⇒ <code>boolean</code>
792801
* [.message(name)](#module_@asyncapi/parser+Components+message) ⇒ <code>Message</code>
@@ -796,6 +805,9 @@ Implements functions to deal with a Components object.
796805
* [.securitySchemes()](#module_@asyncapi/parser+Components+securitySchemes) ⇒ <code>Object.&lt;string, SecurityScheme&gt;</code>
797806
* [.hasSecuritySchemes()](#module_@asyncapi/parser+Components+hasSecuritySchemes) ⇒ <code>boolean</code>
798807
* [.securityScheme(name)](#module_@asyncapi/parser+Components+securityScheme) ⇒ <code>SecurityScheme</code>
808+
* [.servers()](#module_@asyncapi/parser+Components+servers) ⇒ <code>Object.&lt;string, Server&gt;</code>
809+
* [.hasServers()](#module_@asyncapi/parser+Components+hasServers) ⇒ <code>boolean</code>
810+
* [.server(name)](#module_@asyncapi/parser+Components+server) ⇒ <code>Server</code>
799811
* [.parameters()](#module_@asyncapi/parser+Components+parameters) ⇒ <code>Object.&lt;string, ChannelParameter&gt;</code>
800812
* [.hasParameters()](#module_@asyncapi/parser+Components+hasParameters) ⇒ <code>boolean</code>
801813
* [.parameter(name)](#module_@asyncapi/parser+Components+parameter) ⇒ <code>ChannelParameter</code>
@@ -817,6 +829,23 @@ Implements functions to deal with a Components object.
817829
* [.hasExt(key)](#module_@asyncapi/parser+Components+hasExt) ⇒ <code>boolean</code>
818830
* [.ext(key)](#module_@asyncapi/parser+Components+ext) ⇒ <code>any</code>
819831

832+
<a name="module_@asyncapi/parser+Components+channels"></a>
833+
834+
#### components.channels() ⇒ <code>Object.&lt;string, Channel&gt;</code>
835+
**Kind**: instance method of [<code>Components</code>](#module_@asyncapi/parser+Components)
836+
<a name="module_@asyncapi/parser+Components+hasChannels"></a>
837+
838+
#### components.hasChannels() ⇒ <code>boolean</code>
839+
**Kind**: instance method of [<code>Components</code>](#module_@asyncapi/parser+Components)
840+
<a name="module_@asyncapi/parser+Components+channel"></a>
841+
842+
#### components.channel(name) ⇒ <code>Channel</code>
843+
**Kind**: instance method of [<code>Components</code>](#module_@asyncapi/parser+Components)
844+
845+
| Param | Type | Description |
846+
| --- | --- | --- |
847+
| name | <code>string</code> | Name of the channel. |
848+
820849
<a name="module_@asyncapi/parser+Components+messages"></a>
821850

822851
#### components.messages() ⇒ <code>Object.&lt;string, Message&gt;</code>
@@ -868,6 +897,23 @@ Implements functions to deal with a Components object.
868897
| --- | --- | --- |
869898
| name | <code>string</code> | Name of the security schema. |
870899

900+
<a name="module_@asyncapi/parser+Components+servers"></a>
901+
902+
#### components.servers() ⇒ <code>Object.&lt;string, Server&gt;</code>
903+
**Kind**: instance method of [<code>Components</code>](#module_@asyncapi/parser+Components)
904+
<a name="module_@asyncapi/parser+Components+hasServers"></a>
905+
906+
#### components.hasServers() ⇒ <code>boolean</code>
907+
**Kind**: instance method of [<code>Components</code>](#module_@asyncapi/parser+Components)
908+
<a name="module_@asyncapi/parser+Components+server"></a>
909+
910+
#### components.server(name) ⇒ <code>Server</code>
911+
**Kind**: instance method of [<code>Components</code>](#module_@asyncapi/parser+Components)
912+
913+
| Param | Type | Description |
914+
| --- | --- | --- |
915+
| name | <code>string</code> | Name of the server. |
916+
871917
<a name="module_@asyncapi/parser+Components+parameters"></a>
872918

873919
#### components.parameters() ⇒ <code>Object.&lt;string, ChannelParameter&gt;</code>

dist/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/asyncapiSchemaFormatParser.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,13 @@ async function parse({ message, originalAsyncAPIDocument, fileFormat, parsedAsyn
4444
*/
4545
function getMimeTypes() {
4646
return [
47-
'application/vnd.aai.asyncapi;version=2.0.0',
48-
'application/vnd.aai.asyncapi;version=2.1.0',
49-
'application/vnd.aai.asyncapi;version=2.2.0',
50-
'application/vnd.aai.asyncapi+json;version=2.0.0',
51-
'application/vnd.aai.asyncapi+json;version=2.1.0',
52-
'application/vnd.aai.asyncapi+json;version=2.2.0',
53-
'application/vnd.aai.asyncapi+yaml;version=2.0.0',
54-
'application/vnd.aai.asyncapi+yaml;version=2.1.0',
55-
'application/vnd.aai.asyncapi+yaml;version=2.2.0',
56-
'application/schema;version=draft-07',
57-
'application/schema+json;version=draft-07',
58-
'application/schema+yaml;version=draft-07',
47+
...['2.0.0', '2.1.0', '2.2.0', '2.3.0'].map((version) => {
48+
return [
49+
`application/vnd.aai.asyncapi;version=${version}`,
50+
`application/vnd.aai.asyncapi+json;version=${version}`,
51+
`application/vnd.aai.asyncapi+yaml;version=${version}`,
52+
];
53+
}).flat().concat(['application/schema;version=draft-07', 'application/schema+json;version=draft-07', 'application/schema+yaml;version=draft-07'])
5954
];
6055
}
6156

lib/models/components.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const { createMapOfType, getMapValueOfType, mix } = require('./utils');
22

33
const Base = require('./base');
4+
const Channel = require('./channel');
45
const Message = require('./message');
56
const Schema = require('./schema');
67
const SecurityScheme = require('./security-scheme');
8+
const Server = require('./server');
79
const ChannelParameter = require('./channel-parameter');
810
const CorrelationId = require('./correlation-id');
911
const OperationTrait = require('./operation-trait');
@@ -20,6 +22,28 @@ const MixinSpecificationExtensions = require('../mixins/specification-extensions
2022
* @returns {Components}
2123
*/
2224
class Components extends Base {
25+
/**
26+
* @returns {Object<string, Channel>}
27+
*/
28+
channels() {
29+
return createMapOfType(this._json.channels, Channel);
30+
}
31+
32+
/**
33+
* @returns {boolean}
34+
*/
35+
hasChannels() {
36+
return !!this._json.channels;
37+
}
38+
39+
/**
40+
* @param {string} name - Name of the channel.
41+
* @returns {Channel}
42+
*/
43+
channel(name) {
44+
return getMapValueOfType(this._json.channels, name, Channel);
45+
}
46+
2347
/**
2448
* @returns {Object<string, Message>}
2549
*/
@@ -85,6 +109,28 @@ class Components extends Base {
85109
securityScheme(name) {
86110
return getMapValueOfType(this._json.securitySchemes, name, SecurityScheme);
87111
}
112+
113+
/**
114+
* @returns {Object<string, Server>}
115+
*/
116+
servers() {
117+
return createMapOfType(this._json.servers, Server);
118+
}
119+
120+
/**
121+
* @returns {boolean}
122+
*/
123+
hasServers() {
124+
return !!this._json.servers;
125+
}
126+
127+
/**
128+
* @param {string} name - Name of the server.
129+
* @returns {Server}
130+
*/
131+
server(name) {
132+
return getMapValueOfType(this._json.servers, name, Server);
133+
}
88134

89135
/**
90136
* @returns {Object<string, ChannelParameter>}

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@asyncapi/parser",
3-
"version": "1.13.2",
3+
"version": "1.14.0-2022-01-release.3",
44
"description": "JavaScript AsyncAPI parser.",
55
"main": "lib/index.js",
66
"types": "types.d.ts",
@@ -67,7 +67,7 @@
6767
},
6868
"dependencies": {
6969
"@apidevtools/json-schema-ref-parser": "^9.0.6",
70-
"@asyncapi/specs": "^2.11.0",
70+
"@asyncapi/specs": "^2.13.0",
7171
"@fmvilas/pseudo-yaml-ast": "^0.3.1",
7272
"ajv": "^6.10.1",
7373
"js-yaml": "^3.13.1",
@@ -88,7 +88,7 @@
8888
"branches": [
8989
"master",
9090
{
91-
"name": "2021-09-release",
91+
"name": "2022-01-release",
9292
"prerelease": true
9393
}
9494
],

test/models/components_test.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,57 @@ const Components = require('../../lib/models/components');
55
const { assertMixinSpecificationExtensionsInheritance } = require('../mixins/specification-extensions_test');
66

77
describe('Components', function() {
8+
describe('#channels()', function() {
9+
it('should return a map of Channel objects', function() {
10+
const doc = { channels: { test1: { description: 'test1' }, test2: { description: 'test2' } } };
11+
const d = new Components(doc);
12+
expect(typeof d.channels()).to.be.equal('object');
13+
expect(d.channels().test1.constructor.name).to.equal('Channel');
14+
expect(d.channels().test1.json()).to.equal(doc.channels.test1);
15+
expect(d.channels().test2.constructor.name).to.equal('Channel');
16+
expect(d.channels().test2.json()).to.equal(doc.channels.test2);
17+
});
18+
19+
it('should return an empty object if the components field has no defined channels', function() {
20+
const doc = {};
21+
const d = new Components(doc);
22+
expect(typeof d.channels()).to.be.equal('object');
23+
expect(d.channels()).to.deep.equal({});
24+
});
25+
});
26+
27+
describe('#hasChannels()', function() {
28+
it('should return a boolean indicating if the components field has channels', function() {
29+
const doc = { channels: { test1: { description: 'test1' }, test2: { description: 'test2' } } };
30+
const docNoChannels = { schemas: {} };
31+
const d = new Components(doc);
32+
const d2 = new Components(docNoChannels);
33+
expect(d.hasChannels()).to.equal(true);
34+
expect(d2.hasChannels()).to.equal(false);
35+
});
36+
});
37+
38+
describe('#channel()', function() {
39+
it('should return a specific Channel object', function() {
40+
const doc = { channels: { test1: { description: 'test1' }, test2: { description: 'test2' } } };
41+
const d = new Components(doc);
42+
expect(d.channel('test1').constructor.name).to.equal('Channel');
43+
expect(d.channel('test1').json()).to.equal(doc.channels.test1);
44+
});
45+
46+
it('should return null if a channel name is not provided', function() {
47+
const doc = { channels: { test1: { description: 'test1' }, test2: { description: 'test2' } } };
48+
const d = new Components(doc);
49+
expect(d.channel()).to.equal(null);
50+
});
51+
52+
it('should return null if a channel name is not found', function() {
53+
const doc = { channels: { test1: { description: 'test1' }, test2: { description: 'test2' } } };
54+
const d = new Components(doc);
55+
expect(d.channel('not found')).to.equal(null);
56+
});
57+
});
58+
859
describe('#messages()', function() {
960
it('should return a map of Message objects', function() {
1061
const doc = { messages: { test1: { test: 'test1' }, test2: { test: 'test2' } } };
@@ -157,6 +208,57 @@ describe('Components', function() {
157208
expect(d.securityScheme('not found')).to.equal(null);
158209
});
159210
});
211+
212+
describe('#servers()', function() {
213+
it('should return a map of Server objects', function() {
214+
const doc = { servers: { test1: { url: 'test1' }, test2: { url: 'test2' } } };
215+
const d = new Components(doc);
216+
expect(typeof d.servers()).to.be.equal('object');
217+
expect(d.servers().test1.constructor.name).to.equal('Server');
218+
expect(d.servers().test1.json()).to.equal(doc.servers.test1);
219+
expect(d.servers().test2.constructor.name).to.equal('Server');
220+
expect(d.servers().test2.json()).to.equal(doc.servers.test2);
221+
});
222+
223+
it('should return an empty object if the components field has no defined servers', function() {
224+
const doc = {};
225+
const d = new Components(doc);
226+
expect(typeof d.servers()).to.be.equal('object');
227+
expect(d.servers()).to.deep.equal({});
228+
});
229+
});
230+
231+
describe('#hasServers()', function() {
232+
it('should return a boolean indicating if the components field has servers', function() {
233+
const doc = { servers: { test1: { url: 'test1' }, test2: { url: 'test2' } } };
234+
const docNoServers = { schemas: {} };
235+
const d = new Components(doc);
236+
const d2 = new Components(docNoServers);
237+
expect(d.hasServers()).to.equal(true);
238+
expect(d2.hasServers()).to.equal(false);
239+
});
240+
});
241+
242+
describe('#server()', function() {
243+
it('should return a specific Server object', function() {
244+
const doc = { servers: { test1: { url: 'test1' }, test2: { url: 'test2' } } };
245+
const d = new Components(doc);
246+
expect(d.server('test1').constructor.name).to.equal('Server');
247+
expect(d.server('test1').json()).to.equal(doc.servers.test1);
248+
});
249+
250+
it('should return null if a message name is not provided', function() {
251+
const doc = { servers: { test1: { url: 'test1' }, test2: { url: 'test2' } } };
252+
const d = new Components(doc);
253+
expect(d.server()).to.equal(null);
254+
});
255+
256+
it('should return null if a message name is not found', function() {
257+
const doc = { servers: { test1: { url: 'test1' }, test2: { url: 'test2' } } };
258+
const d = new Components(doc);
259+
expect(d.server('not found')).to.equal(null);
260+
});
261+
});
160262

161263
describe('#parameters()', function() {
162264
it('should return a map of ChannelParameter objects', function() {

0 commit comments

Comments
 (0)