@asyncapi/converter 0.7.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.
@@ -6,21 +6,15 @@ name: Automerge release bump PR
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
13
  autoapprove:
23
- if: github.event.pull_request.draft == false && (github.actor == 'asyncapi-bot' || github.actor == 'dependabot[bot]' || github.actor == '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')
24
18
  runs-on: ubuntu-latest
25
19
  steps:
26
20
  - name: Autoapproving
@@ -42,7 +36,6 @@ jobs:
42
36
 
43
37
  automerge:
44
38
  needs: [autoapprove]
45
- 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]'
46
39
  runs-on: ubuntu-latest
47
40
  steps:
48
41
  - name: Automerging
@@ -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
@@ -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
@@ -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
@@ -37,9 +37,16 @@ if (!version) {
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asyncapi/converter",
3
- "version": "0.7.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"
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', () => {
@@ -193,6 +194,48 @@ describe('#convert', () => {
193
194
  const result = convert(input, '2.3.0');
194
195
  assertResults(output, result);
195
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
+ });
196
239
  });
197
240
 
198
241
  /*
@@ -205,4 +248,4 @@ function removeLineBreaks(str) {
205
248
 
206
249
  function assertResults(output, result){
207
250
  assert.strictEqual(removeLineBreaks(output), removeLineBreaks(result));
208
- }
251
+ }
@@ -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
+ }
@@ -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
+ }