Skip to content

Commit 542f8db

Browse files
jonaslagoniderberg
andauthored
feat!: update to parser API v3 (#459)
Co-authored-by: Lukasz Gornicki <[email protected]>
1 parent a0be5c9 commit 542f8db

File tree

7 files changed

+2911
-2991
lines changed

7 files changed

+2911
-2991
lines changed

helpers/all.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ export function includeFile(pathFile) {
133133
* and annotates that specification is parsed.
134134
*/
135135
export function stringifySpec(asyncapi) {
136-
return stringify(asyncapi);
136+
const stringifiedDoc = stringify(asyncapi);
137+
if(stringifiedDoc === undefined) throw new Error("Unable to stringify parsed AsyncAPI document passed by the generator. Please report an issue in https://github.com/asyncapi/html-template repository.")
138+
return stringifiedDoc
137139
}
138140

139141
/**

package-lock.json

+1,937-1,875
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@
3939
"dependencies": {
4040
"@asyncapi/generator-react-sdk": "^1.0.0",
4141
"@asyncapi/react-component": "^1.0.1",
42-
"@asyncapi/parser": "^3.0.0-next-major-spec.3",
42+
"@asyncapi/parser": "^3.0.0-next-major-spec.14",
4343
"highlight.js": "10.7.3",
4444
"puppeteer": "^14.1.0",
4545
"react-dom": "^17.0.2",
4646
"rimraf": "^3.0.2",
4747
"sync-fetch": "^0.5.2"
4848
},
4949
"devDependencies": {
50-
"@asyncapi/cli": "^0.58.5",
50+
"@asyncapi/cli": "^1.1.8",
5151
"cross-env": "^7.0.3",
5252
"jest": "^26.6.3",
5353
"jest-esm-transformer": "^1.0.0",
5454
"markdown-toc": "^1.2.0"
5555
},
5656
"generator": {
5757
"renderer": "react",
58-
"apiVersion": "v2",
59-
"generator": ">=1.13.0 <2.0.0",
58+
"apiVersion": "v3",
59+
"generator": ">=1.15.0 <2.0.0",
6060
"parameters": {
6161
"sidebarOrganization": {
6262
"description": "Defines how the sidebar should be organized. 'byTags' to categorize operations by tags in the root of the document, `byTagsNoRoot` does the same but for pub/sub tags.",

test/components/__snapshots__/index.test.js.snap

+674-743
Large diffs are not rendered by default.

test/components/index.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const parser = new Parser();
88

99
describe('Index component', () => {
1010
it('should render AsyncAPI v3 document', async () => {
11-
const { document } = await fromFile(parser, asyncapi_v3_path).parse();
11+
const { document, diagnostics } = await fromFile(parser, asyncapi_v3_path).parse();
12+
console.log(diagnostics);
1213
expect(document).not.toBeUndefined();
1314
const result = render(<Index asyncapi={document} params={{}}/>);
1415
const actual = result.trim();

test/spec/asyncapi_v2.yml

+22-71
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ info:
1616

1717
servers:
1818
production:
19-
url: mqtt://test.mosquitto.org:{port}
19+
url: test.mosquitto.org:{port}
2020
protocol: mqtt
2121
description: Test broker
2222
variables:
@@ -26,8 +26,18 @@ servers:
2626
enum:
2727
- '1883'
2828
- '8883'
29+
security:
30+
- apiKey: []
31+
- supportedOauthFlows:
32+
- streetlights:on
33+
- streetlights:off
34+
- streetlights:dim
35+
- openIdConnectWellKnown: []
2936

3037
defaultContentType: application/json
38+
tags:
39+
- name: One
40+
- name: Two
3141

3242
channels:
3343
smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured:
@@ -37,30 +47,13 @@ channels:
3747
$ref: '#/components/parameters/streetlightId'
3848
publish:
3949
summary: Inform about environmental lighting conditions of a particular streetlight.
40-
description: |
41-
This is the description with **bold** text.
42-
43-
On multiple lines.
4450
operationId: receiveLightMeasurement
45-
tags:
46-
- name: oparation-tag1
47-
externalDocs:
48-
description: External docs description 1
49-
url: https://www.asyncapi.com/
50-
- name: oparation-tag2
51-
description: Description 2
52-
externalDocs:
53-
url: "https://www.asyncapi.com/"
54-
- name: oparation-tag3
55-
- name: oparation-tag4
56-
description: Description 4
57-
- name: message-tag5
58-
externalDocs:
59-
url: "https://www.asyncapi.com/"
6051
traits:
6152
- $ref: '#/components/operationTraits/kafka'
6253
message:
6354
$ref: '#/components/messages/lightMeasured'
55+
tags:
56+
- name: One
6457

6558
smartylighting/streetlights/1/0/action/{streetlightId}/turn/on:
6659
parameters:
@@ -72,6 +65,8 @@ channels:
7265
- $ref: '#/components/operationTraits/kafka'
7366
message:
7467
$ref: '#/components/messages/turnOnOff'
68+
tags:
69+
- name: Two
7570

7671
smartylighting/streetlights/1/0/action/{streetlightId}/turn/off:
7772
parameters:
@@ -83,6 +78,8 @@ channels:
8378
- $ref: '#/components/operationTraits/kafka'
8479
message:
8580
$ref: '#/components/messages/turnOnOff'
81+
tags:
82+
- name: One
8683

8784
smartylighting/streetlights/1/0/action/{streetlightId}/dim:
8885
parameters:
@@ -94,13 +91,8 @@ channels:
9491
- $ref: '#/components/operationTraits/kafka'
9592
message:
9693
$ref: '#/components/messages/dimLight'
97-
some.channel:
98-
subscribe:
99-
description: this description shows in markdown
100-
message:
101-
oneOf:
102-
- $ref: '#/components/messages/successMessage'
103-
- $ref: '#/components/messages/failureMessage'
94+
tags:
95+
- name: Two
10496

10597
components:
10698
messages:
@@ -109,21 +101,6 @@ components:
109101
title: Light measured
110102
summary: Inform about environmental lighting conditions of a particular streetlight.
111103
contentType: application/json
112-
tags:
113-
- name: message-tag1
114-
externalDocs:
115-
description: External docs description 1
116-
url: https://www.asyncapi.com/
117-
- name: message-tag2
118-
description: Description 2
119-
externalDocs:
120-
url: "https://www.asyncapi.com/"
121-
- name: message-tag3
122-
- name: message-tag4
123-
description: Description 4
124-
- name: message-tag5
125-
externalDocs:
126-
url: "https://www.asyncapi.com/"
127104
traits:
128105
- $ref: '#/components/messageTraits/commonHeaders'
129106
payload:
@@ -144,31 +121,7 @@ components:
144121
- $ref: '#/components/messageTraits/commonHeaders'
145122
payload:
146123
$ref: "#/components/schemas/dimLightPayload"
147-
successMessage:
148-
name: Success
149-
payload:
150-
type: object
151-
properties:
152-
result:
153-
type: string
154-
examples:
155-
- success
156-
failureMessage:
157-
name: Failure
158-
payload:
159-
type: object
160-
properties:
161-
error:
162-
type: object
163-
properties:
164-
errorCode:
165-
type: integer
166-
errorMessage:
167-
type: string
168-
examples:
169-
- error:
170-
errorCode: 404
171-
errorMessage: Something messed up
124+
172125
schemas:
173126
lightMeasuredPayload:
174127
type: object
@@ -177,7 +130,6 @@ components:
177130
type: integer
178131
minimum: 0
179132
description: Light intensity measured in lumens.
180-
x-pi: false
181133
sentAt:
182134
$ref: "#/components/schemas/sentAt"
183135
turnOnOffPayload:
@@ -189,7 +141,6 @@ components:
189141
- on
190142
- off
191143
description: Whether to turn on or off the light.
192-
x-pi: false
193144
sentAt:
194145
$ref: "#/components/schemas/sentAt"
195146
dimLightPayload:
@@ -261,9 +212,9 @@ components:
261212
type: integer
262213
minimum: 0
263214
maximum: 100
264-
215+
265216
operationTraits:
266217
kafka:
267218
bindings:
268219
kafka:
269-
clientId: my-app-id
220+
clientId: my-app-id

0 commit comments

Comments
 (0)