@asyncapi/converter 0.6.2 → 0.8.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.
@@ -11,7 +11,7 @@ on:
11
11
 
12
12
  jobs:
13
13
  add-labels:
14
- if: github.event.issue && github.event.issue.state != 'closed'
14
+ if: ${{!github.event.issue.pull_request && github.event.issue.state != 'closed' && github.actor != 'asyncapi-bot'}}
15
15
  runs-on: ubuntu-latest
16
16
  steps:
17
17
  - name: Add label
@@ -32,7 +32,7 @@ jobs:
32
32
  values[1] = 'docs';
33
33
  }
34
34
  if(values.length != 2 || !areas.includes(values[1])){
35
- const message = `Hey @${context.payload.sender.login}, something is wrong with your command please use \`/help\` for help.`
35
+ const message = `Hey @${context.payload.sender.login}, your message doesn't follow the requirements, you can try \`/help\`.`
36
36
 
37
37
  await github.rest.issues.createComment({
38
38
  issue_number: context.issue.number,
@@ -27,6 +27,6 @@ jobs:
27
27
  GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}"
28
28
  MERGE_LABELS: "!do-not-merge,ready-to-merge"
29
29
  MERGE_METHOD: "squash"
30
- MERGE_COMMIT_MESSAGE: "pull-request-title"
30
+ MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})"
31
31
  MERGE_RETRIES: "20"
32
32
  MERGE_RETRY_SLEEP: "30000"
@@ -1,27 +1,20 @@
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.
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
3
 
4
4
  name: Automerge release bump PR
5
5
 
6
6
  on:
7
7
  pull_request_target:
8
8
  types:
9
- - labeled
10
- - unlabeled
11
- - synchronize
12
9
  - opened
13
- - edited
14
- - ready_for_review
15
- - reopened
16
- - unlocked
17
- pull_request_review:
18
- types:
19
- - submitted
10
+ - synchronize
20
11
 
21
12
  jobs:
22
-
23
13
  autoapprove:
24
- if: github.event.pull_request.draft == false && (github.event.pull_request.user.login == 'asyncapi-bot' || github.event.pull_request.user.login == 'dependabot[bot]' || github.event.pull_request.user.login == 'dependabot-preview[bot]') && !contains(github.event.pull_request.labels.*.name, 'released')
14
+ if: >
15
+ contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]"]'), github.event.pull_request.user.login) &&
16
+ contains(fromJson('["asyncapi-bot", "dependabot[bot]", "dependabot-preview[bot]"]'), github.actor) &&
17
+ !contains(github.event.pull_request.labels.*.name, 'released')
25
18
  runs-on: ubuntu-latest
26
19
  steps:
27
20
  - name: Autoapproving
@@ -39,12 +32,10 @@ jobs:
39
32
  owner: context.repo.owner,
40
33
  repo: context.repo.repo,
41
34
  labels: ['autoapproved']
42
- })
43
-
35
+ })
44
36
 
45
37
  automerge:
46
38
  needs: [autoapprove]
47
- if: github.event.pull_request.user.login == 'asyncapi-bot' || github.event.pull_request.user.login == 'dependabot[bot]' || github.event.pull_request.user.login == 'dependabot-preview[bot]'
48
39
  runs-on: ubuntu-latest
49
40
  steps:
50
41
  - name: Automerging
@@ -54,6 +45,6 @@ jobs:
54
45
  GITHUB_LOGIN: asyncapi-bot
55
46
  MERGE_LABELS: ""
56
47
  MERGE_METHOD: "squash"
57
- MERGE_COMMIT_MESSAGE: "pull-request-title"
48
+ MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})"
58
49
  MERGE_RETRIES: "20"
59
50
  MERGE_RETRY_SLEEP: "30000"
@@ -2,7 +2,7 @@
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
4
  #This workflow is designed to work with:
5
- # - autoapprove and automerge workflows for dependabot and asyncapibot.
5
+ # - autoapprove and automerge workflows for dependabot and asyncapibot.
6
6
  # - special release branches that we from time to time create in upstream repos. If we open up PRs for them from the very beginning of the release, the release branch will constantly update with new things from the destination branch they are opened against
7
7
 
8
8
  # It uses GitHub Action that auto-updates pull requests branches, whenever changes are pushed to their destination branch.
@@ -11,17 +11,21 @@
11
11
  name: autoupdate
12
12
 
13
13
  on:
14
- push: {}
15
-
16
- jobs:
14
+ push:
15
+ branches-ignore:
16
+ - 'version-bump/**'
17
+ - 'dependabot/**'
18
+ - 'bot/**'
19
+ - 'all-contributors/**'
17
20
 
21
+ jobs:
18
22
  autoupdate:
19
23
  runs-on: ubuntu-latest
20
24
  steps:
21
25
  - name: Autoupdating
22
26
  uses: docker://chinthakagodawita/autoupdate-action:v1
23
27
  env:
24
- GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
28
+ GITHUB_TOKEN: '${{ secrets.GH_TOKEN }}'
25
29
  PR_FILTER: "labelled"
26
30
  PR_LABELS: "autoapproved"
27
31
  PR_READY_STATE: "ready_for_review"
@@ -15,6 +15,7 @@ on:
15
15
 
16
16
  jobs:
17
17
  bump:
18
+ if: startsWith(github.event.commits[0].message, 'chore(release):')
18
19
  runs-on: ubuntu-latest
19
20
  steps:
20
21
  - name: Checkout repo
@@ -22,9 +23,9 @@ jobs:
22
23
  - name: Check if Node.js project and has package.json
23
24
  id: packagejson
24
25
  run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false"
25
- - if: steps.packagejson.outputs.exists == 'true' && startsWith(github.event.commits[0].message, 'chore(release):')
26
+ - if: steps.packagejson.outputs.exists == 'true'
26
27
  name: Bumping latest version of this package in other repositories
27
- uses: derberg/npm-dependency-manager-for-your-github-org@v3
28
+ uses: derberg/npm-dependency-manager-for-your-github-org@v4
28
29
  with:
29
30
  github_token: ${{ secrets.GH_TOKEN }}
30
31
  committer_username: asyncapi-bot
@@ -10,7 +10,7 @@ on:
10
10
 
11
11
  jobs:
12
12
  create_help_comment_pr:
13
- if: github.event.issue.pull_request && contains(github.event.comment.body, '/help')
13
+ if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/help') && github.actor != 'asyncapi-bot' }}
14
14
  runs-on: ubuntu-latest
15
15
  steps:
16
16
  - uses: actions-ecosystem/action-create-comment@v1
@@ -26,7 +26,7 @@ jobs:
26
26
  - `/ready-to-merge` or `/rtm` - This comment will trigger automerge of PR in case all required checks are green, approvals in place and do-not-merge label is not added
27
27
  - `/do-not-merge` or `/dnm` - This comment will block automerging even if all conditions are met and ready-to-merge label is added
28
28
  create_help_comment_issue:
29
- if: ${{ !github.event.issue.pull_request && contains(github.event.comment.body, '/help') }}
29
+ if: ${{ !github.event.issue.pull_request && contains(github.event.comment.body, '/help') && github.actor != 'asyncapi-bot' }}
30
30
  runs-on: ubuntu-latest
31
31
  steps:
32
32
  - uses: actions-ecosystem/action-create-comment@v1
@@ -6,16 +6,21 @@ name: PR testing - if Go project
6
6
  on:
7
7
  pull_request:
8
8
  types: [opened, reopened, synchronize, ready_for_review]
9
-
9
+
10
10
  jobs:
11
11
  lint:
12
- if: github.event.pull_request.draft == false
13
12
  name: lint
14
13
  runs-on: ubuntu-latest
15
14
  steps:
16
- - name: Checkout repository
15
+ - if: "github.event.pull_request.draft == false &&!((github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'ci: update global workflows')) || (github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'chore(release):')) || (github.actor == 'allcontributors' && startsWith(github.event.pull_request.title, 'docs: add')))"
16
+ id: should_run
17
+ name: Should Run
18
+ run: echo "::set-output name=shouldrun::true"
19
+ - if: steps.should_run.outputs.shouldrun == 'true'
20
+ name: Checkout repository
17
21
  uses: actions/checkout@v2
18
- - name: Check if Go project and has go.mod
22
+ - if: steps.should_run.outputs.shouldrun == 'true'
23
+ name: Check if Go project and has go.mod
19
24
  id: gomod
20
25
  run: test -e ./go.mod && echo "::set-output name=exists::true" || echo "::set-output name=exists::false"
21
26
  shell: bash
@@ -31,16 +36,21 @@ jobs:
31
36
  skip-go-installation: true # we wanna control the version of Go in use
32
37
 
33
38
  test:
34
- if: github.event.pull_request.draft == false
35
39
  name: ${{ matrix.os }}
36
40
  runs-on: ${{ matrix.os }}
37
41
  strategy:
38
42
  matrix:
39
43
  os: [ubuntu-latest, macos-latest, windows-latest]
40
44
  steps:
41
- - name: Checkout repository
45
+ - if: "github.event.pull_request.draft == false &&!((github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'ci: update global workflows')) || (github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'chore(release):')) || (github.actor == 'allcontributors' && startsWith(github.event.pull_request.title, 'docs: add')))"
46
+ id: should_run
47
+ name: Should Run
48
+ run: echo "::set-output name=shouldrun::true"
49
+ - if: steps.should_run.outputs.shouldrun == 'true'
50
+ name: Checkout repository
42
51
  uses: actions/checkout@v2
43
- - name: Check if Go project and has go.mod
52
+ - if: steps.should_run.outputs.shouldrun == 'true'
53
+ name: Check if Go project and has go.mod
44
54
  id: gomod
45
55
  run: test -e ./go.mod && echo "::set-output name=exists::true" || echo "::set-output name=exists::false"
46
56
  shell: bash
@@ -9,20 +9,26 @@ on:
9
9
 
10
10
  jobs:
11
11
  test:
12
- if: github.event.pull_request.draft == false
13
12
  name: ${{ matrix.os }}
14
13
  runs-on: ${{ matrix.os }}
15
14
  strategy:
16
15
  matrix:
17
16
  os: [ubuntu-latest, macos-latest, windows-latest]
18
17
  steps:
19
- - name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows
18
+ - if: "github.event.pull_request.draft == false &&!((github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'ci: update global workflows')) || (github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'chore(release):')) || (github.actor == 'allcontributors' && startsWith(github.event.pull_request.title, 'docs: add')))"
19
+ id: should_run
20
+ name: Should Run
21
+ run: echo "::set-output name=shouldrun::true"
22
+ - if: steps.should_run.outputs.shouldrun == 'true'
23
+ name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows
20
24
  run: |
21
25
  git config --global core.autocrlf false
22
26
  git config --global core.eol lf
23
- - name: Checkout repository
27
+ - if: steps.should_run.outputs.shouldrun == 'true'
28
+ name: Checkout repository
24
29
  uses: actions/checkout@v2
25
- - name: Check if Node.js project and has package.json
30
+ - if: steps.should_run.outputs.shouldrun == 'true'
31
+ name: Check if Node.js project and has package.json
26
32
  id: packagejson
27
33
  run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false"
28
34
  shell: bash
@@ -10,7 +10,10 @@ on:
10
10
  # below lines are not enough to have release supported for these branches
11
11
  # make sure configuration of `semantic-release` package mentiones these branches
12
12
  - next
13
- - '**-release'
13
+ - next-major
14
+ - beta
15
+ - alpha
16
+ - '**-release' # custom
14
17
 
15
18
  jobs:
16
19
 
@@ -47,7 +50,7 @@ jobs:
47
50
 
48
51
  release:
49
52
  needs: test
50
- name: Publish to NPM and GitHub
53
+ name: Publish to any of NPM, Github, and Docker Hub
51
54
  runs-on: ubuntu-latest
52
55
  steps:
53
56
  - name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows
@@ -68,11 +71,13 @@ jobs:
68
71
  name: Install dependencies
69
72
  run: npm install
70
73
  - if: steps.packagejson.outputs.exists == 'true'
71
- name: Release to NPM and GitHub
74
+ name: Publish to any of NPM, Github, and Docker Hub
72
75
  id: release
73
76
  env:
74
77
  GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
75
78
  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
79
+ DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
80
+ DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
76
81
  GIT_AUTHOR_NAME: asyncapi-bot
77
82
  GIT_AUTHOR_EMAIL: info@asyncapi.io
78
83
  GIT_COMMITTER_NAME: asyncapi-bot
@@ -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
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.2.0';
35
+ version = '2.3.0';
36
36
  }
37
37
 
38
38
  try {
39
39
  const asyncapi = fs.readFileSync(asyncapiFile, 'utf-8');
40
- console.log(converter.convert(asyncapi, version, {
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: false,
15
- parsed: JSON.parse(text)
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
 
@@ -33,16 +34,13 @@ lib.convert = (asyncapi, version, options = {}) => {
33
34
  const toVersion = conversionVersions.indexOf(version);
34
35
 
35
36
  if (fromVersion === -1 || toVersion === -1) {
36
- console.error(`Cannot convert from ${parsed.asyncapi} to ${version}.`);
37
- return;
37
+ throw new Error(`Cannot convert from ${parsed.asyncapi} to ${version}.`);
38
38
  }
39
39
  if (fromVersion > toVersion) {
40
- console.error(`Cannot downgrade from ${parsed.asyncapi} to ${version}.`);
41
- return;
40
+ throw new Error(`Cannot downgrade from ${parsed.asyncapi} to ${version}.`);
42
41
  }
43
42
  if (fromVersion === toVersion) {
44
- console.error(`Cannot convert to the same version.`);
45
- return;
43
+ throw new Error(`Cannot convert to the same version.`);
46
44
  }
47
45
 
48
46
  // add 1 to `fromVersion` because we convert from previous to next
@@ -181,6 +179,12 @@ function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi2rc1, options) { // NOSONAR
181
179
  });
182
180
  }
183
181
 
182
+ if (result.components && result.components.parameters) {
183
+ _.each(result.components.parameters, (parameter) => {
184
+ if (parameter.name) delete parameter.name;
185
+ });
186
+ }
187
+
184
188
  if (!options.id) delete result.id;
185
189
  return result;
186
190
  }
@@ -192,14 +196,17 @@ function from__2_0_0_rc2__to__2_0_0(asyncapi2rc2, options) {
192
196
  return result;
193
197
  }
194
198
 
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
+ function from__2_0_0__to__2_1_0(asyncapi) {
200
+ asyncapi.asyncapi = '2.1.0';
201
+ return asyncapi;
199
202
  }
200
203
 
201
- function from__2_1_0__to__2_2_0(asyncapi2) {
202
- const result = asyncapi2;
203
- result.asyncapi = '2.2.0';
204
- return result;
204
+ function from__2_1_0__to__2_2_0(asyncapi) {
205
+ asyncapi.asyncapi = '2.2.0';
206
+ return asyncapi;
205
207
  }
208
+
209
+ function from__2_2_0__to__2_3_0(asyncapi) {
210
+ asyncapi.asyncapi = '2.3.0';
211
+ return asyncapi;
212
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asyncapi/converter",
3
- "version": "0.6.2",
3
+ "version": "0.8.0",
4
4
  "description": "Convert AsyncAPI documents from older to newer versions.",
5
5
  "bin": {
6
6
  "asyncapi-converter": "cli.js"
package/test/index.js CHANGED
@@ -2,21 +2,28 @@ 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', () => {
8
- const result = convert(`asyncapi: '2.1.0'`, '2.0.0');
9
- assert.strictEqual(result, undefined);
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
+ );
10
13
  });
11
14
 
12
15
  it('should not convert from non existing version', () => {
13
- const result = convert(`asyncapi: '2.0.0-rc3'`, '2.1.0');
14
- assert.strictEqual(result, undefined);
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
+ );
15
20
  });
16
21
 
17
22
  it('should not convert to this same version', () => {
18
- const result = convert(`asyncapi: '2.1.0'`, '2.1.0');
19
- assert.strictEqual(result, undefined);
23
+ assert.throws(
24
+ () => convert(`asyncapi: '2.1.0'`, '2.1.0'),
25
+ /^Error: Cannot convert to the same version.$/
26
+ );
20
27
  });
21
28
 
22
29
  it('should convert from 1.0.0 to 2.0.0-rc1', () => {
@@ -179,6 +186,62 @@ describe('#convert', () => {
179
186
  const result = convert(input, '2.2.0');
180
187
  assertResults(output, result);
181
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
+ });
182
245
  });
183
246
 
184
247
  /*
@@ -191,4 +254,4 @@ function removeLineBreaks(str) {
191
254
 
192
255
  function assertResults(output, result){
193
256
  assert.strictEqual(removeLineBreaks(output), removeLineBreaks(result));
194
- }
257
+ }
@@ -0,0 +1,172 @@
1
+ {
2
+ "asyncapi": "2.0.0",
3
+ "info": {
4
+ "title": "Streetlights API",
5
+ "version": "1.0.0",
6
+ "description": "The Smartylighting Streetlights API allows you to remotely manage the city lights.\n\n### Check out its awesome features:\n\n* Turn a specific streetlight on/off 🌃\n* Dim a specific streetlight 😎\n* Receive real-time information about environmental lighting conditions 📈\n",
7
+ "license": {
8
+ "name": "Apache 2.0",
9
+ "url": "https://www.apache.org/licenses/LICENSE-2.0"
10
+ }
11
+ },
12
+ "servers": {
13
+ "default": {
14
+ "url": "api.streetlights.smartylighting.com:{port}",
15
+ "description": "Test broker",
16
+ "variables": {
17
+ "port": {
18
+ "description": "Secure connection (TLS) is available through port 8883.",
19
+ "default": "1883",
20
+ "enum": [
21
+ "1883",
22
+ "8883"
23
+ ]
24
+ }
25
+ },
26
+ "protocol": "mqtt",
27
+ "security": [
28
+ {
29
+ "apiKey": []
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ "components": {
35
+ "messages": {
36
+ "lightMeasured": {
37
+ "summary": "Inform about environmental lighting conditions for a particular streetlight.",
38
+ "payload": {
39
+ "$ref": "#/components/schemas/lightMeasuredPayload"
40
+ }
41
+ },
42
+ "turnOnOff": {
43
+ "summary": "Command a particular streetlight to turn the lights on or off.",
44
+ "payload": {
45
+ "$ref": "#/components/schemas/turnOnOffPayload"
46
+ }
47
+ },
48
+ "dimLight": {
49
+ "summary": "Command a particular streetlight to dim the lights.",
50
+ "payload": {
51
+ "$ref": "#/components/schemas/dimLightPayload"
52
+ }
53
+ }
54
+ },
55
+ "schemas": {
56
+ "lightMeasuredPayload": {
57
+ "type": "object",
58
+ "properties": {
59
+ "lumens": {
60
+ "type": "integer",
61
+ "minimum": 0,
62
+ "description": "Light intensity measured in lumens."
63
+ },
64
+ "sentAt": {
65
+ "$ref": "#/components/schemas/sentAt"
66
+ }
67
+ }
68
+ },
69
+ "turnOnOffPayload": {
70
+ "type": "object",
71
+ "properties": {
72
+ "command": {
73
+ "type": "string",
74
+ "enum": [
75
+ "on",
76
+ "off"
77
+ ],
78
+ "description": "Whether to turn on or off the light."
79
+ },
80
+ "sentAt": {
81
+ "$ref": "#/components/schemas/sentAt"
82
+ }
83
+ }
84
+ },
85
+ "dimLightPayload": {
86
+ "type": "object",
87
+ "properties": {
88
+ "percentage": {
89
+ "type": "integer",
90
+ "description": "Percentage to which the light should be dimmed to.",
91
+ "minimum": 0,
92
+ "maximum": 100
93
+ },
94
+ "sentAt": {
95
+ "$ref": "#/components/schemas/sentAt"
96
+ }
97
+ }
98
+ },
99
+ "sentAt": {
100
+ "type": "string",
101
+ "format": "date-time",
102
+ "description": "Date and time when the message was sent."
103
+ }
104
+ },
105
+ "securitySchemes": {
106
+ "apiKey": {
107
+ "type": "apiKey",
108
+ "in": "user",
109
+ "description": "Provide your API key as the user and leave the password empty."
110
+ }
111
+ },
112
+ "parameters": {
113
+ "streetlightId": {
114
+ "name": "streetlightId",
115
+ "description": "The ID of the streetlight.",
116
+ "schema": {
117
+ "type": "string"
118
+ }
119
+ }
120
+ }
121
+ },
122
+ "channels": {
123
+ "smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured": {
124
+ "parameters": {
125
+ "streetlightId": {
126
+ "$ref": "#/components/parameters/streetlightId"
127
+ }
128
+ },
129
+ "publish": {
130
+ "message": {
131
+ "$ref": "#/components/messages/lightMeasured"
132
+ }
133
+ }
134
+ },
135
+ "smartylighting/streetlights/1/0/action/{streetlightId}/turn/on": {
136
+ "parameters": {
137
+ "streetlightId": {
138
+ "$ref": "#/components/parameters/streetlightId"
139
+ }
140
+ },
141
+ "subscribe": {
142
+ "message": {
143
+ "$ref": "#/components/messages/turnOnOff"
144
+ }
145
+ }
146
+ },
147
+ "smartylighting/streetlights/1/0/action/{streetlightId}/turn/off": {
148
+ "parameters": {
149
+ "streetlightId": {
150
+ "$ref": "#/components/parameters/streetlightId"
151
+ }
152
+ },
153
+ "subscribe": {
154
+ "message": {
155
+ "$ref": "#/components/messages/turnOnOff"
156
+ }
157
+ }
158
+ },
159
+ "smartylighting/streetlights/1/0/action/{streetlightId}/dim": {
160
+ "parameters": {
161
+ "streetlightId": {
162
+ "$ref": "#/components/parameters/streetlightId"
163
+ }
164
+ },
165
+ "subscribe": {
166
+ "message": {
167
+ "$ref": "#/components/messages/dimLight"
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
@@ -78,7 +78,6 @@ components:
78
78
  description: Provide your API key as the user and leave the password empty.
79
79
  parameters:
80
80
  streetlightId:
81
- name: streetlightId
82
81
  description: The ID of the streetlight.
83
82
  schema:
84
83
  type: string
@@ -78,7 +78,6 @@ components:
78
78
  description: Provide your API key as the user and leave the password empty.
79
79
  parameters:
80
80
  streetlightId:
81
- name: streetlightId
82
81
  description: The ID of the streetlight.
83
82
  schema:
84
83
  type: string
@@ -78,7 +78,6 @@ components:
78
78
  description: Provide your API key as the user and leave the password empty.
79
79
  parameters:
80
80
  streetlightId:
81
- name: streetlightId
82
81
  description: The ID of the streetlight.
83
82
  schema:
84
83
  type: string
@@ -0,0 +1,112 @@
1
+ asyncapi: 2.2.0
2
+ info:
3
+ title: Streetlights API
4
+ version: 1.0.0
5
+ description: "The Smartylighting Streetlights API allows you to remotely manage the city lights.\n\n### Check out its awesome features:\n\n* Turn a specific streetlight on/off \U0001F303\n* Dim a specific streetlight \U0001F60E\n* Receive real-time information about environmental lighting conditions \U0001F4C8\n"
6
+ license:
7
+ name: Apache 2.0
8
+ url: 'https://www.apache.org/licenses/LICENSE-2.0'
9
+ servers:
10
+ default:
11
+ url: 'api.streetlights.smartylighting.com:{port}'
12
+ description: Test broker
13
+ variables:
14
+ port:
15
+ description: Secure connection (TLS) is available through port 8883.
16
+ default: '1883'
17
+ enum:
18
+ - '1883'
19
+ - '8883'
20
+ protocol: mqtt
21
+ security:
22
+ - apiKey: []
23
+ components:
24
+ messages:
25
+ lightMeasured:
26
+ summary: >-
27
+ Inform about environmental lighting conditions for a particular
28
+ streetlight.
29
+ payload:
30
+ $ref: '#/components/schemas/lightMeasuredPayload'
31
+ turnOnOff:
32
+ summary: Command a particular streetlight to turn the lights on or off.
33
+ payload:
34
+ $ref: '#/components/schemas/turnOnOffPayload'
35
+ dimLight:
36
+ summary: Command a particular streetlight to dim the lights.
37
+ payload:
38
+ $ref: '#/components/schemas/dimLightPayload'
39
+ schemas:
40
+ lightMeasuredPayload:
41
+ type: object
42
+ properties:
43
+ lumens:
44
+ type: integer
45
+ minimum: 0
46
+ description: Light intensity measured in lumens.
47
+ sentAt:
48
+ $ref: '#/components/schemas/sentAt'
49
+ turnOnOffPayload:
50
+ type: object
51
+ properties:
52
+ command:
53
+ type: string
54
+ enum:
55
+ - 'on'
56
+ - 'off'
57
+ description: Whether to turn on or off the light.
58
+ sentAt:
59
+ $ref: '#/components/schemas/sentAt'
60
+ dimLightPayload:
61
+ type: object
62
+ properties:
63
+ percentage:
64
+ type: integer
65
+ description: Percentage to which the light should be dimmed to.
66
+ minimum: 0
67
+ maximum: 100
68
+ sentAt:
69
+ $ref: '#/components/schemas/sentAt'
70
+ sentAt:
71
+ type: string
72
+ format: date-time
73
+ description: Date and time when the message was sent.
74
+ securitySchemes:
75
+ apiKey:
76
+ type: apiKey
77
+ in: user
78
+ description: Provide your API key as the user and leave the password empty.
79
+ parameters:
80
+ streetlightId:
81
+ description: The ID of the streetlight.
82
+ schema:
83
+ type: string
84
+ channels:
85
+ 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured':
86
+ parameters:
87
+ streetlightId:
88
+ $ref: '#/components/parameters/streetlightId'
89
+ publish:
90
+ message:
91
+ $ref: '#/components/messages/lightMeasured'
92
+ 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on':
93
+ parameters:
94
+ streetlightId:
95
+ $ref: '#/components/parameters/streetlightId'
96
+ subscribe:
97
+ message:
98
+ $ref: '#/components/messages/turnOnOff'
99
+ 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/off':
100
+ parameters:
101
+ streetlightId:
102
+ $ref: '#/components/parameters/streetlightId'
103
+ subscribe:
104
+ message:
105
+ $ref: '#/components/messages/turnOnOff'
106
+ 'smartylighting/streetlights/1/0/action/{streetlightId}/dim':
107
+ parameters:
108
+ streetlightId:
109
+ $ref: '#/components/parameters/streetlightId'
110
+ subscribe:
111
+ message:
112
+ $ref: '#/components/messages/dimLight'
@@ -78,7 +78,6 @@ components:
78
78
  description: Provide your API key as the user and leave the password empty.
79
79
  parameters:
80
80
  streetlightId:
81
- name: streetlightId
82
81
  description: The ID of the streetlight.
83
82
  schema:
84
83
  type: string
@@ -78,7 +78,6 @@ components:
78
78
  description: Provide your API key as the user and leave the password empty.
79
79
  parameters:
80
80
  streetlightId:
81
- name: streetlightId
82
81
  description: The ID of the streetlight.
83
82
  schema:
84
83
  type: string
@@ -0,0 +1,172 @@
1
+ {
2
+ "asyncapi": "2.1.0",
3
+ "info": {
4
+ "title": "Streetlights API",
5
+ "version": "1.0.0",
6
+ "description": "The Smartylighting Streetlights API allows you to remotely manage the city lights.\n\n### Check out its awesome features:\n\n* Turn a specific streetlight on/off 🌃\n* Dim a specific streetlight 😎\n* Receive real-time information about environmental lighting conditions 📈\n",
7
+ "license": {
8
+ "name": "Apache 2.0",
9
+ "url": "https://www.apache.org/licenses/LICENSE-2.0"
10
+ }
11
+ },
12
+ "servers": {
13
+ "default": {
14
+ "url": "api.streetlights.smartylighting.com:{port}",
15
+ "description": "Test broker",
16
+ "variables": {
17
+ "port": {
18
+ "description": "Secure connection (TLS) is available through port 8883.",
19
+ "default": "1883",
20
+ "enum": [
21
+ "1883",
22
+ "8883"
23
+ ]
24
+ }
25
+ },
26
+ "protocol": "mqtt",
27
+ "security": [
28
+ {
29
+ "apiKey": []
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ "components": {
35
+ "messages": {
36
+ "lightMeasured": {
37
+ "summary": "Inform about environmental lighting conditions for a particular streetlight.",
38
+ "payload": {
39
+ "$ref": "#/components/schemas/lightMeasuredPayload"
40
+ }
41
+ },
42
+ "turnOnOff": {
43
+ "summary": "Command a particular streetlight to turn the lights on or off.",
44
+ "payload": {
45
+ "$ref": "#/components/schemas/turnOnOffPayload"
46
+ }
47
+ },
48
+ "dimLight": {
49
+ "summary": "Command a particular streetlight to dim the lights.",
50
+ "payload": {
51
+ "$ref": "#/components/schemas/dimLightPayload"
52
+ }
53
+ }
54
+ },
55
+ "schemas": {
56
+ "lightMeasuredPayload": {
57
+ "type": "object",
58
+ "properties": {
59
+ "lumens": {
60
+ "type": "integer",
61
+ "minimum": 0,
62
+ "description": "Light intensity measured in lumens."
63
+ },
64
+ "sentAt": {
65
+ "$ref": "#/components/schemas/sentAt"
66
+ }
67
+ }
68
+ },
69
+ "turnOnOffPayload": {
70
+ "type": "object",
71
+ "properties": {
72
+ "command": {
73
+ "type": "string",
74
+ "enum": [
75
+ "on",
76
+ "off"
77
+ ],
78
+ "description": "Whether to turn on or off the light."
79
+ },
80
+ "sentAt": {
81
+ "$ref": "#/components/schemas/sentAt"
82
+ }
83
+ }
84
+ },
85
+ "dimLightPayload": {
86
+ "type": "object",
87
+ "properties": {
88
+ "percentage": {
89
+ "type": "integer",
90
+ "description": "Percentage to which the light should be dimmed to.",
91
+ "minimum": 0,
92
+ "maximum": 100
93
+ },
94
+ "sentAt": {
95
+ "$ref": "#/components/schemas/sentAt"
96
+ }
97
+ }
98
+ },
99
+ "sentAt": {
100
+ "type": "string",
101
+ "format": "date-time",
102
+ "description": "Date and time when the message was sent."
103
+ }
104
+ },
105
+ "securitySchemes": {
106
+ "apiKey": {
107
+ "type": "apiKey",
108
+ "in": "user",
109
+ "description": "Provide your API key as the user and leave the password empty."
110
+ }
111
+ },
112
+ "parameters": {
113
+ "streetlightId": {
114
+ "name": "streetlightId",
115
+ "description": "The ID of the streetlight.",
116
+ "schema": {
117
+ "type": "string"
118
+ }
119
+ }
120
+ }
121
+ },
122
+ "channels": {
123
+ "smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured": {
124
+ "parameters": {
125
+ "streetlightId": {
126
+ "$ref": "#/components/parameters/streetlightId"
127
+ }
128
+ },
129
+ "publish": {
130
+ "message": {
131
+ "$ref": "#/components/messages/lightMeasured"
132
+ }
133
+ }
134
+ },
135
+ "smartylighting/streetlights/1/0/action/{streetlightId}/turn/on": {
136
+ "parameters": {
137
+ "streetlightId": {
138
+ "$ref": "#/components/parameters/streetlightId"
139
+ }
140
+ },
141
+ "subscribe": {
142
+ "message": {
143
+ "$ref": "#/components/messages/turnOnOff"
144
+ }
145
+ }
146
+ },
147
+ "smartylighting/streetlights/1/0/action/{streetlightId}/turn/off": {
148
+ "parameters": {
149
+ "streetlightId": {
150
+ "$ref": "#/components/parameters/streetlightId"
151
+ }
152
+ },
153
+ "subscribe": {
154
+ "message": {
155
+ "$ref": "#/components/messages/turnOnOff"
156
+ }
157
+ }
158
+ },
159
+ "smartylighting/streetlights/1/0/action/{streetlightId}/dim": {
160
+ "parameters": {
161
+ "streetlightId": {
162
+ "$ref": "#/components/parameters/streetlightId"
163
+ }
164
+ },
165
+ "subscribe": {
166
+ "message": {
167
+ "$ref": "#/components/messages/dimLight"
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
@@ -78,7 +78,6 @@ components:
78
78
  description: Provide your API key as the user and leave the password empty.
79
79
  parameters:
80
80
  streetlightId:
81
- name: streetlightId
82
81
  description: The ID of the streetlight.
83
82
  schema:
84
83
  type: string
@@ -78,7 +78,6 @@ components:
78
78
  description: Provide your API key as the user and leave the password empty.
79
79
  parameters:
80
80
  streetlightId:
81
- name: streetlightId
82
81
  description: The ID of the streetlight.
83
82
  schema:
84
83
  type: string
@@ -0,0 +1,112 @@
1
+ asyncapi: 2.3.0
2
+ info:
3
+ title: Streetlights API
4
+ version: 1.0.0
5
+ description: "The Smartylighting Streetlights API allows you to remotely manage the city lights.\n\n### Check out its awesome features:\n\n* Turn a specific streetlight on/off \U0001F303\n* Dim a specific streetlight \U0001F60E\n* Receive real-time information about environmental lighting conditions \U0001F4C8\n"
6
+ license:
7
+ name: Apache 2.0
8
+ url: 'https://www.apache.org/licenses/LICENSE-2.0'
9
+ servers:
10
+ default:
11
+ url: 'api.streetlights.smartylighting.com:{port}'
12
+ description: Test broker
13
+ variables:
14
+ port:
15
+ description: Secure connection (TLS) is available through port 8883.
16
+ default: '1883'
17
+ enum:
18
+ - '1883'
19
+ - '8883'
20
+ protocol: mqtt
21
+ security:
22
+ - apiKey: []
23
+ components:
24
+ messages:
25
+ lightMeasured:
26
+ summary: >-
27
+ Inform about environmental lighting conditions for a particular
28
+ streetlight.
29
+ payload:
30
+ $ref: '#/components/schemas/lightMeasuredPayload'
31
+ turnOnOff:
32
+ summary: Command a particular streetlight to turn the lights on or off.
33
+ payload:
34
+ $ref: '#/components/schemas/turnOnOffPayload'
35
+ dimLight:
36
+ summary: Command a particular streetlight to dim the lights.
37
+ payload:
38
+ $ref: '#/components/schemas/dimLightPayload'
39
+ schemas:
40
+ lightMeasuredPayload:
41
+ type: object
42
+ properties:
43
+ lumens:
44
+ type: integer
45
+ minimum: 0
46
+ description: Light intensity measured in lumens.
47
+ sentAt:
48
+ $ref: '#/components/schemas/sentAt'
49
+ turnOnOffPayload:
50
+ type: object
51
+ properties:
52
+ command:
53
+ type: string
54
+ enum:
55
+ - 'on'
56
+ - 'off'
57
+ description: Whether to turn on or off the light.
58
+ sentAt:
59
+ $ref: '#/components/schemas/sentAt'
60
+ dimLightPayload:
61
+ type: object
62
+ properties:
63
+ percentage:
64
+ type: integer
65
+ description: Percentage to which the light should be dimmed to.
66
+ minimum: 0
67
+ maximum: 100
68
+ sentAt:
69
+ $ref: '#/components/schemas/sentAt'
70
+ sentAt:
71
+ type: string
72
+ format: date-time
73
+ description: Date and time when the message was sent.
74
+ securitySchemes:
75
+ apiKey:
76
+ type: apiKey
77
+ in: user
78
+ description: Provide your API key as the user and leave the password empty.
79
+ parameters:
80
+ streetlightId:
81
+ description: The ID of the streetlight.
82
+ schema:
83
+ type: string
84
+ channels:
85
+ 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured':
86
+ parameters:
87
+ streetlightId:
88
+ $ref: '#/components/parameters/streetlightId'
89
+ publish:
90
+ message:
91
+ $ref: '#/components/messages/lightMeasured'
92
+ 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on':
93
+ parameters:
94
+ streetlightId:
95
+ $ref: '#/components/parameters/streetlightId'
96
+ subscribe:
97
+ message:
98
+ $ref: '#/components/messages/turnOnOff'
99
+ 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/off':
100
+ parameters:
101
+ streetlightId:
102
+ $ref: '#/components/parameters/streetlightId'
103
+ subscribe:
104
+ message:
105
+ $ref: '#/components/messages/turnOnOff'
106
+ 'smartylighting/streetlights/1/0/action/{streetlightId}/dim':
107
+ parameters:
108
+ streetlightId:
109
+ $ref: '#/components/parameters/streetlightId'
110
+ subscribe:
111
+ message:
112
+ $ref: '#/components/messages/dimLight'