@asyncapi/converter 0.9.0 → 1.0.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.
Files changed (58) hide show
  1. package/README.md +96 -21
  2. package/lib/convert.d.ts +3 -0
  3. package/lib/convert.js +192 -0
  4. package/lib/index.d.ts +2 -0
  5. package/lib/index.js +5 -212
  6. package/lib/interfaces.d.ts +6 -0
  7. package/lib/interfaces.js +2 -0
  8. package/lib/utils.d.ts +21 -0
  9. package/lib/utils.js +114 -0
  10. package/package.json +24 -12
  11. package/.github/workflows/add-good-first-issue-labels.yml +0 -68
  12. package/.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml +0 -54
  13. package/.github/workflows/automerge-for-humans-merging.yml +0 -32
  14. package/.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml +0 -35
  15. package/.github/workflows/automerge-orphans.yml +0 -63
  16. package/.github/workflows/automerge.yml +0 -50
  17. package/.github/workflows/autoupdate.yml +0 -32
  18. package/.github/workflows/bump.yml +0 -33
  19. package/.github/workflows/help-command.yml +0 -43
  20. package/.github/workflows/if-go-pr-testing.yml +0 -68
  21. package/.github/workflows/if-nodejs-pr-testing.yml +0 -60
  22. package/.github/workflows/if-nodejs-release.yml +0 -85
  23. package/.github/workflows/if-nodejs-version-bump.yml +0 -48
  24. package/.github/workflows/issues-prs-notifications.yml +0 -72
  25. package/.github/workflows/lint-pr-title.yml +0 -22
  26. package/.github/workflows/notify-tsc-members-mention.yml +0 -142
  27. package/.github/workflows/release-announcements.yml +0 -76
  28. package/.github/workflows/sentiment-analysis.yml +0 -44
  29. package/.github/workflows/stale-issues-prs.yml +0 -42
  30. package/.github/workflows/welcome-first-time-contrib.yml +0 -83
  31. package/CODEOWNERS +0 -8
  32. package/cli.js +0 -66
  33. package/lib/helpers.js +0 -109
  34. package/test/index.js +0 -257
  35. package/test/input/1.0.0/streetlights.yml +0 -120
  36. package/test/input/1.1.0/streetlights.yml +0 -120
  37. package/test/input/1.2.0/gitter-streaming.yml +0 -140
  38. package/test/input/1.2.0/slack-rtm.yml +0 -876
  39. package/test/input/1.2.0/streetlights.yml +0 -120
  40. package/test/input/2.0.0/streetlights.json +0 -172
  41. package/test/input/2.0.0/streetlights.yml +0 -112
  42. package/test/input/2.0.0-rc1/streetlights.yml +0 -109
  43. package/test/input/2.0.0-rc2/streetlights.yml +0 -112
  44. package/test/input/2.1.0/streetlights.yml +0 -112
  45. package/test/input/2.2.0/streetlights.yml +0 -112
  46. package/test/output/2.0.0/gitter-streaming.yml +0 -137
  47. package/test/output/2.0.0/slack-rtm.yml +0 -879
  48. package/test/output/2.0.0/streetlights.yml +0 -112
  49. package/test/output/2.0.0-rc1/gitter-streaming.yml +0 -137
  50. package/test/output/2.0.0-rc1/slack-rtm.yml +0 -879
  51. package/test/output/2.0.0-rc1/streetlights.yml +0 -109
  52. package/test/output/2.0.0-rc2/gitter-streaming.yml +0 -137
  53. package/test/output/2.0.0-rc2/slack-rtm.yml +0 -879
  54. package/test/output/2.0.0-rc2/streetlights.yml +0 -112
  55. package/test/output/2.1.0/streetlights.json +0 -172
  56. package/test/output/2.1.0/streetlights.yml +0 -112
  57. package/test/output/2.2.0/streetlights.yml +0 -112
  58. package/test/output/2.3.0/streetlights.yml +0 -112
@@ -1,83 +0,0 @@
1
- #This action is centrally managed in https://github.com/asyncapi/.github/
2
- #Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo
3
-
4
- name: Welcome first time contributors
5
-
6
- on:
7
- pull_request_target:
8
- types:
9
- - opened
10
- issues:
11
- types:
12
- - opened
13
-
14
- jobs:
15
- welcome:
16
- runs-on: ubuntu-latest
17
- steps:
18
- - uses: actions/github-script@v3
19
- with:
20
- github-token: ${{ secrets.GITHUB_TOKEN }}
21
- script: |
22
- const issueMessage = `Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our [contributors guide](https://github.com/asyncapi/community/blob/master/CONTRIBUTING.md) and the instructions about a [basic recommended setup](https://github.com/asyncapi/.github/blob/master/git-workflow.md) useful for opening a pull request.<br />Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out [this issue](https://github.com/asyncapi/asyncapi/issues/115).`;
23
- const prMessage = `Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our [contributors guide](https://github.com/asyncapi/community/blob/master/CONTRIBUTING.md) useful for opening a pull request.<br />Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out [this issue](https://github.com/asyncapi/asyncapi/issues/115).`;
24
- if (!issueMessage && !prMessage) {
25
- throw new Error('Action must have at least one of issue-message or pr-message set');
26
- }
27
- const isIssue = !!context.payload.issue;
28
- let isFirstContribution;
29
- if (isIssue) {
30
- const query = `query($owner:String!, $name:String!, $contributer:String!) {
31
- repository(owner:$owner, name:$name){
32
- issues(first: 1, filterBy: {createdBy:$contributer}){
33
- totalCount
34
- }
35
- }
36
- }`;
37
- const variables = {
38
- owner: context.repo.owner,
39
- name: context.repo.repo,
40
- contributer: context.payload.sender.login
41
- };
42
- const { repository: { issues: { totalCount } } } = await github.graphql(query, variables);
43
- isFirstContribution = totalCount === 1;
44
- } else {
45
- const query = `query($qstr: String!) {
46
- search(query: $qstr, type: ISSUE, first: 1) {
47
- issueCount
48
- }
49
- }`;
50
- const variables = {
51
- "qstr": `repo:${context.repo.owner}/${context.repo.repo} type:pr author:${context.payload.sender.login}`,
52
- };
53
- const { search: { issueCount } } = await github.graphql(query, variables);
54
- isFirstContribution = issueCount === 1;
55
- }
56
-
57
- if (!isFirstContribution) {
58
- console.log(`Not the users first contribution.`);
59
- return;
60
- }
61
- const message = isIssue ? issueMessage : prMessage;
62
- // Add a comment to the appropriate place
63
- if (isIssue) {
64
- const issueNumber = context.payload.issue.number;
65
- console.log(`Adding message: ${message} to issue #${issueNumber}`);
66
- await github.issues.createComment({
67
- owner: context.payload.repository.owner.login,
68
- repo: context.payload.repository.name,
69
- issue_number: issueNumber,
70
- body: message
71
- });
72
- }
73
- else {
74
- const pullNumber = context.payload.pull_request.number;
75
- console.log(`Adding message: ${message} to pull request #${pullNumber}`);
76
- await github.pulls.createReview({
77
- owner: context.payload.repository.owner.login,
78
- repo: context.payload.repository.name,
79
- pull_number: pullNumber,
80
- body: message,
81
- event: 'COMMENT'
82
- });
83
- }
package/CODEOWNERS DELETED
@@ -1,8 +0,0 @@
1
- # This file provides an overview of code owners in this repository.
2
-
3
- # Each line is a file pattern followed by one or more owners.
4
- # The last matching pattern has the most precedence.
5
- # For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/.
6
-
7
- # The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.
8
- * @fmvilas @magicmatatjahu @derberg @github-actions[bot]
package/cli.js DELETED
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const program = require('commander');
6
- const packageInfo = require('./package.json');
7
- const converter = require('./lib');
8
-
9
- const red = text => `\x1b[31m${text}\x1b[0m`;
10
-
11
- let asyncapiFile;
12
- let version;
13
- let output;
14
-
15
- const parseArguments = (asyncAPIPath, v) => {
16
- asyncapiFile = path.resolve(asyncAPIPath);
17
- version = v;
18
- }
19
-
20
- const parseOutput = (filePath) => {
21
- output = path.resolve(filePath);
22
- }
23
-
24
- const showErrorAndExit = err => {
25
- console.error(red('Something went wrong:'));
26
- console.error(red(err.stack || err.message));
27
- process.exit(1);
28
- };
29
-
30
- program
31
- .version(packageInfo.version)
32
- .arguments('<document> [version]')
33
- .action(parseArguments)
34
- .option('--id <id>', 'application id (defaults to a generated one)')
35
- .option('-o, --output <outputFile>', 'file where to put the converted AsyncAPI document', parseOutput)
36
- .parse(process.argv);
37
-
38
- if (!asyncapiFile) {
39
- console.error(red('> Path to AsyncAPI file not provided.'));
40
- program.help(); // This exits the process
41
- }
42
- if (!version) {
43
- version = '2.3.0';
44
- }
45
-
46
- try {
47
- const asyncapi = fs.readFileSync(asyncapiFile, 'utf-8');
48
- let converted = converter.convert(asyncapi, version, {
49
- id: program.id,
50
- });
51
-
52
- // JSON case
53
- if (typeof converted === 'object') {
54
- converted = JSON.stringify(converted, undefined, 2);
55
- }
56
-
57
- if (output) {
58
- fs.writeFileSync(output, converted, 'utf-8');
59
- } else {
60
- console.log(converted);
61
- }
62
- } catch (e) {
63
- showErrorAndExit(e);
64
- }
65
-
66
- process.on('unhandledRejection', showErrorAndExit);
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