@asyncapi/converter 0.4.3 → 0.6.2

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 (35) hide show
  1. package/.github/workflows/add-good-first-issue-labels.yml +68 -0
  2. package/.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml +54 -0
  3. package/.github/workflows/automerge-for-humans-merging.yml +32 -0
  4. package/.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml +35 -0
  5. package/.github/workflows/automerge-orphans.yml +63 -0
  6. package/.github/workflows/automerge.yml +24 -13
  7. package/.github/workflows/autoupdate.yml +28 -0
  8. package/.github/workflows/bump.yml +13 -13
  9. package/.github/workflows/help-command.yml +43 -0
  10. package/.github/workflows/if-go-pr-testing.yml +58 -0
  11. package/.github/workflows/if-nodejs-pr-testing.yml +54 -0
  12. package/.github/workflows/if-nodejs-release.yml +80 -0
  13. package/.github/workflows/if-nodejs-version-bump.yml +48 -0
  14. package/.github/workflows/issues-prs-notifications.yml +72 -0
  15. package/.github/workflows/lint-pr-title.yml +22 -0
  16. package/.github/workflows/release-announcements.yml +76 -0
  17. package/.github/workflows/sentiment-analysis.yml +3 -0
  18. package/.github/workflows/stale-issues-prs.yml +24 -9
  19. package/.github/workflows/welcome-first-time-contrib.yml +68 -10
  20. package/CODEOWNERS +8 -0
  21. package/README.md +2 -2
  22. package/cli.js +1 -1
  23. package/lib/index.js +71 -53
  24. package/package.json +13 -13
  25. package/test/index.js +99 -16
  26. package/test/input/1.2.0/gitter-streaming.yml +3 -2
  27. package/test/input/2.0.0/streetlights.yml +113 -0
  28. package/test/input/2.1.0/streetlights.yml +113 -0
  29. package/test/output/2.0.0/gitter-streaming.yml +2 -1
  30. package/test/output/2.0.0-rc1/gitter-streaming.yml +2 -1
  31. package/test/output/2.0.0-rc2/gitter-streaming.yml +2 -1
  32. package/test/output/2.1.0/streetlights.yml +113 -0
  33. package/test/output/2.2.0/streetlights.yml +113 -0
  34. package/.github/workflows/pull-request-testing.yml +0 -24
  35. package/.github/workflows/release.yml +0 -65
@@ -0,0 +1,48 @@
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
+ #It does magic only if there is package.json file in the root of the project
4
+ name: Version bump - if Node.js project
5
+
6
+ on:
7
+ release:
8
+ types:
9
+ - published
10
+
11
+ jobs:
12
+ version_bump:
13
+ name: Generate assets and bump
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - name: Checkout repository
17
+ uses: actions/checkout@v2
18
+ with:
19
+ # target branch of release. More info https://docs.github.com/en/rest/reference/repos#releases
20
+ # in case release is created from release branch then we need to checkout from given branch
21
+ # if @semantic-release/github is used to publish, the minimum version is 7.2.0 for proper working
22
+ ref: ${{ github.event.release.target_commitish }}
23
+ - name: Check if Node.js project and has package.json
24
+ id: packagejson
25
+ run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false"
26
+ - if: steps.packagejson.outputs.exists == 'true'
27
+ name: Install dependencies
28
+ run: npm install
29
+ - if: steps.packagejson.outputs.exists == 'true'
30
+ name: Assets generation
31
+ run: npm run generate:assets
32
+ - if: steps.packagejson.outputs.exists == 'true'
33
+ name: Bump version in package.json
34
+ # There is no need to substract "v" from the tag as version script handles it
35
+ # When adding "bump:version" script in package.json, make sure no tags are added by default (--no-git-tag-version) as they are already added by release workflow
36
+ # When adding "bump:version" script in package.json, make sure --allow-same-version is set in case someone forgot and updated package.json manually and we want to avoide this action to fail and raise confusion
37
+ run: VERSION=${{github.event.release.tag_name}} npm run bump:version
38
+ - if: steps.packagejson.outputs.exists == 'true'
39
+ name: Create Pull Request with updated asset files including package.json
40
+ uses: peter-evans/create-pull-request@v3
41
+ with:
42
+ token: ${{ secrets.GH_TOKEN }}
43
+ commit-message: 'chore(release): ${{github.event.release.tag_name}}'
44
+ committer: asyncapi-bot <info@asyncapi.io>
45
+ author: asyncapi-bot <info@asyncapi.io>
46
+ title: 'chore(release): ${{github.event.release.tag_name}}'
47
+ body: 'Version bump in package.json for release [${{github.event.release.tag_name}}](${{github.event.release.html_url}})'
48
+ branch: version-bump/${{github.event.release.tag_name}}
@@ -0,0 +1,72 @@
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
6
+
7
+ on:
8
+
9
+ issues:
10
+ types: [opened, reopened]
11
+
12
+ pull_request_target:
13
+ types: [opened, reopened, ready_for_review]
14
+
15
+ discussion:
16
+ types: [created]
17
+
18
+ jobs:
19
+
20
+ issue:
21
+ if: github.event_name == 'issues' && github.actor != 'asyncapi-bot' && github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]'
22
+ name: On every new issue
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - name: Convert markdown to slack markdown for issue
26
+ uses: LoveToKnow/slackify-markdown-action@v1.0.0
27
+ id: issuemarkdown
28
+ with:
29
+ text: "[${{github.event.issue.title}}](${{github.event.issue.html_url}}) \n ${{github.event.issue.body}}"
30
+ - name: Send info about issue
31
+ uses: rtCamp/action-slack-notify@v2
32
+ env:
33
+ SLACK_WEBHOOK: ${{secrets.SLACK_GITHUB_NEWISSUEPR}}
34
+ SLACK_TITLE: 🐛 New Issue 🐛
35
+ SLACK_MESSAGE: ${{steps.issuemarkdown.outputs.text}}
36
+ MSG_MINIMAL: true
37
+
38
+ pull_request:
39
+ if: github.event_name == 'pull_request_target' && github.actor != 'asyncapi-bot' && github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]'
40
+ name: On every new pull request
41
+ runs-on: ubuntu-latest
42
+ steps:
43
+ - name: Convert markdown to slack markdown for pull request
44
+ uses: LoveToKnow/slackify-markdown-action@v1.0.0
45
+ id: prmarkdown
46
+ with:
47
+ text: "[${{github.event.pull_request.title}}](${{github.event.pull_request.html_url}}) \n ${{github.event.pull_request.body}}"
48
+ - name: Send info about pull request
49
+ uses: rtCamp/action-slack-notify@v2
50
+ env:
51
+ SLACK_WEBHOOK: ${{secrets.SLACK_GITHUB_NEWISSUEPR}}
52
+ SLACK_TITLE: 💪 New Pull Request 💪
53
+ SLACK_MESSAGE: ${{steps.prmarkdown.outputs.text}}
54
+ MSG_MINIMAL: true
55
+
56
+ discussion:
57
+ if: github.event_name == 'discussion' && github.actor != 'asyncapi-bot' && github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]'
58
+ name: On every new pull request
59
+ runs-on: ubuntu-latest
60
+ steps:
61
+ - name: Convert markdown to slack markdown for pull request
62
+ uses: LoveToKnow/slackify-markdown-action@v1.0.0
63
+ id: discussionmarkdown
64
+ with:
65
+ text: "[${{github.event.discussion.title}}](${{github.event.discussion.html_url}}) \n ${{github.event.discussion.body}}"
66
+ - name: Send info about pull request
67
+ uses: rtCamp/action-slack-notify@v2
68
+ env:
69
+ SLACK_WEBHOOK: ${{secrets.SLACK_GITHUB_NEWISSUEPR}}
70
+ SLACK_TITLE: 💬 New Discussion 💬
71
+ SLACK_MESSAGE: ${{steps.discussionmarkdown.outputs.text}}
72
+ MSG_MINIMAL: true
@@ -0,0 +1,22 @@
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: Lint PR title
5
+
6
+ on:
7
+
8
+ pull_request_target:
9
+ types: [opened, reopened, synchronize, edited, ready_for_review]
10
+
11
+ jobs:
12
+
13
+ lint:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: amannn/action-semantic-pull-request@v3.2.5
17
+ env:
18
+ GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
19
+ with:
20
+ subjectPattern: ^(?![A-Z]).+$
21
+ subjectPatternError: |
22
+ The subject "{subject}" found in the pull request title "{title}" should start with a lowercase character.
@@ -0,0 +1,76 @@
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
+ name: 'Announce releases in different channels'
4
+
5
+ on:
6
+ release:
7
+ types:
8
+ - published
9
+
10
+ jobs:
11
+
12
+ slack:
13
+ name: Slack - notify on every release
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - name: Convert markdown to slack markdown for issue
17
+ uses: LoveToKnow/slackify-markdown-action@v1.0.0
18
+ id: markdown
19
+ with:
20
+ text: "[${{github.event.release.tag_name}}](${{github.event.release.html_url}}) \n ${{ github.event.release.body }}"
21
+ - name: Send info about release to Slack
22
+ uses: rtCamp/action-slack-notify@v2
23
+ env:
24
+ SLACK_WEBHOOK: ${{ secrets.SLACK_RELEASES }}
25
+ SLACK_TITLE: Release ${{github.event.release.tag_name}} for ${{github.repository}} is out in the wild 😱💪🍾🎂
26
+ SLACK_MESSAGE: ${{steps.markdown.outputs.text}}
27
+ MSG_MINIMAL: true
28
+
29
+ twitter:
30
+ name: Twitter - notify on minor and major releases
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - name: Checkout repo
34
+ uses: actions/checkout@v2
35
+ - name: Get version of last and previous release
36
+ uses: actions/github-script@v3
37
+ id: versions
38
+ with:
39
+ github-token: ${{ secrets.GITHUB_TOKEN }}
40
+ script: |
41
+ const query = `query($owner:String!, $name:String!) {
42
+ repository(owner:$owner, name:$name){
43
+ releases(first: 2, orderBy: {field: CREATED_AT, direction: DESC}) {
44
+ nodes {
45
+ name
46
+ }
47
+ }
48
+ }
49
+ }`;
50
+ const variables = {
51
+ owner: context.repo.owner,
52
+ name: context.repo.repo
53
+ };
54
+ const { repository: { releases: { nodes } } } = await github.graphql(query, variables);
55
+ core.setOutput('lastver', nodes[0].name);
56
+ // In case of first release in the package, there is no such thing as previous error, so we set info about previous version only once we have it
57
+ // We should tweet about the release no matter of the type as it is initial release
58
+ if (nodes.length != 1) core.setOutput('previousver', nodes[1].name);
59
+ - name: Identify release type
60
+ id: releasetype
61
+ # if previousver is not provided then this steps just logs information about missing version, no errors
62
+ run: echo "::set-output name=type::$(npx -q -p semver-diff-cli semver-diff ${{steps.versions.outputs.previousver}} ${{steps.versions.outputs.lastver}})"
63
+ - name: Get name of the person that is behind the newly released version
64
+ id: author
65
+ run: echo "::set-output name=name::$(git log -1 --pretty=format:'%an')"
66
+ - name: Publish information about the release to Twitter # tweet only if detected version change is not a patch
67
+ # tweet goes out even if the type is not major or minor but "You need provide version number to compare."
68
+ # it is ok, it just means we did not identify previous version as we are tweeting out information about the release for the first time
69
+ if: steps.releasetype.outputs.type != 'null' && steps.releasetype.outputs.type != 'patch' # null means that versions are the same
70
+ uses: m1ner79/Github-Twittction@v1.0.1
71
+ with:
72
+ twitter_status: "Release ${{github.event.release.tag_name}} for ${{github.repository}} is out in the wild 😱💪🍾🎂\n\nThank you for the contribution ${{ steps.author.outputs.name }} ${{github.event.release.html_url}}"
73
+ twitter_consumer_key: ${{ secrets.TWITTER_CONSUMER_KEY }}
74
+ twitter_consumer_secret: ${{ secrets.TWITTER_CONSUMER_SECRET }}
75
+ twitter_access_token_key: ${{ secrets.TWITTER_ACCESS_TOKEN_KEY }}
76
+ twitter_access_token_secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
@@ -1,3 +1,6 @@
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
+
1
4
  name: 'Sentiment Analysis'
2
5
 
3
6
  on:
@@ -1,3 +1,6 @@
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
+
1
4
  name: Manage stale issues and PRs
2
5
 
3
6
  on:
@@ -8,20 +11,32 @@ jobs:
8
11
  stale:
9
12
  runs-on: ubuntu-latest
10
13
  steps:
11
- - uses: actions/stale@v1.1.0
14
+ - uses: actions/stale@v4.0.0
12
15
  with:
13
16
  repo-token: ${{ secrets.GITHUB_TOKEN }}
14
17
  stale-issue-message: |
15
18
  This issue has been automatically marked as stale because it has not had recent activity :sleeping:
16
- It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
17
- Thank you for your contributions :heart:
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:
18
27
  stale-pr-message: |
19
28
  This pull request has been automatically marked as stale because it has not had recent activity :sleeping:
20
- It will be closed in 30 days if no further activity occurs. To unstale this pull request, add a comment with detailed explanation.
21
- Thank you for your contributions :heart:
22
- days-before-stale: 60
23
- days-before-close: 30
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
24
39
  stale-issue-label: stale
25
40
  stale-pr-label: stale
26
- exempt-issue-label: keep-open
27
- exempt-pr-label: keep-open
41
+ exempt-issue-labels: keep-open
42
+ exempt-pr-labels: keep-open
@@ -1,3 +1,6 @@
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
+
1
4
  name: Welcome first time contributors
2
5
 
3
6
  on:
@@ -12,14 +15,69 @@ jobs:
12
15
  welcome:
13
16
  runs-on: ubuntu-latest
14
17
  steps:
15
- - uses: actions/first-interaction@v1
18
+ - uses: actions/github-script@v3
16
19
  with:
17
- repo-token: ${{ secrets.GITHUB_TOKEN }}
18
- issue-message: |
19
- Welcome to AsyncAPI. Thanks a lot for reporting your first issue.
20
-
21
- 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).
22
- pr-message: |
23
- Welcome to AsyncAPI. Thanks a lot for creating your first pull request.
24
-
25
- 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).
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/README.md CHANGED
@@ -5,7 +5,7 @@ Convert [AsyncAPI](https://asyncapi.com) documents older to newer versions.
5
5
  ## Installation
6
6
 
7
7
  ```sh
8
- npm i -g asyncapi-converter
8
+ npm i -g @asyncapi/converter
9
9
  ```
10
10
 
11
11
  ## Usage
@@ -43,7 +43,7 @@ asyncapi-converter streetlights.yml > streetlights2.yml
43
43
  ### As a package
44
44
 
45
45
  ```js
46
- const { convert } = require('asyncapi-converter')
46
+ const { convert } = require('@asyncapi/converter')
47
47
 
48
48
  try {
49
49
  const asyncapi = fs.readFileSync('streetlights.yml', 'utf-8')
package/cli.js CHANGED
@@ -32,7 +32,7 @@ if (!asyncapiFile) {
32
32
  program.help(); // This exits the process
33
33
  }
34
34
  if (!version) {
35
- version = '2.0.0';
35
+ version = '2.2.0';
36
36
  }
37
37
 
38
38
  try {
package/lib/index.js CHANGED
@@ -10,49 +10,74 @@ const {
10
10
 
11
11
  const lib = module.exports;
12
12
 
13
+ /**
14
+ * Value for key (version) represents the function which converts specification from previous version to the given as key.
15
+ */
13
16
  const conversions = {
14
- '1.0.0-to-2.0.0-rc1': from1to2rc1,
15
- '1.1.0-to-2.0.0-rc1': from1to2rc1,
16
- '1.2.0-to-2.0.0-rc1': from1to2rc1,
17
- '2.0.0-rc1-to-2.0.0-rc2': from2rc1to2rc2,
18
- '1.0.0-to-2.0.0-rc2': from1to2rc2,
19
- '1.1.0-to-2.0.0-rc2': from1to2rc2,
20
- '1.2.0-to-2.0.0-rc2': from1to2rc2,
21
- '1.0.0-to-2.0.0': from1to2,
22
- '1.1.0-to-2.0.0': from1to2,
23
- '1.2.0-to-2.0.0': from1to2,
24
- '2.0.0-rc1-to-2.0.0': from2rc1to2,
25
- '2.0.0-rc2-to-2.0.0': from2rc2to2,
26
-
27
- };
17
+ '1.0.0': undefined,
18
+ '1.1.0': from__1_0_0__to__1_1_0,
19
+ '1.2.0': from__1_1_0__to__1_2_0,
20
+ '2.0.0-rc1': from__1_2_0__to__2_0_0_rc1,
21
+ '2.0.0-rc2': from__2_0_0_rc1__to__2_0_0_rc2,
22
+ '2.0.0': from__2_0_0_rc2__to__2_0_0,
23
+ '2.1.0': from__2_0_0__to__2_1_0,
24
+ '2.2.0': from__2_1_0__to__2_2_0,
25
+ }
26
+ const conversionVersions = Object.keys(conversions);
28
27
 
29
28
  lib.convert = (asyncapi, version, options = {}) => {
30
29
  const { isYAML, parsed } = serialize(asyncapi);
31
30
  if (parsed === undefined) return '';
32
31
 
33
- const conversion = `${parsed.asyncapi}-to-${version}`;
32
+ let fromVersion = conversionVersions.indexOf(parsed.asyncapi);
33
+ const toVersion = conversionVersions.indexOf(version);
34
+
35
+ if (fromVersion === -1 || toVersion === -1) {
36
+ console.error(`Cannot convert from ${parsed.asyncapi} to ${version}.`);
37
+ return;
38
+ }
39
+ if (fromVersion > toVersion) {
40
+ console.error(`Cannot downgrade from ${parsed.asyncapi} to ${version}.`);
41
+ return;
42
+ }
43
+ if (fromVersion === toVersion) {
44
+ console.error(`Cannot convert to the same version.`);
45
+ return;
46
+ }
47
+
48
+ // add 1 to `fromVersion` because we convert from previous to next
49
+ fromVersion++;
50
+ let converted = parsed;
51
+ for (let i = fromVersion; i <= toVersion; i++) {
52
+ const fn = conversions[conversionVersions[i]];
53
+ converted = fn(converted, options);
54
+ }
34
55
 
35
- if (conversions[conversion]) {
36
- const result = conversions[conversion](parsed, options);
37
- let converted = result;
38
- if (isYAML) converted = yaml.safeDump(result, { skipInvalid: true });
39
- return converted;
40
- } else {
41
- console.error(`Can't convert from ${parsed.asyncapi} to ${version}.`);
56
+ if (isYAML) {
57
+ converted = yaml.safeDump(converted, { skipInvalid: true });
42
58
  }
59
+ return converted;
43
60
  };
44
61
 
45
- function from1to2rc1 (asyncapi1, options) {
62
+ function from__1_0_0__to__1_1_0(asyncapi) {
63
+ return asyncapi;
64
+ }
65
+
66
+ function from__1_1_0__to__1_2_0(asyncapi) {
67
+ return asyncapi;
68
+ }
69
+
70
+ function from__1_2_0__to__2_0_0_rc1(asyncapi1, options) { // NOSONAR
46
71
  const result = asyncapi1;
47
72
 
48
73
  result.asyncapi = '2.0.0-rc1';
49
74
  result.id = options.id || `urn:${asyncapi1.info.title.toLowerCase().split(' ').join('.')}`;
50
-
75
+
51
76
  if (asyncapi1.servers) {
52
77
  const security = asyncapi1.security;
53
78
  result.servers = asyncapi1.servers.map(server => {
54
79
  const { scheme, schemeVersion, ...rest } = server;
55
-
80
+
56
81
  const out = {
57
82
  ...rest,
58
83
  ...{
@@ -69,9 +94,10 @@ function from1to2rc1 (asyncapi1, options) {
69
94
  return out;
70
95
  });
71
96
  }
72
-
97
+
73
98
  if (asyncapi1.topics) {
74
- result.channels = _.mapKeys(result.topics, (_, topicName) => dotsToSlashes(`${asyncapi1.baseTopic ? `${asyncapi1.baseTopic}.` : ''}${topicName}`));
99
+ const baseTopic = asyncapi1.baseTopic ? `${asyncapi1.baseTopic}.` : "";
100
+ result.channels = _.mapKeys(result.topics, (__, topicName) => dotsToSlashes(`${baseTopic}${topicName}`));
75
101
  _.map(result.channels, ch => {
76
102
  if (ch.publish) {
77
103
  ch.publish = { message: ch.publish };
@@ -89,7 +115,7 @@ function from1to2rc1 (asyncapi1, options) {
89
115
  '/': eventToChannel(asyncapi1.events),
90
116
  };
91
117
  }
92
-
118
+
93
119
  delete result.topics;
94
120
  delete result.stream;
95
121
  delete result.events;
@@ -99,12 +125,12 @@ function from1to2rc1 (asyncapi1, options) {
99
125
  return result;
100
126
  }
101
127
 
102
- function from2rc1to2rc2 (asyncapi2rc1, options) {
128
+ function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi2rc1, options) { // NOSONAR
103
129
  const result = asyncapi2rc1;
104
130
 
105
131
  result.asyncapi = '2.0.0-rc2';
106
132
  result.id = result.id || options.id;
107
-
133
+
108
134
  if (asyncapi2rc1.servers) {
109
135
  const serverMap = {};
110
136
  asyncapi2rc1.servers.forEach((server, index) => {
@@ -114,12 +140,12 @@ function from2rc1to2rc2 (asyncapi2rc1, options) {
114
140
  });
115
141
  result.servers = serverMap;
116
142
  }
117
-
143
+
118
144
  if (result.channels) {
119
145
  _.each(result.channels, (channel, channelName) => {
120
146
  if (channel.parameters) {
121
147
  const parametersMap = {};
122
- const paramNames = channelName.match(/\{([^\}]+)\}/g).map(p => p.substr(1, p.length - 2));
148
+ const paramNames = channelName.match(/\{([^\}]{1,100})\}/g).map(p => p.substr(1, p.length - 2));
123
149
  channel.parameters.forEach((parameter, index) => {
124
150
  const name = parameter.name || paramNames[index];
125
151
  if (parameter.name) delete parameter.name;
@@ -132,7 +158,7 @@ function from2rc1to2rc2 (asyncapi2rc1, options) {
132
158
  const message = channel.publish.message;
133
159
  convertMessage(message);
134
160
  }
135
-
161
+
136
162
  if (channel.subscribe && channel.subscribe.message) {
137
163
  const message = channel.subscribe.message;
138
164
  convertMessage(message);
@@ -152,36 +178,28 @@ function from2rc1to2rc2 (asyncapi2rc1, options) {
152
178
  channel.subscribe.bindings = channel.subscribe.protocolInfo;
153
179
  delete channel.subscribe.protocolInfo;
154
180
  }
155
- });
181
+ });
156
182
  }
157
183
 
184
+ if (!options.id) delete result.id;
158
185
  return result;
159
186
  }
160
187
 
161
- function from1to2rc2 (asyncapi1, options) {
162
- let res = from1to2rc1(asyncapi1, options);
163
- if (!options.id) delete res.id;
164
- return from2rc1to2rc2(res, options);
165
- }
166
-
167
- // Release 2.0.0 mappings
168
-
169
- function from1to2 (asyncapi1, options) {
170
- return from2rc2to2(from1to2rc2(asyncapi1, options), options);
171
- }
172
-
173
- function from2rc1to2 (asyncapi2rc1, options) {
174
- let result = from2rc1to2rc2(asyncapi2rc1, options);
188
+ function from__2_0_0_rc2__to__2_0_0(asyncapi2rc2, options) {
189
+ const result = asyncapi2rc2;
175
190
  if (!options.id) delete result.id;
176
191
  result.asyncapi = '2.0.0';
177
-
178
192
  return result;
179
193
  }
180
194
 
181
- // version 2.0.0-rc2 has the same schema as 2.0.0 release
182
- function from2rc2to2 (asyncapi2rc2, options) {
183
- const result = asyncapi2rc2;
184
- result.asyncapi = '2.0.0';
195
+ function from__2_0_0__to__2_1_0(asyncapi2) {
196
+ const result = asyncapi2;
197
+ result.asyncapi = '2.1.0';
198
+ return result;
199
+ }
185
200
 
201
+ function from__2_1_0__to__2_2_0(asyncapi2) {
202
+ const result = asyncapi2;
203
+ result.asyncapi = '2.2.0';
186
204
  return result;
187
205
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asyncapi/converter",
3
- "version": "0.4.3",
3
+ "version": "0.6.2",
4
4
  "description": "Convert AsyncAPI documents from older to newer versions.",
5
5
  "bin": {
6
6
  "asyncapi-converter": "cli.js"
@@ -10,8 +10,8 @@
10
10
  "test": "mocha",
11
11
  "lint": "echo 'no linter configured yet'",
12
12
  "release": "semantic-release",
13
- "get-version": "echo $npm_package_version",
14
- "get-name": "echo $npm_package_name"
13
+ "generate:assets": "echo 'No additional assets need to be generated at the moment'",
14
+ "bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION"
15
15
  },
16
16
  "keywords": [
17
17
  "asyncapi",
@@ -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": "^2.20.0",
37
- "js-yaml": "^3.13.1",
38
- "lodash": "^4.17.15",
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": "^8.0.1",
43
- "@semantic-release/github": "^7.0.4",
44
- "@semantic-release/npm": "^7.0.3",
45
- "@semantic-release/release-notes-generator": "^9.0.1",
46
- "conventional-changelog-conventionalcommits": "^4.2.3",
47
- "semantic-release": "^17.0.4"
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": [