Skip to content

Commit 36ddecb

Browse files
aayushmau5Shurtu-gal
authored andcommitted
feat: handle AsyncAPI v3 for diff command (asyncapi#1596)
Co-authored-by: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com>
1 parent 1e2af49 commit 36ddecb

File tree

6 files changed

+284
-37
lines changed

6 files changed

+284
-37
lines changed

.changeset/silent-olives-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@asyncapi/cli": patch
3+
---
4+
5+
Handle AsyncAPI v3 in diff command

package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@asyncapi/avro-schema-parser": "^3.0.23",
1212
"@asyncapi/bundler": "^0.6.4",
1313
"@asyncapi/converter": "^1.6.2",
14-
"@asyncapi/diff": "^0.4.1",
14+
"@asyncapi/diff": "^0.5.0",
1515
"@asyncapi/generator": "^1.17.25",
1616
"@asyncapi/modelina-cli": "^4.0.0-next.48",
1717
"@asyncapi/openapi-schema-parser": "^3.0.24",
@@ -172,4 +172,4 @@
172172
"action:test": "cd github-action && make test"
173173
},
174174
"types": "lib/index.d.ts"
175-
}
175+
}

src/commands/diff.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
DiffOverrideJSONError,
1515
} from '../core/errors/diff-error';
1616
import { specWatcher } from '../core/globals';
17-
import { parse, convertToOldAPI } from '../core/parser';
17+
import { parse } from '../core/parser';
1818

1919
import type { SpecWatcherParams } from '../core/globals';
2020
import { diffFlags } from '../core/flags/diff.flags';
@@ -57,10 +57,6 @@ export default class Diff extends Command {
5757
try {
5858
firstDocument = await load(firstDocumentPath);
5959

60-
if (firstDocument.isAsyncAPI3()) {
61-
this.error('Diff command does not support AsyncAPI v3 yet which was your first document, please checkout https://github.com/asyncapi/diff/issues/154');
62-
}
63-
6460
enableWatch(watchMode, {
6561
spec: firstDocument,
6662
handler: this,
@@ -83,10 +79,6 @@ export default class Diff extends Command {
8379
try {
8480
secondDocument = await load(secondDocumentPath);
8581

86-
if (secondDocument.isAsyncAPI3()) {
87-
this.error('Diff command does not support AsyncAPI v3 yet which was your second document, please checkout https://github.com/asyncapi/diff/issues/154');
88-
}
89-
9082
enableWatch(watchMode, {
9183
spec: secondDocument,
9284
handler: this,
@@ -146,9 +138,9 @@ export default class Diff extends Command {
146138
throwOnBreakingChange(diffOutput, outputFormat);
147139
}
148140
} catch (error) {
149-
if (error instanceof DiffBreakingChangeError) {
141+
if (error instanceof DiffBreakingChangeError || error instanceof TypeError) {
150142
this.error(error);
151-
}
143+
}
152144
throw new ValidationError({
153145
type: 'parser-error',
154146
err: error,
@@ -196,15 +188,13 @@ function genericOutput(diffOutput: AsyncAPIDiff, outputType: string) {
196188
}
197189

198190
async function parseDocuments(command: Command, firstDocument: Specification, secondDocument: Specification, flags: Record<string, any>) {
199-
const { document: newFirstDocumentParsed, status: firstDocumentStatus } = await parse(command, firstDocument, flags);
200-
const { document: newSecondDocumentParsed, status: secondDocumentStatus } = await parse(command, secondDocument, flags);
191+
const { document: firstDocumentParsed, status: firstDocumentStatus } = await parse(command, firstDocument, flags);
192+
const { document: secondDocumentParsed, status: secondDocumentStatus } = await parse(command, secondDocument, flags);
201193

202-
if (!newFirstDocumentParsed || !newSecondDocumentParsed || firstDocumentStatus === 'invalid' || secondDocumentStatus === 'invalid') {
194+
if (!firstDocumentParsed || !secondDocumentParsed || firstDocumentStatus === 'invalid' || secondDocumentStatus === 'invalid') {
203195
return;
204196
}
205197

206-
const firstDocumentParsed = convertToOldAPI(newFirstDocumentParsed);
207-
const secondDocumentParsed = convertToOldAPI(newSecondDocumentParsed);
208198
return { firstDocumentParsed, secondDocumentParsed };
209199
}
210200

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
asyncapi: 3.0.0
2+
id: 'urn:example:com:smartylighting:streetlights:server'
3+
info:
4+
title: AsyncAPI App
5+
version: 1.0.1
6+
description: This is a sample app.
7+
termsOfService: 'https://asyncapi.com/terms/'
8+
contact:
9+
name: API Support
10+
url: 'https://www.asyncapi.com/support'
11+
email: support@asyncapi.org
12+
license:
13+
name: Apache 2.0
14+
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
15+
tags:
16+
- name: e-commerce
17+
- name: another-tag
18+
description: Description...
19+
externalDocs:
20+
description: Find more info here
21+
url: 'https://www.asyncapi.com'
22+
defaultContentType: application/json
23+
servers:
24+
default:
25+
host: 'api.streetlights.smartylighting.com:{port}'
26+
protocol: mqtt
27+
description: Test broker
28+
variables:
29+
port:
30+
description: Secure connection (TLS) is available through port 8883.
31+
default: '8883'
32+
enum:
33+
- '1883'
34+
- '8883'
35+
security:
36+
- $ref: '#/components/securitySchemes/apiKey'
37+
- type: oauth2
38+
flows:
39+
implicit:
40+
authorizationUrl: 'https://example.com/api/oauth/dialog'
41+
availableScopes:
42+
'write:pets': modify pets in your account
43+
'read:pets': read your pets
44+
scopes:
45+
- 'write:pets'
46+
- type: openIdConnect
47+
openIdConnectUrl: https://example.com/api
48+
scopes:
49+
- 'some:scope:1'
50+
- 'some:scope:2'
51+
production:
52+
host: 'api.streetlights.smartylighting.com:{port}'
53+
pathname: /some/path-name
54+
protocol: mqtt
55+
description: Test broker
56+
variables:
57+
port:
58+
description: Secure connection (TLS) is available through port 8883.
59+
default: '1883'
60+
enum:
61+
- '1883'
62+
- '8883'
63+
security:
64+
- $ref: '#/components/securitySchemes/apiKey'
65+
withProtocol:
66+
host: 'api.streetlights.smartylighting.com:{port}'
67+
pathname: /some/path
68+
protocol: mqtt
69+
description: Test broker
70+
variables:
71+
port:
72+
description: Secure connection (TLS) is available through port 8883.
73+
default: '1883'
74+
enum:
75+
- '1883'
76+
- '8883'
77+
security:
78+
- $ref: '#/components/securitySchemes/apiKey'
79+
channels:
80+
'lightingMeasured':
81+
address: 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured'
82+
messages:
83+
lightMeasured:
84+
payload:
85+
type: object
86+
servers:
87+
- $ref: '#/servers/production'
88+
parameters:
89+
streetlightId:
90+
$ref: '#/components/parameters/streetlightId'
91+
'turnOn':
92+
address: 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on'
93+
messages:
94+
lightMeasured:
95+
$ref: '#/components/messages/lightMeasured'
96+
subscribe.message.0:
97+
$ref: '#/components/messages/turnOnOff'
98+
customMessageId:
99+
payload:
100+
type: object
101+
subscribe.message.2:
102+
payload:
103+
type: object
104+
servers:
105+
- $ref: '#/servers/default'
106+
- $ref: '#/servers/production'
107+
parameters:
108+
streetlightId:
109+
$ref: '#/components/parameters/streetlightId'
110+
customChannelId:
111+
address: 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/off'
112+
messages:
113+
turnOnOff:
114+
$ref: '#/components/messages/turnOnOff'
115+
parameters:
116+
streetlightId:
117+
$ref: '#/components/parameters/streetlightId'
118+
x-channelId: customChannelId
119+
'dim':
120+
address: 'smartylighting/streetlights/1/0/action/{streetlightId}/dim'
121+
messages:
122+
dimLight:
123+
$ref: '#/components/messages/dimLight'
124+
parameters:
125+
streetlightId:
126+
$ref: '#/components/parameters/streetlightId'
127+
operations:
128+
receiveLightMeasured:
129+
action: receive
130+
channel:
131+
$ref: '#/channels/lightingMeasured'
132+
messages:
133+
- $ref: '#/channels/lightingMeasured/messages/lightMeasured'
134+
'receiveTurnOn':
135+
action: receive
136+
channel:
137+
$ref: '#/channels/turnOn'
138+
messages:
139+
- $ref: '#/channels/turnOn/messages/lightMeasured'
140+
'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.subscribe':
141+
action: send
142+
channel:
143+
$ref: '#/channels/turnOn'
144+
messages:
145+
- $ref: '#/channels/turnOn/messages/customMessageId'
146+
- $ref: '#/channels/turnOn/messages/subscribe.message.2'
147+
turnOnOff:
148+
action: send
149+
channel:
150+
$ref: '#/channels/customChannelId'
151+
messages:
152+
- $ref: '#/channels/customChannelId/messages/turnOnOff'
153+
dimLight:
154+
action: send
155+
channel:
156+
$ref: '#/channels/dim'
157+
security:
158+
- type: oauth2
159+
flows:
160+
implicit:
161+
authorizationUrl: 'https://example.com/api/oauth/dialog'
162+
availableScopes:
163+
'write:pets': modify pets in your account
164+
'read:pets': read your pets
165+
scopes:
166+
- 'write:pets'
167+
messages:
168+
- $ref: '#/channels/dim/messages/dimLight'
169+
components:
170+
messages:
171+
lightMeasured:
172+
summary: >-
173+
Inform about environmental lighting conditions for a particular
174+
streetlight.
175+
payload:
176+
$ref: '#/components/schemas/lightMeasuredPayload'
177+
turnOnOff:
178+
summary: Command a particular streetlight to turn the lights on or off.
179+
payload:
180+
$ref: '#/components/schemas/turnOnOffPayload'
181+
dimLight:
182+
summary: Command a particular streetlight to dim the lights.
183+
payload:
184+
$ref: '#/components/schemas/dimLightPayload'
185+
schemas:
186+
lightMeasuredPayload:
187+
type: object
188+
properties:
189+
lumens:
190+
type: integer
191+
minimum: 0
192+
description: Light intensity measured in lumens.
193+
sentAt:
194+
$ref: '#/components/schemas/sentAt'
195+
turnOnOffPayload:
196+
type: object
197+
properties:
198+
command:
199+
type: string
200+
enum:
201+
- 'on'
202+
- 'off'
203+
description: Whether to turn on or off the light.
204+
sentAt:
205+
$ref: '#/components/schemas/sentAt'
206+
dimLightPayload:
207+
type: object
208+
properties:
209+
percentage:
210+
type: integer
211+
description: Percentage to which the light should be dimmed to.
212+
minimum: 0
213+
maximum: 100
214+
sentAt:
215+
$ref: '#/components/schemas/sentAt'
216+
sentAt:
217+
type: string
218+
format: date-time
219+
description: Date and time when the message was sent.
220+
securitySchemes:
221+
apiKey:
222+
type: apiKey
223+
in: user
224+
description: Provide your API key as the user and leave the password empty.
225+
flows:
226+
type: oauth2
227+
flows:
228+
implicit:
229+
authorizationUrl: 'https://example.com/api/oauth/dialog'
230+
availableScopes:
231+
'write:pets': modify pets in your account
232+
'read:pets': read your pets
233+
openIdConnect:
234+
type: openIdConnect
235+
openIdConnectUrl: https://example.com/api
236+
scopes:
237+
- 'some:scope:1'
238+
- 'some:scope:2'
239+
unusedFlows:
240+
type: oauth2
241+
flows:
242+
implicit:
243+
authorizationUrl: 'https://example.com/api/oauth/dialog'
244+
availableScopes:
245+
'write:pets': modify pets in your account
246+
'read:pets': read your pets
247+
parameters:
248+
streetlightId:
249+
description: The ID of the streetlight.

0 commit comments

Comments
 (0)