Skip to content

Commit c267f14

Browse files
authored
fix: support for Avro schemes in async spec parsing [TDX-7063] (#743)
1 parent cef6d67 commit c267f14

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
},
5555
"dependencies": {
5656
"@apidevtools/json-schema-ref-parser": "14.0.3",
57+
"@asyncapi/avro-schema-parser": "^3.0.24",
5758
"@asyncapi/openapi-schema-parser": "^3.0.24",
5859
"@asyncapi/parser": "^3.4.0",
5960
"@floating-ui/vue": "^1.1.9",

pnpm-lock.yaml

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

src/composables/useSchemaParser.spec.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,73 @@ components:
416416
expect((parsedDocument.value as ServiceNode).children[0].data.security[0][0].flows.clientCredentials.scopes).toEqual(scopes)
417417
})
418418
})
419+
420+
describe('async api parsing', () => {
421+
422+
it('should parse avro', async () => {
423+
const specContent = `asyncapi: 3.0.0
424+
info:
425+
title: Traffic Light Events
426+
version: '1.0.0'
427+
428+
servers:
429+
kafka-broker:
430+
host: localhost:9092
431+
protocol: kafka
432+
433+
channels:
434+
traffic-light.state:
435+
address: traffic-light.state
436+
messages:
437+
trafficLightState:
438+
$ref: "#/components/messages/TrafficLightStateMessage"
439+
440+
operations:
441+
publishTrafficLightState:
442+
action: send
443+
channel:
444+
$ref: "#/channels/traffic-light.state"
445+
messages:
446+
- $ref: "#/channels/traffic-light.state/messages/trafficLightState"
447+
448+
consumeTrafficLightState:
449+
action: receive
450+
channel:
451+
$ref: "#/channels/traffic-light.state"
452+
messages:
453+
- $ref: "#/channels/traffic-light.state/messages/trafficLightState"
454+
455+
components:
456+
messages:
457+
TrafficLightStateMessage:
458+
name: TrafficLightStateMessage
459+
title: Traffic Light State
460+
summary: Current state of a traffic light
461+
contentType: application/avro-binary
462+
payload:
463+
schemaFormat: application/vnd.apache.avro+json;version=1.9.0
464+
schema:
465+
type: record
466+
name: TrafficLightState
467+
namespace: com.example.traffic
468+
fields:
469+
- name: intersectionId
470+
type: string
471+
- name: state
472+
type:
473+
type: enum
474+
name: LightState
475+
symbols: ["RED", "YELLOW", "GREEN"]
476+
- name: changedAt
477+
type: string
478+
`
479+
480+
const { parseSpecDocument, tableOfContents } = composables.useSchemaParser()
481+
await parseSpecDocument(specContent)
482+
expect(tableOfContents.value?.length).toEqual(3)
483+
484+
})
485+
})
419486
})
420487

421488

src/composables/useSchemaParser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ export default (): {
109109
if (!asyncParser) {
110110
const AsyncParser:any = await import('@asyncapi/parser/browser')
111111
const OpenAPISchemaParser:any = await import('@asyncapi/openapi-schema-parser')
112+
const AvroSchemaParser: any = await import('@asyncapi/avro-schema-parser')
113+
112114
asyncParser = new AsyncParser.default()
113115
asyncParser.registerSchemaParser(OpenAPISchemaParser.default())
116+
asyncParser.registerSchemaParser(AvroSchemaParser.default())
114117
}
115118

116119
let specToParse = spec

0 commit comments

Comments
 (0)