@asyncapi/converter 0.8.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -4
- package/cli.js +18 -6
- package/lib/convert.d.ts +3 -0
- package/lib/convert.js +198 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +5 -212
- package/lib/interfaces.d.ts +7 -0
- package/lib/interfaces.js +2 -0
- package/lib/utils.d.ts +21 -0
- package/lib/utils.js +114 -0
- package/package.json +21 -6
- package/.github/workflows/add-good-first-issue-labels.yml +0 -68
- package/.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml +0 -54
- package/.github/workflows/automerge-for-humans-merging.yml +0 -32
- package/.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml +0 -35
- package/.github/workflows/automerge-orphans.yml +0 -63
- package/.github/workflows/automerge.yml +0 -50
- package/.github/workflows/autoupdate.yml +0 -32
- package/.github/workflows/bump.yml +0 -33
- package/.github/workflows/help-command.yml +0 -43
- package/.github/workflows/if-go-pr-testing.yml +0 -68
- package/.github/workflows/if-nodejs-pr-testing.yml +0 -60
- package/.github/workflows/if-nodejs-release.yml +0 -85
- package/.github/workflows/if-nodejs-version-bump.yml +0 -48
- package/.github/workflows/issues-prs-notifications.yml +0 -72
- package/.github/workflows/lint-pr-title.yml +0 -22
- package/.github/workflows/notify-tsc-members-mention.yml +0 -142
- package/.github/workflows/release-announcements.yml +0 -76
- package/.github/workflows/sentiment-analysis.yml +0 -44
- package/.github/workflows/stale-issues-prs.yml +0 -42
- package/.github/workflows/welcome-first-time-contrib.yml +0 -83
- package/CODEOWNERS +0 -8
- package/lib/helpers.js +0 -109
- package/test/index.js +0 -257
- package/test/input/1.0.0/streetlights.yml +0 -120
- package/test/input/1.1.0/streetlights.yml +0 -120
- package/test/input/1.2.0/gitter-streaming.yml +0 -140
- package/test/input/1.2.0/slack-rtm.yml +0 -876
- package/test/input/1.2.0/streetlights.yml +0 -120
- package/test/input/2.0.0/streetlights.json +0 -172
- package/test/input/2.0.0/streetlights.yml +0 -112
- package/test/input/2.0.0-rc1/streetlights.yml +0 -109
- package/test/input/2.0.0-rc2/streetlights.yml +0 -112
- package/test/input/2.1.0/streetlights.yml +0 -112
- package/test/input/2.2.0/streetlights.yml +0 -112
- package/test/output/2.0.0/gitter-streaming.yml +0 -137
- package/test/output/2.0.0/slack-rtm.yml +0 -879
- package/test/output/2.0.0/streetlights.yml +0 -112
- package/test/output/2.0.0-rc1/gitter-streaming.yml +0 -137
- package/test/output/2.0.0-rc1/slack-rtm.yml +0 -879
- package/test/output/2.0.0-rc1/streetlights.yml +0 -109
- package/test/output/2.0.0-rc2/gitter-streaming.yml +0 -137
- package/test/output/2.0.0-rc2/slack-rtm.yml +0 -879
- package/test/output/2.0.0-rc2/streetlights.yml +0 -112
- package/test/output/2.1.0/streetlights.json +0 -172
- package/test/output/2.1.0/streetlights.yml +0 -112
- package/test/output/2.2.0/streetlights.yml +0 -112
- package/test/output/2.3.0/streetlights.yml +0 -112
package/lib/helpers.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash');
|
|
2
|
-
const yaml = require('js-yaml');
|
|
3
|
-
const helpers = module.exports;
|
|
4
|
-
|
|
5
|
-
helpers.serialize = (text) => {
|
|
6
|
-
if (typeof text === 'object') {
|
|
7
|
-
return {
|
|
8
|
-
isYAML: false,
|
|
9
|
-
parsed: text,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const maybeJSON = JSON.parse(text);
|
|
15
|
-
if (typeof maybeJSON === 'object') {
|
|
16
|
-
return {
|
|
17
|
-
isYAML: false,
|
|
18
|
-
parsed: maybeJSON,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// if `maybeJSON` is object, then we have 100% sure that we operate on JSON,
|
|
23
|
-
// but if it's `string` then we have option that it can be YAML but it doesn't have to be
|
|
24
|
-
return {
|
|
25
|
-
isYAML: true,
|
|
26
|
-
parsed: yaml.safeLoad(text)
|
|
27
|
-
};
|
|
28
|
-
} catch (e) {
|
|
29
|
-
try {
|
|
30
|
-
// try to parse again YAML, because the text itself may not have a JSON representation and cannot be represented as a JSON object/string
|
|
31
|
-
return {
|
|
32
|
-
isYAML: true,
|
|
33
|
-
parsed: yaml.safeLoad(text)
|
|
34
|
-
};
|
|
35
|
-
} catch (err) {
|
|
36
|
-
throw new Error('AsyncAPI document must be a valid JSON or YAML document.');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
helpers.dotsToSlashes = topic => topic.replace(/\./g, '/');
|
|
42
|
-
|
|
43
|
-
helpers.eventToChannel = event => {
|
|
44
|
-
const out = {};
|
|
45
|
-
if (event.receive) {
|
|
46
|
-
out.publish = {
|
|
47
|
-
message: {
|
|
48
|
-
oneOf: event.receive
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (event.send) {
|
|
53
|
-
out.subscribe = {
|
|
54
|
-
message: {
|
|
55
|
-
oneOf: event.send
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return out;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
helpers.streamToChannel = event => {
|
|
64
|
-
const out = {};
|
|
65
|
-
if (event.read) {
|
|
66
|
-
out.publish = {
|
|
67
|
-
message: {
|
|
68
|
-
oneOf: event.read
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (event.write) {
|
|
73
|
-
out.subscribe = {
|
|
74
|
-
message: {
|
|
75
|
-
oneOf: event.write
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return out;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const objectToSchema = obj => {
|
|
84
|
-
const schema = { type: 'object', properties: {} };
|
|
85
|
-
_.each(obj, (prop, propName) => {
|
|
86
|
-
schema.properties[propName] = prop;
|
|
87
|
-
});
|
|
88
|
-
return obj;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
helpers.convertMessage = message => {
|
|
92
|
-
if (message.oneOf) {
|
|
93
|
-
message.oneOf.forEach(m => {
|
|
94
|
-
if (m.protocolInfo) {
|
|
95
|
-
m.bindings = m.protocolInfo;
|
|
96
|
-
delete m.protocolInfo;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (m.headers) m.headers = objectToSchema(m.headers);
|
|
100
|
-
});
|
|
101
|
-
} else {
|
|
102
|
-
if (message.protocolInfo) {
|
|
103
|
-
message.bindings = message.protocolInfo;
|
|
104
|
-
delete message.protocolInfo;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (message.headers) message.headers = objectToSchema(message.headers);
|
|
108
|
-
}
|
|
109
|
-
}
|
package/test/index.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const { convert } = require('../lib');
|
|
5
|
-
const { serialize } = require('../lib/helpers');
|
|
6
|
-
|
|
7
|
-
describe('#convert', () => {
|
|
8
|
-
it('should not convert to lowest version', () => {
|
|
9
|
-
assert.throws(
|
|
10
|
-
() => convert(`asyncapi: '2.1.0'`, '2.0.0'),
|
|
11
|
-
/^Error: Cannot downgrade from 2.1.0 to 2.0.0.$/
|
|
12
|
-
);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should not convert from non existing version', () => {
|
|
16
|
-
assert.throws(
|
|
17
|
-
() => convert(`asyncapi: '2.0.0-rc3'`, '2.1.0'),
|
|
18
|
-
/^Error: Cannot convert from 2.0.0-rc3 to 2.1.0.$/
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should not convert to this same version', () => {
|
|
23
|
-
assert.throws(
|
|
24
|
-
() => convert(`asyncapi: '2.1.0'`, '2.1.0'),
|
|
25
|
-
/^Error: Cannot convert to the same version.$/
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should convert from 1.0.0 to 2.0.0-rc1', () => {
|
|
30
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.0.0', 'streetlights.yml'), 'utf8');
|
|
31
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc1', 'streetlights.yml'), 'utf8');
|
|
32
|
-
const result = convert(input, '2.0.0-rc1');
|
|
33
|
-
assertResults(output, result);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should convert from 1.1.0 to 2.0.0-rc1', () => {
|
|
37
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.1.0', 'streetlights.yml'), 'utf8');
|
|
38
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc1', 'streetlights.yml'), 'utf8');
|
|
39
|
-
const result = convert(input, '2.0.0-rc1');
|
|
40
|
-
assertResults(output, result);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should convert from 1.2.0 to 2.0.0-rc1', () => {
|
|
44
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'streetlights.yml'), 'utf8');
|
|
45
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc1', 'streetlights.yml'), 'utf8');
|
|
46
|
-
const result = convert(input, '2.0.0-rc1');
|
|
47
|
-
assertResults(output, result);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should convert from 1.2.0 to 2.0.0-rc1 - stream', () => {
|
|
51
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'gitter-streaming.yml'), 'utf8');
|
|
52
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc1', 'gitter-streaming.yml'), 'utf8');
|
|
53
|
-
const result = convert(input, '2.0.0-rc1');
|
|
54
|
-
assertResults(output, result);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should convert from 1.2.0 to 2.0.0-rc1 - events', () => {
|
|
58
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'slack-rtm.yml'), 'utf8');
|
|
59
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc1', 'slack-rtm.yml'), 'utf8');
|
|
60
|
-
const result = convert(input, '2.0.0-rc1');
|
|
61
|
-
assertResults(output, result);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should convert from 1.0.0 to 2.0.0-rc2', () => {
|
|
65
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.0.0', 'streetlights.yml'), 'utf8');
|
|
66
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc2', 'streetlights.yml'), 'utf8');
|
|
67
|
-
const result = convert(input, '2.0.0-rc2');
|
|
68
|
-
assertResults(output, result);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should convert from 1.1.0 to 2.0.0-rc2', () => {
|
|
72
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.1.0', 'streetlights.yml'), 'utf8');
|
|
73
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc2', 'streetlights.yml'), 'utf8');
|
|
74
|
-
const result = convert(input, '2.0.0-rc2');
|
|
75
|
-
assertResults(output, result);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should convert from 1.2.0 to 2.0.0-rc2 - stream', () => {
|
|
79
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'gitter-streaming.yml'), 'utf8');
|
|
80
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc2', 'gitter-streaming.yml'), 'utf8');
|
|
81
|
-
const result = convert(input, '2.0.0-rc2');
|
|
82
|
-
assertResults(output, result);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should convert from 1.2.0 to 2.0.0-rc2 - events', () => {
|
|
86
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'slack-rtm.yml'), 'utf8');
|
|
87
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc2', 'slack-rtm.yml'), 'utf8');
|
|
88
|
-
const result = convert(input, '2.0.0-rc2');
|
|
89
|
-
assertResults(output, result);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should convert from 1.2.0 to 2.0.0-rc2', () => {
|
|
93
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'streetlights.yml'), 'utf8');
|
|
94
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc2', 'streetlights.yml'), 'utf8');
|
|
95
|
-
const result = convert(input, '2.0.0-rc2');
|
|
96
|
-
assertResults(output, result);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should convert from 1.0.0 to 2.0.0', () => {
|
|
100
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.0.0', 'streetlights.yml'), 'utf8');
|
|
101
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0', 'streetlights.yml'), 'utf8');
|
|
102
|
-
const result = convert(input, '2.0.0');
|
|
103
|
-
assertResults(output, result);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should convert from 1.1.0 to 2.0.0', () => {
|
|
107
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.1.0', 'streetlights.yml'), 'utf8');
|
|
108
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0', 'streetlights.yml'), 'utf8');
|
|
109
|
-
const result = convert(input, '2.0.0');
|
|
110
|
-
assertResults(output, result);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should convert from 1.2.0 to 2.0.0', () => {
|
|
114
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'streetlights.yml'), 'utf8');
|
|
115
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0', 'streetlights.yml'), 'utf8');
|
|
116
|
-
const result = convert(input, '2.0.0');
|
|
117
|
-
assertResults(output, result);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should convert from 2.0.0-rc1 to 2.0.0', () => {
|
|
121
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0-rc1', 'streetlights.yml'), 'utf8');
|
|
122
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0', 'streetlights.yml'), 'utf8');
|
|
123
|
-
const result = convert(input, '2.0.0');
|
|
124
|
-
assertResults(output, result);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should convert from 2.0.0-rc2 to 2.0.0', () => {
|
|
128
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0-rc2', 'streetlights.yml'), 'utf8');
|
|
129
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0', 'streetlights.yml'), 'utf8');
|
|
130
|
-
const result = convert(input, '2.0.0');
|
|
131
|
-
assertResults(output, result);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should convert from 1.0.0 to 2.1.0', () => {
|
|
135
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.0.0', 'streetlights.yml'), 'utf8');
|
|
136
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
|
|
137
|
-
const result = convert(input, '2.1.0');
|
|
138
|
-
assertResults(output, result);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('should convert from 1.1.0 to 2.1.0', () => {
|
|
142
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.1.0', 'streetlights.yml'), 'utf8');
|
|
143
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
|
|
144
|
-
const result = convert(input, '2.1.0');
|
|
145
|
-
assertResults(output, result);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should convert from 1.2.0 to 2.1.0', () => {
|
|
149
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'streetlights.yml'), 'utf8');
|
|
150
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
|
|
151
|
-
const result = convert(input, '2.1.0');
|
|
152
|
-
assertResults(output, result);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('should convert from 2.0.0-rc1 to 2.1.0', () => {
|
|
156
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0-rc1', 'streetlights.yml'), 'utf8');
|
|
157
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
|
|
158
|
-
const result = convert(input, '2.1.0');
|
|
159
|
-
assertResults(output, result);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('should convert from 2.0.0-rc2 to 2.1.0', () => {
|
|
163
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0-rc2', 'streetlights.yml'), 'utf8');
|
|
164
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
|
|
165
|
-
const result = convert(input, '2.1.0');
|
|
166
|
-
assertResults(output, result);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('should convert from 2.0.0 to 2.1.0', () => {
|
|
170
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0', 'streetlights.yml'), 'utf8');
|
|
171
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
|
|
172
|
-
const result = convert(input, '2.1.0');
|
|
173
|
-
assertResults(output, result);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('should convert from 2.0.0 to 2.2.0', () => {
|
|
177
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0', 'streetlights.yml'), 'utf8');
|
|
178
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.2.0', 'streetlights.yml'), 'utf8');
|
|
179
|
-
const result = convert(input, '2.2.0');
|
|
180
|
-
assertResults(output, result);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('should convert from 2.1.0 to 2.2.0', () => {
|
|
184
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.1.0', 'streetlights.yml'), 'utf8');
|
|
185
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.2.0', 'streetlights.yml'), 'utf8');
|
|
186
|
-
const result = convert(input, '2.2.0');
|
|
187
|
-
assertResults(output, result);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('should convert from 2.1.0 to 2.3.0', () => {
|
|
191
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.1.0', 'streetlights.yml'), 'utf8');
|
|
192
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.3.0', 'streetlights.yml'), 'utf8');
|
|
193
|
-
const result = convert(input, '2.3.0');
|
|
194
|
-
assertResults(output, result);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('should convert from 2.2.0 to 2.3.0', () => {
|
|
198
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.2.0', 'streetlights.yml'), 'utf8');
|
|
199
|
-
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.3.0', 'streetlights.yml'), 'utf8');
|
|
200
|
-
const result = convert(input, '2.3.0');
|
|
201
|
-
assertResults(output, result);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('should convert from 2.0.0 to 2.1.0 (JSON case)', () => {
|
|
205
|
-
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0', 'streetlights.json'), 'utf8');
|
|
206
|
-
let output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.json'), 'utf8');
|
|
207
|
-
let result = convert(input, '2.1.0');
|
|
208
|
-
|
|
209
|
-
output = JSON.stringify(JSON.parse(output));
|
|
210
|
-
result = JSON.stringify(JSON.parse(JSON.stringify(result)));
|
|
211
|
-
assert.strictEqual(output, result);
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
describe('#serialize', () => {
|
|
216
|
-
it('should serialize JSON', () => {
|
|
217
|
-
const input = '{"foo": "bar"}';
|
|
218
|
-
const output = serialize(input);
|
|
219
|
-
assert.strictEqual(output.isYAML, false);
|
|
220
|
-
assert.deepEqual(output.parsed, {foo: "bar"});
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('should serialize YAML', () => {
|
|
224
|
-
const input = 'foo: bar';
|
|
225
|
-
const output = serialize(input);
|
|
226
|
-
assert.strictEqual(output.isYAML, true);
|
|
227
|
-
assert.deepEqual(output.parsed, {foo: "bar"});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('should serialize YAML (with JSON syntax)', () => {
|
|
231
|
-
const input = '{foo: bar}';
|
|
232
|
-
const output = serialize(input);
|
|
233
|
-
assert.strictEqual(output.isYAML, true);
|
|
234
|
-
assert.deepEqual(output.parsed, {foo: "bar"});
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it('should throw error', () => {
|
|
238
|
-
const input = '%{foo: bar}';
|
|
239
|
-
try {
|
|
240
|
-
serialize(input);
|
|
241
|
-
} catch(e) {
|
|
242
|
-
assert.strictEqual(e.message, 'AsyncAPI document must be a valid JSON or YAML document.');
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
/*
|
|
248
|
-
It is a helper required for testing on windows. It can't be solved by editor configuration and the end line setting because expected result is converted during tests.
|
|
249
|
-
We need to remove all line breaks from the string
|
|
250
|
-
*/
|
|
251
|
-
function removeLineBreaks(str) {
|
|
252
|
-
return str.replace(/\r?\n|\r/g, '')
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function assertResults(output, result){
|
|
256
|
-
assert.strictEqual(removeLineBreaks(output), removeLineBreaks(result));
|
|
257
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
asyncapi: '1.0.0'
|
|
2
|
-
info:
|
|
3
|
-
title: Streetlights API
|
|
4
|
-
version: '1.0.0'
|
|
5
|
-
description: |
|
|
6
|
-
The Smartylighting Streetlights API allows you to remotely manage the city lights.
|
|
7
|
-
|
|
8
|
-
### Check out its awesome features:
|
|
9
|
-
|
|
10
|
-
* Turn a specific streetlight on/off 🌃
|
|
11
|
-
* Dim a specific streetlight 😎
|
|
12
|
-
* Receive real-time information about environmental lighting conditions 📈
|
|
13
|
-
license:
|
|
14
|
-
name: Apache 2.0
|
|
15
|
-
url: https://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
baseTopic: smartylighting.streetlights.1.0
|
|
17
|
-
|
|
18
|
-
servers:
|
|
19
|
-
- url: api.streetlights.smartylighting.com:{port}
|
|
20
|
-
scheme: mqtt
|
|
21
|
-
description: Test broker
|
|
22
|
-
variables:
|
|
23
|
-
port:
|
|
24
|
-
description: Secure connection (TLS) is available through port 8883.
|
|
25
|
-
default: '1883'
|
|
26
|
-
enum:
|
|
27
|
-
- '1883'
|
|
28
|
-
- '8883'
|
|
29
|
-
|
|
30
|
-
security:
|
|
31
|
-
- apiKey: []
|
|
32
|
-
|
|
33
|
-
topics:
|
|
34
|
-
event.{streetlightId}.lighting.measured:
|
|
35
|
-
parameters:
|
|
36
|
-
- $ref: '#/components/parameters/streetlightId'
|
|
37
|
-
publish:
|
|
38
|
-
$ref: '#/components/messages/lightMeasured'
|
|
39
|
-
|
|
40
|
-
action.{streetlightId}.turn.on:
|
|
41
|
-
parameters:
|
|
42
|
-
- $ref: '#/components/parameters/streetlightId'
|
|
43
|
-
subscribe:
|
|
44
|
-
$ref: '#/components/messages/turnOnOff'
|
|
45
|
-
|
|
46
|
-
action.{streetlightId}.turn.off:
|
|
47
|
-
parameters:
|
|
48
|
-
- $ref: '#/components/parameters/streetlightId'
|
|
49
|
-
subscribe:
|
|
50
|
-
$ref: '#/components/messages/turnOnOff'
|
|
51
|
-
|
|
52
|
-
action.{streetlightId}.dim:
|
|
53
|
-
parameters:
|
|
54
|
-
- $ref: '#/components/parameters/streetlightId'
|
|
55
|
-
subscribe:
|
|
56
|
-
$ref: '#/components/messages/dimLight'
|
|
57
|
-
|
|
58
|
-
components:
|
|
59
|
-
messages:
|
|
60
|
-
lightMeasured:
|
|
61
|
-
summary: Inform about environmental lighting conditions for a particular streetlight.
|
|
62
|
-
payload:
|
|
63
|
-
$ref: "#/components/schemas/lightMeasuredPayload"
|
|
64
|
-
turnOnOff:
|
|
65
|
-
summary: Command a particular streetlight to turn the lights on or off.
|
|
66
|
-
payload:
|
|
67
|
-
$ref: "#/components/schemas/turnOnOffPayload"
|
|
68
|
-
dimLight:
|
|
69
|
-
summary: Command a particular streetlight to dim the lights.
|
|
70
|
-
payload:
|
|
71
|
-
$ref: "#/components/schemas/dimLightPayload"
|
|
72
|
-
|
|
73
|
-
schemas:
|
|
74
|
-
lightMeasuredPayload:
|
|
75
|
-
type: object
|
|
76
|
-
properties:
|
|
77
|
-
lumens:
|
|
78
|
-
type: integer
|
|
79
|
-
minimum: 0
|
|
80
|
-
description: Light intensity measured in lumens.
|
|
81
|
-
sentAt:
|
|
82
|
-
$ref: "#/components/schemas/sentAt"
|
|
83
|
-
turnOnOffPayload:
|
|
84
|
-
type: object
|
|
85
|
-
properties:
|
|
86
|
-
command:
|
|
87
|
-
type: string
|
|
88
|
-
enum:
|
|
89
|
-
- on
|
|
90
|
-
- off
|
|
91
|
-
description: Whether to turn on or off the light.
|
|
92
|
-
sentAt:
|
|
93
|
-
$ref: "#/components/schemas/sentAt"
|
|
94
|
-
dimLightPayload:
|
|
95
|
-
type: object
|
|
96
|
-
properties:
|
|
97
|
-
percentage:
|
|
98
|
-
type: integer
|
|
99
|
-
description: Percentage to which the light should be dimmed to.
|
|
100
|
-
minimum: 0
|
|
101
|
-
maximum: 100
|
|
102
|
-
sentAt:
|
|
103
|
-
$ref: "#/components/schemas/sentAt"
|
|
104
|
-
sentAt:
|
|
105
|
-
type: string
|
|
106
|
-
format: date-time
|
|
107
|
-
description: Date and time when the message was sent.
|
|
108
|
-
|
|
109
|
-
securitySchemes:
|
|
110
|
-
apiKey:
|
|
111
|
-
type: apiKey
|
|
112
|
-
in: user
|
|
113
|
-
description: Provide your API key as the user and leave the password empty.
|
|
114
|
-
|
|
115
|
-
parameters:
|
|
116
|
-
streetlightId:
|
|
117
|
-
name: streetlightId
|
|
118
|
-
description: The ID of the streetlight.
|
|
119
|
-
schema:
|
|
120
|
-
type: string
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
asyncapi: '1.1.0'
|
|
2
|
-
info:
|
|
3
|
-
title: Streetlights API
|
|
4
|
-
version: '1.0.0'
|
|
5
|
-
description: |
|
|
6
|
-
The Smartylighting Streetlights API allows you to remotely manage the city lights.
|
|
7
|
-
|
|
8
|
-
### Check out its awesome features:
|
|
9
|
-
|
|
10
|
-
* Turn a specific streetlight on/off 🌃
|
|
11
|
-
* Dim a specific streetlight 😎
|
|
12
|
-
* Receive real-time information about environmental lighting conditions 📈
|
|
13
|
-
license:
|
|
14
|
-
name: Apache 2.0
|
|
15
|
-
url: https://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
baseTopic: smartylighting.streetlights.1.0
|
|
17
|
-
|
|
18
|
-
servers:
|
|
19
|
-
- url: api.streetlights.smartylighting.com:{port}
|
|
20
|
-
scheme: mqtt
|
|
21
|
-
description: Test broker
|
|
22
|
-
variables:
|
|
23
|
-
port:
|
|
24
|
-
description: Secure connection (TLS) is available through port 8883.
|
|
25
|
-
default: '1883'
|
|
26
|
-
enum:
|
|
27
|
-
- '1883'
|
|
28
|
-
- '8883'
|
|
29
|
-
|
|
30
|
-
security:
|
|
31
|
-
- apiKey: []
|
|
32
|
-
|
|
33
|
-
topics:
|
|
34
|
-
event.{streetlightId}.lighting.measured:
|
|
35
|
-
parameters:
|
|
36
|
-
- $ref: '#/components/parameters/streetlightId'
|
|
37
|
-
publish:
|
|
38
|
-
$ref: '#/components/messages/lightMeasured'
|
|
39
|
-
|
|
40
|
-
action.{streetlightId}.turn.on:
|
|
41
|
-
parameters:
|
|
42
|
-
- $ref: '#/components/parameters/streetlightId'
|
|
43
|
-
subscribe:
|
|
44
|
-
$ref: '#/components/messages/turnOnOff'
|
|
45
|
-
|
|
46
|
-
action.{streetlightId}.turn.off:
|
|
47
|
-
parameters:
|
|
48
|
-
- $ref: '#/components/parameters/streetlightId'
|
|
49
|
-
subscribe:
|
|
50
|
-
$ref: '#/components/messages/turnOnOff'
|
|
51
|
-
|
|
52
|
-
action.{streetlightId}.dim:
|
|
53
|
-
parameters:
|
|
54
|
-
- $ref: '#/components/parameters/streetlightId'
|
|
55
|
-
subscribe:
|
|
56
|
-
$ref: '#/components/messages/dimLight'
|
|
57
|
-
|
|
58
|
-
components:
|
|
59
|
-
messages:
|
|
60
|
-
lightMeasured:
|
|
61
|
-
summary: Inform about environmental lighting conditions for a particular streetlight.
|
|
62
|
-
payload:
|
|
63
|
-
$ref: "#/components/schemas/lightMeasuredPayload"
|
|
64
|
-
turnOnOff:
|
|
65
|
-
summary: Command a particular streetlight to turn the lights on or off.
|
|
66
|
-
payload:
|
|
67
|
-
$ref: "#/components/schemas/turnOnOffPayload"
|
|
68
|
-
dimLight:
|
|
69
|
-
summary: Command a particular streetlight to dim the lights.
|
|
70
|
-
payload:
|
|
71
|
-
$ref: "#/components/schemas/dimLightPayload"
|
|
72
|
-
|
|
73
|
-
schemas:
|
|
74
|
-
lightMeasuredPayload:
|
|
75
|
-
type: object
|
|
76
|
-
properties:
|
|
77
|
-
lumens:
|
|
78
|
-
type: integer
|
|
79
|
-
minimum: 0
|
|
80
|
-
description: Light intensity measured in lumens.
|
|
81
|
-
sentAt:
|
|
82
|
-
$ref: "#/components/schemas/sentAt"
|
|
83
|
-
turnOnOffPayload:
|
|
84
|
-
type: object
|
|
85
|
-
properties:
|
|
86
|
-
command:
|
|
87
|
-
type: string
|
|
88
|
-
enum:
|
|
89
|
-
- on
|
|
90
|
-
- off
|
|
91
|
-
description: Whether to turn on or off the light.
|
|
92
|
-
sentAt:
|
|
93
|
-
$ref: "#/components/schemas/sentAt"
|
|
94
|
-
dimLightPayload:
|
|
95
|
-
type: object
|
|
96
|
-
properties:
|
|
97
|
-
percentage:
|
|
98
|
-
type: integer
|
|
99
|
-
description: Percentage to which the light should be dimmed to.
|
|
100
|
-
minimum: 0
|
|
101
|
-
maximum: 100
|
|
102
|
-
sentAt:
|
|
103
|
-
$ref: "#/components/schemas/sentAt"
|
|
104
|
-
sentAt:
|
|
105
|
-
type: string
|
|
106
|
-
format: date-time
|
|
107
|
-
description: Date and time when the message was sent.
|
|
108
|
-
|
|
109
|
-
securitySchemes:
|
|
110
|
-
apiKey:
|
|
111
|
-
type: apiKey
|
|
112
|
-
in: user
|
|
113
|
-
description: Provide your API key as the user and leave the password empty.
|
|
114
|
-
|
|
115
|
-
parameters:
|
|
116
|
-
streetlightId:
|
|
117
|
-
name: streetlightId
|
|
118
|
-
description: The ID of the streetlight.
|
|
119
|
-
schema:
|
|
120
|
-
type: string
|