Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"dependencies": {
"@apidevtools/json-schema-ref-parser": "14.0.3",
"@asyncapi/avro-schema-parser": "^3.0.24",
"@asyncapi/openapi-schema-parser": "^3.0.24",
"@asyncapi/parser": "^3.4.0",
"@floating-ui/vue": "^1.1.9",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions src/composables/useSchemaParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,73 @@ components:
expect((parsedDocument.value as ServiceNode).children[0].data.security[0][0].flows.clientCredentials.scopes).toEqual(scopes)
})
})

describe('async api parsing', () => {

it('should parse avro', async () => {
const specContent = `asyncapi: 3.0.0
info:
title: Traffic Light Events
version: '1.0.0'

servers:
kafka-broker:
host: localhost:9092
protocol: kafka

channels:
traffic-light.state:
address: traffic-light.state
messages:
trafficLightState:
$ref: "#/components/messages/TrafficLightStateMessage"

operations:
publishTrafficLightState:
action: send
channel:
$ref: "#/channels/traffic-light.state"
messages:
- $ref: "#/channels/traffic-light.state/messages/trafficLightState"

consumeTrafficLightState:
action: receive
channel:
$ref: "#/channels/traffic-light.state"
messages:
- $ref: "#/channels/traffic-light.state/messages/trafficLightState"

components:
messages:
TrafficLightStateMessage:
name: TrafficLightStateMessage
title: Traffic Light State
summary: Current state of a traffic light
contentType: application/avro-binary
payload:
schemaFormat: application/vnd.apache.avro+json;version=1.9.0
schema:
type: record
name: TrafficLightState
namespace: com.example.traffic
fields:
- name: intersectionId
type: string
- name: state
type:
type: enum
name: LightState
symbols: ["RED", "YELLOW", "GREEN"]
- name: changedAt
type: string
`

const { parseSpecDocument, tableOfContents } = composables.useSchemaParser()
await parseSpecDocument(specContent)
expect(tableOfContents.value?.length).toEqual(3)

})
})
})


3 changes: 3 additions & 0 deletions src/composables/useSchemaParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ export default (): {
if (!asyncParser) {
const AsyncParser:any = await import('@asyncapi/parser/browser')
const OpenAPISchemaParser:any = await import('@asyncapi/openapi-schema-parser')
const AvroSchemaParser: any = await import('@asyncapi/avro-schema-parser')

asyncParser = new AsyncParser.default()
asyncParser.registerSchemaParser(OpenAPISchemaParser.default())
asyncParser.registerSchemaParser(AvroSchemaParser.default())
}

let specToParse = spec
Expand Down
Loading