asyncapi / go-watermill-template

Go template for the AsyncAPI Generator using Watermill module
Apache License 2.0
49 stars 16 forks source link

Missing payloads on v2.5.0 #195

Closed tarampampam closed 1 year ago

tarampampam commented 1 year ago

Describe the bug

When I declare version 2.5.0 in asyncapi.yaml - payloads are missing in payloads.go.

How to Reproduce

asyncapi: 2.4.0

info:
  title: Example API
  version: 0.0.1

defaultContentType: application/json

channels:
  exampleChannel:
    publish:
      operationId: exampleChannelPublish
      message:
        $ref: '#/components/messages/ExampleMessage'
    subscribe:
      operationId: exampleChannelSubscribe
      message:
        $ref: '#/components/messages/ExampleMessage'
    bindings: {amqp: {queue: {name: undefined}}} # TODO Go template generator hack

components:
  messages:
    ExampleMessage:
      payload:
        $id: ExampleMessage
        type: object
        additionalProperties: false
        properties:
          foo:
            type: string
            description: Foo property description
            examples: [foo, bar]
            maxLength: 1
            readOnly: true
$ ag ./api/asyncapi.yaml @asyncapi/go-watermill-template --force-write -o ./go -p moduleName=events

Done! ✨
Check out your shiny new generated files at /host/go.

$ cat ./go/asyncapi/payloads.go
package asyncapi

import (
    "encoding/json"

    "github.com/ThreeDotsLabs/watermill/message"
)

// ExampleMessage represents a ExampleMessage model.
type ExampleMessage struct {
    Foo string `json:"foo"`
}

// PayloadToMessage converts a payload to watermill message
func PayloadToMessage(i interface{}) (*message.Message, error) {
    var m message.Message

    b, err := json.Marshal(i)
    if err != nil {
        return nil, nil
    }
    m.Payload = b

    return &m, nil
}

Now I change the version 2.4.0 => 2.5.0 in asyncapi.yaml and generate again:

-asyncapi: 2.4.0
+asyncapi: 2.5.0

 info:
   title: Example API
$ ag ./api/asyncapi.yaml @asyncapi/go-watermill-template --force-write -o ./go -p moduleName=events

Done! ✨
Check out your shiny new generated files at /host/go.

$ cat ./go/asyncapi/payloads.go
package asyncapi

import (
    "encoding/json"

    "github.com/ThreeDotsLabs/watermill/message"
)

// PayloadToMessage converts a payload to watermill message
func PayloadToMessage(i interface{}) (*message.Message, error) {
    var m message.Message

    b, err := json.Marshal(i)
    if err != nil {
        return nil, nil
    }
    m.Payload = b

    return &m, nil
}

As you can see, ExampleMessage is missing.

Expected behavior

All structures will be in their places.

github-actions[bot] commented 1 year ago

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

tarampampam commented 1 year ago

Related issue: https://github.com/asyncapi/modelina/issues/954