Skip to content

Commit

Permalink
feat!: update to parser API v3 (#459)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukasz Gornicki <[email protected]>
  • Loading branch information
jonaslagoni and derberg authored Nov 29, 2023
1 parent a0be5c9 commit 542f8db
Show file tree
Hide file tree
Showing 7 changed files with 2,911 additions and 2,991 deletions.
4 changes: 3 additions & 1 deletion helpers/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export function includeFile(pathFile) {
* and annotates that specification is parsed.
*/
export function stringifySpec(asyncapi) {
return stringify(asyncapi);
const stringifiedDoc = stringify(asyncapi);
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.")
return stringifiedDoc
}

/**
Expand Down
3,812 changes: 1,937 additions & 1,875 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@
"dependencies": {
"@asyncapi/generator-react-sdk": "^1.0.0",
"@asyncapi/react-component": "^1.0.1",
"@asyncapi/parser": "^3.0.0-next-major-spec.3",
"@asyncapi/parser": "^3.0.0-next-major-spec.14",
"highlight.js": "10.7.3",
"puppeteer": "^14.1.0",
"react-dom": "^17.0.2",
"rimraf": "^3.0.2",
"sync-fetch": "^0.5.2"
},
"devDependencies": {
"@asyncapi/cli": "^0.58.5",
"@asyncapi/cli": "^1.1.8",
"cross-env": "^7.0.3",
"jest": "^26.6.3",
"jest-esm-transformer": "^1.0.0",
"markdown-toc": "^1.2.0"
},
"generator": {
"renderer": "react",
"apiVersion": "v2",
"generator": ">=1.13.0 <2.0.0",
"apiVersion": "v3",
"generator": ">=1.15.0 <2.0.0",
"parameters": {
"sidebarOrganization": {
"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.",
Expand Down
1,417 changes: 674 additions & 743 deletions test/components/__snapshots__/index.test.js.snap

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion test/components/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const parser = new Parser();

describe('Index component', () => {
it('should render AsyncAPI v3 document', async () => {
const { document } = await fromFile(parser, asyncapi_v3_path).parse();
const { document, diagnostics } = await fromFile(parser, asyncapi_v3_path).parse();
console.log(diagnostics);
expect(document).not.toBeUndefined();
const result = render(<Index asyncapi={document} params={{}}/>);
const actual = result.trim();
Expand Down
93 changes: 22 additions & 71 deletions test/spec/asyncapi_v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ info:

servers:
production:
url: mqtt://test.mosquitto.org:{port}
url: test.mosquitto.org:{port}
protocol: mqtt
description: Test broker
variables:
Expand All @@ -26,8 +26,18 @@ servers:
enum:
- '1883'
- '8883'
security:
- apiKey: []
- supportedOauthFlows:
- streetlights:on
- streetlights:off
- streetlights:dim
- openIdConnectWellKnown: []

defaultContentType: application/json
tags:
- name: One
- name: Two

channels:
smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured:
Expand All @@ -37,30 +47,13 @@ channels:
$ref: '#/components/parameters/streetlightId'
publish:
summary: Inform about environmental lighting conditions of a particular streetlight.
description: |
This is the description with **bold** text.
On multiple lines.
operationId: receiveLightMeasurement
tags:
- name: oparation-tag1
externalDocs:
description: External docs description 1
url: https://www.asyncapi.com/
- name: oparation-tag2
description: Description 2
externalDocs:
url: "https://www.asyncapi.com/"
- name: oparation-tag3
- name: oparation-tag4
description: Description 4
- name: message-tag5
externalDocs:
url: "https://www.asyncapi.com/"
traits:
- $ref: '#/components/operationTraits/kafka'
message:
$ref: '#/components/messages/lightMeasured'
tags:
- name: One

smartylighting/streetlights/1/0/action/{streetlightId}/turn/on:
parameters:
Expand All @@ -72,6 +65,8 @@ channels:
- $ref: '#/components/operationTraits/kafka'
message:
$ref: '#/components/messages/turnOnOff'
tags:
- name: Two

smartylighting/streetlights/1/0/action/{streetlightId}/turn/off:
parameters:
Expand All @@ -83,6 +78,8 @@ channels:
- $ref: '#/components/operationTraits/kafka'
message:
$ref: '#/components/messages/turnOnOff'
tags:
- name: One

smartylighting/streetlights/1/0/action/{streetlightId}/dim:
parameters:
Expand All @@ -94,13 +91,8 @@ channels:
- $ref: '#/components/operationTraits/kafka'
message:
$ref: '#/components/messages/dimLight'
some.channel:
subscribe:
description: this description shows in markdown
message:
oneOf:
- $ref: '#/components/messages/successMessage'
- $ref: '#/components/messages/failureMessage'
tags:
- name: Two

components:
messages:
Expand All @@ -109,21 +101,6 @@ components:
title: Light measured
summary: Inform about environmental lighting conditions of a particular streetlight.
contentType: application/json
tags:
- name: message-tag1
externalDocs:
description: External docs description 1
url: https://www.asyncapi.com/
- name: message-tag2
description: Description 2
externalDocs:
url: "https://www.asyncapi.com/"
- name: message-tag3
- name: message-tag4
description: Description 4
- name: message-tag5
externalDocs:
url: "https://www.asyncapi.com/"
traits:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
Expand All @@ -144,31 +121,7 @@ components:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
$ref: "#/components/schemas/dimLightPayload"
successMessage:
name: Success
payload:
type: object
properties:
result:
type: string
examples:
- success
failureMessage:
name: Failure
payload:
type: object
properties:
error:
type: object
properties:
errorCode:
type: integer
errorMessage:
type: string
examples:
- error:
errorCode: 404
errorMessage: Something messed up

schemas:
lightMeasuredPayload:
type: object
Expand All @@ -177,7 +130,6 @@ components:
type: integer
minimum: 0
description: Light intensity measured in lumens.
x-pi: false
sentAt:
$ref: "#/components/schemas/sentAt"
turnOnOffPayload:
Expand All @@ -189,7 +141,6 @@ components:
- on
- off
description: Whether to turn on or off the light.
x-pi: false
sentAt:
$ref: "#/components/schemas/sentAt"
dimLightPayload:
Expand Down Expand Up @@ -261,9 +212,9 @@ components:
type: integer
minimum: 0
maximum: 100

operationTraits:
kafka:
bindings:
kafka:
clientId: my-app-id
clientId: my-app-id
Loading

0 comments on commit 542f8db

Please sign in to comment.