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
91 stars 23 forks source link

[bug] Typed headers can't be parsed from message #241

Closed matoous closed 3 months ago

matoous commented 3 months ago

When using $ref in headers the headers can't be parsed from the message as they are not typed back to specific type properly. Minimal example:

asyncapi: 3.0.0
info:
  title: Sample App
  version: 1.0.0
channels:
  v3.issue333.msg: # channel that has the two operations
    messages:
      ping:
        name: Ping
        payload:
          type: object
          properties:
            event:
              type: string
              const: ping
        headers:
          name: test_headers
          type: object
          properties:
            event_id:
              $ref: "#/components/schemas/eventId"
          required:
            - event_id
components:
  schemas:
    eventId:
      type: string

Generating code for the above results in following code:

    // Get each headers from broker message
    for k, v := range bMsg.Headers {
        switch {
        case k == "event_id": // Retrieving EventId header
            msg.Headers.EventId = (v)
        default:
            // TODO: log unknown error
        }
    }

where msg.Headers.EventId is of type EventIdSchema but we are trying to assign []byte to it.

lerenn commented 3 months ago

Thanks for bringing this issue and a PR ! I'll take a look at it right now :)