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

Ref to schema in other file? #193

Closed lo00l closed 2 months ago

lo00l commented 2 months ago

First of all, thank you for your package! This is exactly what I was looking for.

Suppose I have 2 yaml files: asyncapi.yaml:

asyncapi: 2.6.0
info:
  title: Test
  version: 1.0.0

defaultContentType: application/json

channels:
  test:
    description: Test
    subscribe:
      operationId: Test
      message:
        $ref: "#/components/messages/TestMessage"
    bindings:
      kafka:
        is: topic

components:
  messages:
    TestMessage:
      messageId: TestMessage
      name: TestMessage
      payload:
        $ref: "common.yaml#/components/schemas/Foo"

common.yaml:

components:
  schemas:
    Foo:
      type: object
      properties:
        bar:
          type: string

When I run asyncapi-codegen -g types -i asyncapi.yaml -o ./models.gen.go -p test I get error error when using AsyncAPI: invalid reference: empty target for schema reference "common.yaml#/components/schemas/Foo".

Is it even possible to define my schemas in separate file to make it reusable?

lerenn commented 2 months ago

Hello @lo00l ! Thanks for your interest in this project ☺️

Well, this is a really interesting feature which is not yet developed. There is another issue with kinda the same request, so I'll do a PR to have this ASAP as it should not be difficult (I aim for the end of the week, but no guarantee).

lerenn commented 2 months ago

Should be fixed now ! Do not hesitate to reopen this thread if needed !