redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

better error handling when $ref references an external file in asyncapi

Open marianobntz opened this issue 1 year ago • 8 comments

Is your feature request related to a problem? Please describe.

I am building my pipelines to publish APIs and when I tried to bundle the asyncapi files I found the error below

Describe the solution you'd like

Support for bundling asyncapi files is the expected solution.

Describe alternatives you've considered

not much since bunding is the whole idea...

Additional context

The error shown now is:

Something went wrong when processing .\cache-messages-1.0.json:

  • Cannot read properties of undefined (reading 'schemas')

marianobntz avatar May 02 '24 17:05 marianobntz

Update This comment is wrong, $schema and $ref are different things... Anyway... when I use a $ref keyword referencing an external file I get the error... I tried different combinations:

  • "$ref": "components/schemas/type.json"
  • "$ref": "components/schemas/type.json#"

type.json is:

{ "type": "string", "description": "dummy", "pattern": "^[a-z0-9\-]+$", "example": "supplier" }

  • tried changing the type.json to (this is a sample, maybe I got a syntax error in this sample):

{ "components": { "schemas": { "record": { "type": "string", "description": "dummy", "pattern": "^[a-z0-9\-]+$", "example": "supplier" }}}}

and tested

  • "$ref": "components/schemas/type.json#/components/schemas/record"

But no luck..

Original comment After some debuging I discovered that in asyncapi schema references use the $schema keyword instead of $ref that is used in openapi. It would be nice to have a lint check and better information when discovering this problem.

Thanks

marianobntz avatar May 02 '24 18:05 marianobntz

Hi @marianobntz, this looks like a bug. Where did you put the $ref?

tatomyr avatar May 03 '24 09:05 tatomyr

Tried to put the $ref in a message payload directly in a channel, inside a reusable component under components/messages with no luck.

marianobntz avatar May 06 '24 13:05 marianobntz

weird thing is that the lint command supports the external ref, it is just the bundle command who breaks...

marianobntz avatar May 06 '24 14:05 marianobntz

I'm sorry, only the lint command supports AsyncAPI (v2.6) at the moment. Bundle doesn't have AsyncAPI support yet (for any version)

lornajane avatar May 07 '24 08:05 lornajane

ok.. can I change the issue title to "support bundle for asyncapi documents?" 😄

bundle actually works if you do not use the external $ref

marianobntz avatar May 09 '24 00:05 marianobntz

bundle actually works if you do not use the external $ref

It also works for external $refs from some specific places (like channel servers and message examples). So at first I thought the bundle command was implemented 🙈. But yes, it needs to be implemented separately.

tatomyr avatar May 10 '24 09:05 tatomyr

@marianobntz Hi, please provide a full example of asyncapi description. I'll try to reproduce it and fix.

AlexVarchuk avatar Jul 22 '24 12:07 AlexVarchuk