@asyncapi/converter 0.6.0 → 0.7.1
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/.github/workflows/add-good-first-issue-labels.yml +68 -0
- package/.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml +54 -0
- package/.github/workflows/automerge-for-humans-merging.yml +32 -0
- package/.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml +35 -0
- package/.github/workflows/automerge.yml +22 -19
- package/.github/workflows/autoupdate.yml +32 -0
- package/.github/workflows/bump.yml +3 -2
- package/.github/workflows/help-command.yml +43 -0
- package/.github/workflows/if-go-pr-testing.yml +17 -7
- package/.github/workflows/if-nodejs-pr-testing.yml +16 -4
- package/.github/workflows/if-nodejs-release.yml +20 -5
- package/.github/workflows/issues-prs-notifications.yml +1 -1
- package/.github/workflows/notify-tsc-members-mention.yml +142 -0
- package/.github/workflows/stale-issues-prs.yml +21 -9
- package/.github/workflows/welcome-first-time-contrib.yml +78 -29
- package/CODEOWNERS +8 -0
- package/cli.js +10 -3
- package/lib/helpers.js +20 -2
- package/lib/index.js +22 -17
- package/package.json +11 -11
- package/test/index.js +58 -1
- package/test/input/2.0.0/streetlights.json +172 -0
- package/test/input/2.2.0/streetlights.yml +113 -0
- package/test/output/2.1.0/streetlights.json +172 -0
- package/test/output/2.3.0/streetlights.yml +113 -0
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
#This action notifies community on slack whenever there is a new issue, PR or discussion started in given repository
|
|
5
|
+
name: Notify slack whenever TSC members are mentioned in GitHub
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
issue_comment:
|
|
9
|
+
types:
|
|
10
|
+
- created
|
|
11
|
+
- edited
|
|
12
|
+
|
|
13
|
+
discussion_comment:
|
|
14
|
+
types:
|
|
15
|
+
- created
|
|
16
|
+
- edited
|
|
17
|
+
|
|
18
|
+
issues:
|
|
19
|
+
types:
|
|
20
|
+
- opened
|
|
21
|
+
- reopened
|
|
22
|
+
|
|
23
|
+
pull_request_target:
|
|
24
|
+
types:
|
|
25
|
+
- opened
|
|
26
|
+
- reopened
|
|
27
|
+
- ready_for_review
|
|
28
|
+
|
|
29
|
+
discussion:
|
|
30
|
+
types:
|
|
31
|
+
- created
|
|
32
|
+
- edited
|
|
33
|
+
|
|
34
|
+
jobs:
|
|
35
|
+
|
|
36
|
+
issue:
|
|
37
|
+
if: github.event_name == 'issues' && contains(github.event.issue.body, '@asyncapi/tsc_members')
|
|
38
|
+
name: On every new issue
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
steps:
|
|
41
|
+
- name: Convert markdown to slack markdown
|
|
42
|
+
uses: LoveToKnow/slackify-markdown-action@v1.0.0
|
|
43
|
+
id: issuemarkdown
|
|
44
|
+
with:
|
|
45
|
+
text: "[${{github.event.issue.title}}](${{github.event.issue.html_url}}) \n ${{github.event.issue.body}}"
|
|
46
|
+
- name: Send info about issue
|
|
47
|
+
uses: rtCamp/action-slack-notify@v2
|
|
48
|
+
env:
|
|
49
|
+
SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}}
|
|
50
|
+
SLACK_TITLE: 🆘 New issue that requires TSC Members attention 🆘
|
|
51
|
+
SLACK_MESSAGE: ${{steps.issuemarkdown.outputs.text}}
|
|
52
|
+
MSG_MINIMAL: true
|
|
53
|
+
|
|
54
|
+
pull_request:
|
|
55
|
+
if: github.event_name == 'pull_request_target' && contains(github.event.pull_request.body, '@asyncapi/tsc_members')
|
|
56
|
+
name: On every new pull request
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
steps:
|
|
59
|
+
- name: Convert markdown to slack markdown
|
|
60
|
+
uses: LoveToKnow/slackify-markdown-action@v1.0.0
|
|
61
|
+
id: prmarkdown
|
|
62
|
+
with:
|
|
63
|
+
text: "[${{github.event.pull_request.title}}](${{github.event.pull_request.html_url}}) \n ${{github.event.pull_request.body}}"
|
|
64
|
+
- name: Send info about pull request
|
|
65
|
+
uses: rtCamp/action-slack-notify@v2
|
|
66
|
+
env:
|
|
67
|
+
SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}}
|
|
68
|
+
SLACK_TITLE: 🆘 New PR that requires TSC Members attention 🆘
|
|
69
|
+
SLACK_MESSAGE: ${{steps.prmarkdown.outputs.text}}
|
|
70
|
+
MSG_MINIMAL: true
|
|
71
|
+
|
|
72
|
+
discussion:
|
|
73
|
+
if: github.event_name == 'discussion' && contains(github.event.discussion.body, '@asyncapi/tsc_members')
|
|
74
|
+
name: On every new discussion
|
|
75
|
+
runs-on: ubuntu-latest
|
|
76
|
+
steps:
|
|
77
|
+
- name: Convert markdown to slack markdown
|
|
78
|
+
uses: LoveToKnow/slackify-markdown-action@v1.0.0
|
|
79
|
+
id: discussionmarkdown
|
|
80
|
+
with:
|
|
81
|
+
text: "[${{github.event.discussion.title}}](${{github.event.discussion.html_url}}) \n ${{github.event.discussion.body}}"
|
|
82
|
+
- name: Send info about pull request
|
|
83
|
+
uses: rtCamp/action-slack-notify@v2
|
|
84
|
+
env:
|
|
85
|
+
SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}}
|
|
86
|
+
SLACK_TITLE: 🆘 New discussion that requires TSC Members attention 🆘
|
|
87
|
+
SLACK_MESSAGE: ${{steps.discussionmarkdown.outputs.text}}
|
|
88
|
+
MSG_MINIMAL: true
|
|
89
|
+
|
|
90
|
+
issue_comment:
|
|
91
|
+
if: ${{ github.event_name == 'issue_comment' && !github.event.issue.pull_request && contains(github.event.comment.body, '@asyncapi/tsc_members') }}
|
|
92
|
+
name: On every new comment in issue
|
|
93
|
+
runs-on: ubuntu-latest
|
|
94
|
+
steps:
|
|
95
|
+
- name: Convert markdown to slack markdown
|
|
96
|
+
uses: LoveToKnow/slackify-markdown-action@v1.0.0
|
|
97
|
+
id: issuemarkdown
|
|
98
|
+
with:
|
|
99
|
+
text: "[${{github.event.issue.title}}](${{github.event.comment.html_url}}) \n ${{github.event.comment.body}}"
|
|
100
|
+
- name: Send info about issue comment
|
|
101
|
+
uses: rtCamp/action-slack-notify@v2
|
|
102
|
+
env:
|
|
103
|
+
SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}}
|
|
104
|
+
SLACK_TITLE: 🆘 New comment under existing issue that requires TSC Members attention 🆘
|
|
105
|
+
SLACK_MESSAGE: ${{steps.issuemarkdown.outputs.text}}
|
|
106
|
+
MSG_MINIMAL: true
|
|
107
|
+
|
|
108
|
+
pr_comment:
|
|
109
|
+
if: github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '@asyncapi/tsc_members')
|
|
110
|
+
name: On every new comment in pr
|
|
111
|
+
runs-on: ubuntu-latest
|
|
112
|
+
steps:
|
|
113
|
+
- name: Convert markdown to slack markdown
|
|
114
|
+
uses: LoveToKnow/slackify-markdown-action@v1.0.0
|
|
115
|
+
id: prmarkdown
|
|
116
|
+
with:
|
|
117
|
+
text: "[${{github.event.issue.title}}](${{github.event.comment.html_url}}) \n ${{github.event.comment.body}}"
|
|
118
|
+
- name: Send info about PR comment
|
|
119
|
+
uses: rtCamp/action-slack-notify@v2
|
|
120
|
+
env:
|
|
121
|
+
SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}}
|
|
122
|
+
SLACK_TITLE: 🆘 New comment under existing PR that requires TSC Members attention 🆘
|
|
123
|
+
SLACK_MESSAGE: ${{steps.prmarkdown.outputs.text}}
|
|
124
|
+
MSG_MINIMAL: true
|
|
125
|
+
|
|
126
|
+
discussion_comment:
|
|
127
|
+
if: github.event_name == 'discussion_comment' && contains(github.event.comment.body, '@asyncapi/tsc_members')
|
|
128
|
+
name: On every new comment in discussion
|
|
129
|
+
runs-on: ubuntu-latest
|
|
130
|
+
steps:
|
|
131
|
+
- name: Convert markdown to slack markdown
|
|
132
|
+
uses: LoveToKnow/slackify-markdown-action@v1.0.0
|
|
133
|
+
id: discussionmarkdown
|
|
134
|
+
with:
|
|
135
|
+
text: "[${{github.event.discussion.title}}](${{github.event.comment.html_url}}) \n ${{github.event.comment.body}}"
|
|
136
|
+
- name: Send info about discussion comment
|
|
137
|
+
uses: rtCamp/action-slack-notify@v2
|
|
138
|
+
env:
|
|
139
|
+
SLACK_WEBHOOK: ${{secrets.SLACK_TSC_MEMBERS_NOTIFY}}
|
|
140
|
+
SLACK_TITLE: 🆘 New comment under existing discussion that requires TSC Members attention 🆘
|
|
141
|
+
SLACK_MESSAGE: ${{steps.discussionmarkdown.outputs.text}}
|
|
142
|
+
MSG_MINIMAL: true
|
|
@@ -11,20 +11,32 @@ jobs:
|
|
|
11
11
|
stale:
|
|
12
12
|
runs-on: ubuntu-latest
|
|
13
13
|
steps:
|
|
14
|
-
- uses: actions/stale@
|
|
14
|
+
- uses: actions/stale@v4.0.0
|
|
15
15
|
with:
|
|
16
16
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
17
17
|
stale-issue-message: |
|
|
18
18
|
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
|
|
20
|
+
It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
|
|
21
|
+
|
|
22
|
+
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under [open governance model](https://github.com/asyncapi/community/blob/master/CHARTER.md).
|
|
23
|
+
|
|
24
|
+
Let us figure out together how to push this issue forward. Connect with us through [one of many communication channels](https://github.com/asyncapi/community/issues/1) we established here.
|
|
25
|
+
|
|
26
|
+
Thank you for your patience :heart:
|
|
21
27
|
stale-pr-message: |
|
|
22
28
|
This pull request has been automatically marked as stale because it has not had recent activity :sleeping:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
|
|
30
|
+
It will be closed in 120 days if no further activity occurs. To unstale this pull request, add a comment with detailed explanation.
|
|
31
|
+
|
|
32
|
+
There can be many reasons why some specific pull request has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under [open governance model](https://github.com/asyncapi/community/blob/master/CHARTER.md).
|
|
33
|
+
|
|
34
|
+
Let us figure out together how to push this pull request forward. Connect with us through [one of many communication channels](https://github.com/asyncapi/community/issues/1) we established here.
|
|
35
|
+
|
|
36
|
+
Thank you for your patience :heart:
|
|
37
|
+
days-before-stale: 120
|
|
38
|
+
days-before-close: 120
|
|
27
39
|
stale-issue-label: stale
|
|
28
40
|
stale-pr-label: stale
|
|
29
|
-
exempt-issue-
|
|
30
|
-
exempt-pr-
|
|
41
|
+
exempt-issue-labels: keep-open
|
|
42
|
+
exempt-pr-labels: keep-open
|
|
@@ -1,34 +1,83 @@
|
|
|
1
1
|
#This action is centrally managed in https://github.com/asyncapi/.github/
|
|
2
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
3
|
|
|
4
|
-
|
|
5
|
-
#disabled because of https://github.com/asyncapi/.github/issues/73
|
|
6
|
-
#########
|
|
4
|
+
name: Welcome first time contributors
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
on:
|
|
7
|
+
pull_request_target:
|
|
8
|
+
types:
|
|
9
|
+
- opened
|
|
10
|
+
issues:
|
|
11
|
+
types:
|
|
12
|
+
- opened
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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
CHANGED
|
@@ -32,14 +32,21 @@ if (!asyncapiFile) {
|
|
|
32
32
|
program.help(); // This exits the process
|
|
33
33
|
}
|
|
34
34
|
if (!version) {
|
|
35
|
-
version = '2.
|
|
35
|
+
version = '2.3.0';
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
try {
|
|
39
39
|
const asyncapi = fs.readFileSync(asyncapiFile, 'utf-8');
|
|
40
|
-
|
|
40
|
+
let converted = converter.convert(asyncapi, version, {
|
|
41
41
|
id: program.id,
|
|
42
|
-
})
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// JSON case
|
|
45
|
+
if (typeof converted === 'object') {
|
|
46
|
+
converted = JSON.stringify(converted, undefined, 2);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(converted);
|
|
43
50
|
} catch (e) {
|
|
44
51
|
showErrorAndExit(e);
|
|
45
52
|
}
|
package/lib/helpers.js
CHANGED
|
@@ -3,16 +3,34 @@ const yaml = require('js-yaml');
|
|
|
3
3
|
const helpers = module.exports;
|
|
4
4
|
|
|
5
5
|
helpers.serialize = (text) => {
|
|
6
|
+
if (typeof text === 'object') {
|
|
7
|
+
return {
|
|
8
|
+
isYAML: false,
|
|
9
|
+
parsed: text,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
6
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
|
|
7
24
|
return {
|
|
8
25
|
isYAML: true,
|
|
9
26
|
parsed: yaml.safeLoad(text)
|
|
10
27
|
};
|
|
11
28
|
} catch (e) {
|
|
12
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
|
|
13
31
|
return {
|
|
14
|
-
isYAML:
|
|
15
|
-
parsed:
|
|
32
|
+
isYAML: true,
|
|
33
|
+
parsed: yaml.safeLoad(text)
|
|
16
34
|
};
|
|
17
35
|
} catch (err) {
|
|
18
36
|
throw new Error('AsyncAPI document must be a valid JSON or YAML document.');
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,7 @@ const conversions = {
|
|
|
22
22
|
'2.0.0': from__2_0_0_rc2__to__2_0_0,
|
|
23
23
|
'2.1.0': from__2_0_0__to__2_1_0,
|
|
24
24
|
'2.2.0': from__2_1_0__to__2_2_0,
|
|
25
|
+
'2.3.0': from__2_2_0__to__2_3_0,
|
|
25
26
|
}
|
|
26
27
|
const conversionVersions = Object.keys(conversions);
|
|
27
28
|
|
|
@@ -72,12 +73,12 @@ function from__1_2_0__to__2_0_0_rc1(asyncapi1, options) { // NOSONAR
|
|
|
72
73
|
|
|
73
74
|
result.asyncapi = '2.0.0-rc1';
|
|
74
75
|
result.id = options.id || `urn:${asyncapi1.info.title.toLowerCase().split(' ').join('.')}`;
|
|
75
|
-
|
|
76
|
+
|
|
76
77
|
if (asyncapi1.servers) {
|
|
77
78
|
const security = asyncapi1.security;
|
|
78
79
|
result.servers = asyncapi1.servers.map(server => {
|
|
79
80
|
const { scheme, schemeVersion, ...rest } = server;
|
|
80
|
-
|
|
81
|
+
|
|
81
82
|
const out = {
|
|
82
83
|
...rest,
|
|
83
84
|
...{
|
|
@@ -94,9 +95,10 @@ function from__1_2_0__to__2_0_0_rc1(asyncapi1, options) { // NOSONAR
|
|
|
94
95
|
return out;
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
+
|
|
98
99
|
if (asyncapi1.topics) {
|
|
99
|
-
|
|
100
|
+
const baseTopic = asyncapi1.baseTopic ? `${asyncapi1.baseTopic}.` : "";
|
|
101
|
+
result.channels = _.mapKeys(result.topics, (__, topicName) => dotsToSlashes(`${baseTopic}${topicName}`));
|
|
100
102
|
_.map(result.channels, ch => {
|
|
101
103
|
if (ch.publish) {
|
|
102
104
|
ch.publish = { message: ch.publish };
|
|
@@ -114,7 +116,7 @@ function from__1_2_0__to__2_0_0_rc1(asyncapi1, options) { // NOSONAR
|
|
|
114
116
|
'/': eventToChannel(asyncapi1.events),
|
|
115
117
|
};
|
|
116
118
|
}
|
|
117
|
-
|
|
119
|
+
|
|
118
120
|
delete result.topics;
|
|
119
121
|
delete result.stream;
|
|
120
122
|
delete result.events;
|
|
@@ -129,7 +131,7 @@ function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi2rc1, options) { // NOSONAR
|
|
|
129
131
|
|
|
130
132
|
result.asyncapi = '2.0.0-rc2';
|
|
131
133
|
result.id = result.id || options.id;
|
|
132
|
-
|
|
134
|
+
|
|
133
135
|
if (asyncapi2rc1.servers) {
|
|
134
136
|
const serverMap = {};
|
|
135
137
|
asyncapi2rc1.servers.forEach((server, index) => {
|
|
@@ -139,7 +141,7 @@ function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi2rc1, options) { // NOSONAR
|
|
|
139
141
|
});
|
|
140
142
|
result.servers = serverMap;
|
|
141
143
|
}
|
|
142
|
-
|
|
144
|
+
|
|
143
145
|
if (result.channels) {
|
|
144
146
|
_.each(result.channels, (channel, channelName) => {
|
|
145
147
|
if (channel.parameters) {
|
|
@@ -157,7 +159,7 @@ function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi2rc1, options) { // NOSONAR
|
|
|
157
159
|
const message = channel.publish.message;
|
|
158
160
|
convertMessage(message);
|
|
159
161
|
}
|
|
160
|
-
|
|
162
|
+
|
|
161
163
|
if (channel.subscribe && channel.subscribe.message) {
|
|
162
164
|
const message = channel.subscribe.message;
|
|
163
165
|
convertMessage(message);
|
|
@@ -177,7 +179,7 @@ function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi2rc1, options) { // NOSONAR
|
|
|
177
179
|
channel.subscribe.bindings = channel.subscribe.protocolInfo;
|
|
178
180
|
delete channel.subscribe.protocolInfo;
|
|
179
181
|
}
|
|
180
|
-
});
|
|
182
|
+
});
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
if (!options.id) delete result.id;
|
|
@@ -191,14 +193,17 @@ function from__2_0_0_rc2__to__2_0_0(asyncapi2rc2, options) {
|
|
|
191
193
|
return result;
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
function from__2_0_0__to__2_1_0(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return result;
|
|
196
|
+
function from__2_0_0__to__2_1_0(asyncapi) {
|
|
197
|
+
asyncapi.asyncapi = '2.1.0';
|
|
198
|
+
return asyncapi;
|
|
198
199
|
}
|
|
199
200
|
|
|
200
|
-
function from__2_1_0__to__2_2_0(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return result;
|
|
201
|
+
function from__2_1_0__to__2_2_0(asyncapi) {
|
|
202
|
+
asyncapi.asyncapi = '2.2.0';
|
|
203
|
+
return asyncapi;
|
|
204
204
|
}
|
|
205
|
+
|
|
206
|
+
function from__2_2_0__to__2_3_0(asyncapi) {
|
|
207
|
+
asyncapi.asyncapi = '2.3.0';
|
|
208
|
+
return asyncapi;
|
|
209
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyncapi/converter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Convert AsyncAPI documents from older to newer versions.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"asyncapi-converter": "cli.js"
|
|
@@ -33,18 +33,18 @@
|
|
|
33
33
|
"author": "Fran Mendez <fmvilas@gmail.com> (fmvilas.com)",
|
|
34
34
|
"license": "Apache-2.0",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"commander": "^
|
|
37
|
-
"js-yaml": "^3.
|
|
38
|
-
"lodash": "^4.17.
|
|
39
|
-
"mocha": "^6.1.4"
|
|
36
|
+
"commander": "^8.3.0",
|
|
37
|
+
"js-yaml": "^3.14.1",
|
|
38
|
+
"lodash": "^4.17.21"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
|
-
"@semantic-release/commit-analyzer": "^
|
|
43
|
-
"@semantic-release/github": "^
|
|
44
|
-
"@semantic-release/npm": "^
|
|
45
|
-
"@semantic-release/release-notes-generator": "^
|
|
46
|
-
"conventional-changelog-conventionalcommits": "^4.
|
|
47
|
-
"semantic-release": "^
|
|
41
|
+
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
42
|
+
"@semantic-release/github": "^8.0.2",
|
|
43
|
+
"@semantic-release/npm": "^8.0.3",
|
|
44
|
+
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
45
|
+
"conventional-changelog-conventionalcommits": "^4.6.3",
|
|
46
|
+
"semantic-release": "^18.0.1",
|
|
47
|
+
"mocha": "^9.1.3"
|
|
48
48
|
},
|
|
49
49
|
"release": {
|
|
50
50
|
"branches": [
|
package/test/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const assert = require('assert');
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const { convert } = require('../lib');
|
|
5
|
+
const { serialize } = require('../lib/helpers');
|
|
5
6
|
|
|
6
7
|
describe('#convert', () => {
|
|
7
8
|
it('should not convert to lowest version', () => {
|
|
@@ -179,6 +180,62 @@ describe('#convert', () => {
|
|
|
179
180
|
const result = convert(input, '2.2.0');
|
|
180
181
|
assertResults(output, result);
|
|
181
182
|
});
|
|
183
|
+
|
|
184
|
+
it('should convert from 2.1.0 to 2.3.0', () => {
|
|
185
|
+
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.1.0', 'streetlights.yml'), 'utf8');
|
|
186
|
+
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.3.0', 'streetlights.yml'), 'utf8');
|
|
187
|
+
const result = convert(input, '2.3.0');
|
|
188
|
+
assertResults(output, result);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('should convert from 2.2.0 to 2.3.0', () => {
|
|
192
|
+
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.2.0', 'streetlights.yml'), 'utf8');
|
|
193
|
+
const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.3.0', 'streetlights.yml'), 'utf8');
|
|
194
|
+
const result = convert(input, '2.3.0');
|
|
195
|
+
assertResults(output, result);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should convert from 2.0.0 to 2.1.0 (JSON case)', () => {
|
|
199
|
+
const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0', 'streetlights.json'), 'utf8');
|
|
200
|
+
let output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.json'), 'utf8');
|
|
201
|
+
let result = convert(input, '2.1.0');
|
|
202
|
+
|
|
203
|
+
output = JSON.stringify(JSON.parse(output));
|
|
204
|
+
result = JSON.stringify(JSON.parse(JSON.stringify(result)));
|
|
205
|
+
assert.strictEqual(output, result);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('#serialize', () => {
|
|
210
|
+
it('should serialize JSON', () => {
|
|
211
|
+
const input = '{"foo": "bar"}';
|
|
212
|
+
const output = serialize(input);
|
|
213
|
+
assert.strictEqual(output.isYAML, false);
|
|
214
|
+
assert.deepEqual(output.parsed, {foo: "bar"});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('should serialize YAML', () => {
|
|
218
|
+
const input = 'foo: bar';
|
|
219
|
+
const output = serialize(input);
|
|
220
|
+
assert.strictEqual(output.isYAML, true);
|
|
221
|
+
assert.deepEqual(output.parsed, {foo: "bar"});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should serialize YAML (with JSON syntax)', () => {
|
|
225
|
+
const input = '{foo: bar}';
|
|
226
|
+
const output = serialize(input);
|
|
227
|
+
assert.strictEqual(output.isYAML, true);
|
|
228
|
+
assert.deepEqual(output.parsed, {foo: "bar"});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should throw error', () => {
|
|
232
|
+
const input = '%{foo: bar}';
|
|
233
|
+
try {
|
|
234
|
+
serialize(input);
|
|
235
|
+
} catch(e) {
|
|
236
|
+
assert.strictEqual(e.message, 'AsyncAPI document must be a valid JSON or YAML document.');
|
|
237
|
+
}
|
|
238
|
+
});
|
|
182
239
|
});
|
|
183
240
|
|
|
184
241
|
/*
|
|
@@ -191,4 +248,4 @@ function removeLineBreaks(str) {
|
|
|
191
248
|
|
|
192
249
|
function assertResults(output, result){
|
|
193
250
|
assert.strictEqual(removeLineBreaks(output), removeLineBreaks(result));
|
|
194
|
-
}
|
|
251
|
+
}
|