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

Custom Plugin: Using wrapComponents to modify operation description #5618

Closed
skorper opened this issue Sep 23, 2019 · 2 comments
Closed

Custom Plugin: Using wrapComponents to modify operation description #5618

skorper opened this issue Sep 23, 2019 · 2 comments

Comments

@skorper
Copy link

skorper commented Sep 23, 2019

Q&A

  • Method of installation: dist assets
  • Swagger-UI version: 3.23.11
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

I'm trying to write a custom plugin that will append to the description for a particular endpoint, using wrapComponents.

const ModifyDescriptionPlugin = function() {
     return {
         wrapComponents: {
         operation: (Original, { React }) => (props) => {
             // ???
             return React.createElement(Original, props)
            }
        }
    }
}

I saw this which seems to indicate I can't wrap OperationContainer, so now I'm at a loss. I also cannot find any examples of anyone trying to modify the description of an endpoint in a plugin.

I have tried looking through operation props and I can't seem to find any way to access description.

@shockey
Copy link
Contributor

shockey commented Sep 24, 2019

Hey @skorper!

This is possible, but the operation component interface just happens to be the most convoluted interface in the entire app (😓) so it's not immediately obvious how to do it.

Here's my implementation:

const ModifyDescriptionPlugin = function() {
  return {
    wrapComponents: {
      operation: (Original, { React }) => props => {
        const { operation } = props
        if (
          operation.get("path") === "/pet/findByStatus" &&
          operation.get("method") === "get" &&
          operation.get("op").size // i.e., resolved Operation has been provided
        ) {
          const originalDescription = operation.getIn(["op", "description"])
          return React.createElement(Original, {
            ...props,
            operation: operation.setIn(
              ["op", "description"],
              originalDescription + "\n\n*Hello world!*"
            )
          })
        }
        return React.createElement(Original, props)
      }
    }
  }
}

Hope this helps!

@skorper
Copy link
Author

skorper commented Sep 24, 2019

@shockey Brilliant, thank you so much! Works great!

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

2 participants