lerenn / asyncapi-codegen

An AsyncAPI Golang Code generator that generates all Go code from the broker to the application/user. Just plug your application to your favorite message broker!
Apache License 2.0
76 stars 21 forks source link

AsyncAPI v3: support `servers` object as a map. #209

Closed wizzardich closed 2 months ago

wizzardich commented 2 months ago

Current Behaviour

Given the following configuration of the servers object:

servers:
  local:
    host: localhost:9092
    protocol: kafka
    protocolVersion: '3.5'
    description: Local Kafka broker
  test:
    host: test.k8s.cluster.local:9092
    protocol: kafka
    protocolVersion: '3.5'
    description: Test environment K8S Kafka cluster

The execution of asyncapi-codegen fails while unmarshalling the spec:

✘ asyncapi-codegen -i api/asyncapi/client/events.yml -o asyncapi.gen.go -g types
Error: json: cannot unmarshal object into Go struct field Specification.servers of type []*asyncapiv3.Server

According to the AsyncAPI v3 specification, the servers object is supposed to be a map.

Expected Behaviour

The objects are unmarshalled correctly according to the AsyncAPI spec.

Notes

PS. Thanks so much for this tool! We actively use oapi-codegen in our projects so having a similar toolking for AsyncAPI would be very helpful for us. Kudos!

lerenn commented 2 months ago

Hello @wizzardich, thanks for taking the time to fill in the issue and sorry about that !

I'll fix it asap, it should not be difficult :)

lerenn commented 2 months ago

Should be good now ! Feel free to reopen it if there is any problem or to open another if you encounter any other bug :)

wizzardich commented 2 months ago

Wow, that was quick! Thanks! I got another one coming :)

lerenn commented 2 months ago

Thanks ! This tool is not perfect, but little by little, we can improve it :)