Open nuttert opened 1 month ago
Hello @nuttert ! Thanks for the issue !
Normally, it should have enable by this issue: https://github.com/lerenn/asyncapi-codegen/issues/192 Do you have an error when you're trying to import a schema from an openapi schema? :)
Okay I see it, thanks, but yes I could not generate a code with ref: I created UserMeta message with payload:
I expected it will create a structure UserMeta and Payload will have the UserMeta type.
But it generated these:
(I pointed to the dependencies in the input -i ../schemas/channels_api.yaml,../../common/schemas/common.yaml)
Thanks for the example, I'll try to recreate it and solve it in the next days :)
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.
By the way, the initial example above worked after I added x-go-type:
Sorry about the delay, I was a bit busy. Thanks for providing more insight :)
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:
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:
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.