Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

References and compatibility with OpenApi #224

Open
nuttert opened this issue May 27, 2024 · 6 comments
Open

References and compatibility with OpenApi #224

nuttert opened this issue May 27, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@nuttert
Copy link

nuttert commented May 27, 2024

Hey, I use both async(fro streams) and open(for rest) api. And it's quite common case when it's needed to use some structure for requests and streams at the same time:

Type:
      payload:
        x-go-type: common.Type
        x-go-type-import: 
          path: /my-module/path

This approach will work, but it breaks the sense of schemas - I can't use it for other languages and, for instance, front-end developers can't use it.

But official specification provide refs for such cases:

Type:
     payload:
         $ref: "../common/schemas/common.yaml#/components/schemas/Type"

And the case not only for open api but also for other schemas for async api e.g. when two services use the same structure.

@lerenn
Copy link
Owner

lerenn commented May 27, 2024

Hello @nuttert ! Thanks for the issue !

Normally, it should have enable by this issue: #192
Do you have an error when you're trying to import a schema from an openapi schema? :)

@nuttert
Copy link
Author

nuttert commented May 28, 2024

Okay I see it, thanks, but yes I could not generate a code with ref:
I created UserMeta message with payload:
image

I expected it will create a structure UserMeta and Payload will have the UserMeta type.

But it generated these:
image

(I pointed to the dependencies in the input -i ../schemas/channels_api.yaml,../../common/schemas/common.yaml)

@lerenn
Copy link
Owner

lerenn commented Jun 2, 2024

Thanks for the example, I'll try to recreate it and solve it in the next days :)

@lerenn lerenn self-assigned this Jun 2, 2024
@lerenn lerenn added the bug Something isn't working label Jun 2, 2024
@nuttert
Copy link
Author

nuttert commented Jun 12, 2024

Also I see that it is trying to parse the open API schema:

Error: json: cannot unmarshal array into Go struct field Specification.servers of type map[string]*asyncapiv3.Server
Usage:
  asyncapi-codegen [flags]

Flags:
  -c, --convert-keys string   Schema property key names conversion strategy.
                              Supported values: snake, camel, kebab, none. (default "none")
  -f, --disable-formatting    Disables the code generation formatting
  -g, --generate string       Generation options (default "user,application,types")
  -h, --help                  help for asyncapi-codegen
  -i, --input strings         AsyncAPI specification file to use, and its dependencies (default [asyncapi.yaml])
  -o, --output string         Destination file (default "asyncapi.gen.go")
  -p, --package string        Golang package name (default "asyncapi")

Error: json: cannot unmarshal array into Go struct field Specification.servers of type map[string]*asyncapiv3.Server
services/login/api/service.go:5: running "asyncapi-codegen": exit status 1

However, I expect it to only parse the components/headers/parameters and not the entire file.

After I removed servers field it failed with unknown error:

Error: open : no such file or directory
Usage:
  asyncapi-codegen [flags]

Flags:
  -c, --convert-keys string   Schema property key names conversion strategy.
                              Supported values: snake, camel, kebab, none. (default "none")
  -f, --disable-formatting    Disables the code generation formatting
  -g, --generate string       Generation options (default "user,application,types")
  -h, --help                  help for asyncapi-codegen
  -i, --input strings         AsyncAPI specification file to use, and its dependencies (default [asyncapi.yaml])
  -o, --output string         Destination file (default "asyncapi.gen.go")
  -p, --package string        Golang package name (default "asyncapi")

Error: open : no such file or directory
services/login/api/service.go:5: running "asyncapi-codegen": exit status 1

Despite the fact that open api generator validate it and correctly works with the schema.

@nuttert
Copy link
Author

nuttert commented Jun 12, 2024

By the way, the initial example above worked after I added x-go-type:

image

@lerenn
Copy link
Owner

lerenn commented Jun 18, 2024

Sorry about the delay, I was a bit busy. Thanks for providing more insight :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants