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

SwaggerEditor@next: passing the configuration to AsyncAPI plugin #5006

Closed
char0n opened this issue May 6, 2024 · 2 comments
Closed

SwaggerEditor@next: passing the configuration to AsyncAPI plugin #5006

char0n opened this issue May 6, 2024 · 2 comments

Comments

@char0n
Copy link
Member

char0n commented May 6, 2024

We need a way to pass the configuration to AsyncAPI plugin via Swagger UI constructor. Is there a way already?

Refs #4493

@char0n
Copy link
Member Author

char0n commented May 6, 2024

This PR (#5007) opened possibility to pass additional configuration to AsyncAPI React Component.

To actually pass a configuration to AsyncAPI React Component, EditorPreviewAsyncAPIReactComponent needs to be wrapped and within the wrapper the custom config can be provided. Here is an example.

const AsyncAPICustomConfigPlugin = () => ({
  wrapComponents: {
    EditorPreviewAsyncAPIReactComponent: (Original) => ({ schema, config: defaultConfig }) => {
      // defaultConfig = { show: { errors: true } }
      const customConfig = { ...defaultConfig, sidebar: true };

      return <Original schema={schema} config={customConfig} />;
    }
  }
})

const root = createRoot(document.getElementById('swagger-editor'));
root.render(
  <SwaggerEditor 
    url="https://raw.githubusercontent.com/asyncapi/spec/v2.6.0/examples/streetlights-kafka.yml"
    plugins=[AsyncAPICustomConfigPlugin] 
  />
);

@char0n char0n closed this as completed May 6, 2024
swagger-bot pushed a commit that referenced this issue May 6, 2024
# [5.0.0-alpha.95](v5.0.0-alpha.94...v5.0.0-alpha.95) (2024-05-06)

### Features

* **editor-preview-asyncapi:** allow passing additional config ([#5007](#5007)) ([e2c96df](e2c96df)), closes [#5006](#5006)
@char0n
Copy link
Member Author

char0n commented May 6, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant