redoc icon indicating copy to clipboard operation
redoc copied to clipboard

feat: Custom Extension Components

Open jmendiara opened this issue 6 years ago • 7 comments

Custom Element for openapi extensions

Inspired by Extended Markdown Components feature, add the ability to customize how an extension should be rendered. Backwards compatible.

Usage:

openapi: 3.0.0
paths:
  /pet:
    post:
      x-custom:  # or whatever the extension lives
        - foo
        - bar
const options: RedocRawOptions = {
  showExtensions: true,
  extensionsComponents: {
    'x-custom': {
      component: ExtensionCustomComponent,
      propsSelector: (store: AppStore) => store.spec.parser.spec,
      props: { defined: true },
    },
  },
}

type Props = OpenAPISpec & { defined: boolean } & {
  'x-custom': any
};
class ExtensionCustomComponent extends React.PureComponent<Props> {
  render() { 
    // this.props['x-custom'] === ['foo', 'bar']
    // this.props.defined === true
    // this.props also has what propsSelector returns, in this case, all the spec properties
  }
}

jmendiara avatar Mar 19 '19 18:03 jmendiara

Coverage Status

Coverage decreased (-0.1%) to 82.453% when pulling 6f34a3530d77c97a2786199de969f7cc7c391da8 on jmendiara:feat/extensionComponents into 2f65f051e0ede6d786d510cc1ddad2889ab9d367 on Rebilly:master.

coveralls avatar Mar 19 '19 18:03 coveralls

@RomanHotsiy Any chance to get this merged? Do you need something from my side?

jmendiara avatar Jun 11 '19 07:06 jmendiara

Hey @jmendiara. This PR looks really great 👍

I will review it carefully early next week though. Sorry for the delay.

RomanHotsiy avatar Sep 30 '19 09:09 RomanHotsiy

Hey @RomanHotsiy :) did you have some time to review this?

jmendiara avatar Oct 18 '19 16:10 jmendiara

Hey @RomanHotsiy...

any news on this?

adestis-ds avatar Feb 26 '20 20:02 adestis-ds

@RomanHotsiy This PR is published in npm in case you want to try it and helps in merging this PR

npm install @jmendiara/[email protected]

https://www.npmjs.com/package/@jmendiara/redoc/v/2.0.0-rc.23-customComponents.1

jmendiara avatar Mar 09 '20 12:03 jmendiara

@RomanHotsiy Any update?

mik-laj avatar Aug 26 '20 01:08 mik-laj

If this helps on merging, the full changeset is now rebased against main

jmendiara avatar Nov 17 '22 18:11 jmendiara

@RomanHotsiy did you find some time to consider this PR? We've been using it in production for several years now and we'd like to avoid forking redoc if possible. Thank you.

palmerabollo avatar May 02 '23 14:05 palmerabollo

First of all, thank you for building this and sharing it with us! It's a good use case, but we eventually decided that this feature is not something that we're comfortable adopting at this time. I'm therefore closing this pull request, and I'm sorry it hung around without a clear outcome for so long.

lornajane avatar Aug 22 '23 09:08 lornajane