swagger-editor icon indicating copy to clipboard operation
swagger-editor copied to clipboard

EditorPreviewAsyncAPI not rendered for AsyncAPI 3.x.x

Open Rzepin opened this issue 10 months ago • 4 comments

Q&A (please complete the following information)

  • OS: Ubuntu
  • Browser: Chrome
  • Version: 132
  • Method of installation: unpkg
  • Swagger-Editor version: 5.0.0-alpha.99
  • Swagger/OpenAPI version: AsyncAPI 3.0.0

Content & configuration

Example Swagger/OpenAPI definition:

asyncapi: 3.0.0
...

e.g. https://raw.githubusercontent.com/asyncapi/spec/refs/heads/master/examples/streetlights-kafka-asyncapi.yml

Swagger-Editor configuration options:

  SwaggerUIBundle({
    url: 'https://raw.githubusercontent.com/asyncapi/spec/refs/heads/master/examples/streetlights-kafka-asyncapi.yml',
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset,
    ],
    dom_id: '#swagger-ui',
    plugins: [
      SwaggerEditor.plugins.EditorContentType,
      SwaggerEditor.plugins.EditorPreviewAsyncAPI,
      SwaggerEditor.plugins.EditorPreviewApiDesignSystems,
      SwaggerEditor.plugins.SwaggerUIAdapter,
      SwaggerUIBundle.plugins.DownloadUrl,
    ],
    layout: 'StandaloneLayout',
  });

Describe the bug you're encountering

BaseLayout is rendering EditorPreviewAsyncAPI using selector: selectIsContentTypeAsyncAPI2 altough component would be able to render AsyncAPI 3.x.x as well.

To reproduce...

  1. Try to render any AsyncAPI 3.x.x using StandaloneLayout.
  2. See error: 'Unable to render this definition'.

Expected behavior

Properly rendered definition with EditorPreviewAsyncAPI plugin.

Screenshots

Image

Additional context or thoughts

Btw. current error details are a little bit misleading:

Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.x.y (for example, openapi: 3.1.0).

Maybe it should be addressed to be changed/improved. In my opinion it would be better to be less specific, but not suggest that only swagger/openapi is supported.

Rzepin avatar Feb 09 '25 18:02 Rzepin

:tada: This issue has been resolved in version 5.0.0-alpha.101 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

swagger-bot avatar Mar 19 '25 13:03 swagger-bot

Can somebody confirm this is indeed solved in 5.0.0-alpha.101? Because I am hitting the same issue, i.e.

Unable to render this definition
The provided definition does not specify a valid version field.

Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.x.y (for example, openapi: 3.1.0).

@char0n

sergiuiacob1 avatar Mar 31 '25 19:03 sergiuiacob1

@Rzepin can you confirm that this issue is still ongoing with release 5.0.0-alpha.101?

sergiuiacob1 avatar Apr 04 '25 08:04 sergiuiacob1

@Rzepin can you confirm that this issue is still ongoing with release 5.0.0-alpha.101?

No, I can't.

Issue faced by me was fixed in 5.0.0-alpha.101

Here's full working example:

<!DOCTYPE html>
<html >
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta name="description" content="SwaggerUIMultifold" />
    <link rel="stylesheet" href="//unpkg.com/[email protected]/dist/swagger-editor.css" />
</head>
<body style="margin:0; padding:0;">
<section id="swagger-ui"></section>

<script src="//unpkg.com/[email protected]/swagger-ui-bundle.js"></script>
<script src="//unpkg.com/[email protected]/swagger-ui-standalone-preset.js"></script>
<script>
    ui = SwaggerUIBundle({});
    // expose SwaggerUI React globally for SwaggerEditor to use
    window.React = ui.React;
</script>
<script src="//unpkg.com/[email protected]/dist/umd/swagger-editor.js"></script>
<script>
    SwaggerUIBundle({
      url: 'https://raw.githubusercontent.com/asyncapi/spec/refs/heads/master/examples/streetlights-kafka-asyncapi.yml',
      dom_id: '#swagger-ui',
      presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIStandalonePreset,
      ],
      plugins: [
        SwaggerEditor.plugins.EditorContentType,
        SwaggerEditor.plugins.EditorPreviewAsyncAPI,
        SwaggerEditor.plugins.EditorPreviewApiDesignSystems,
        SwaggerEditor.plugins.SwaggerUIAdapter,
        SwaggerUIBundle.plugins.DownloadUrl,
      ],
      layout: 'StandaloneLayout',
    });
</script>
</body>
</html>

You can verify that above won't work after downgrading to 5.0.0-alpha.100

Rzepin avatar Apr 11 '25 16:04 Rzepin