Search code examples
asp.net-mvcswaggerdocumentation

How to add option in <redoc>?


I want to add some additional option to my ReDoc. For current implementation I am using json file that is generated from Swagger, and this is added in html page. Example how this is done:

  <body>
    <redoc spec-url='http://petstore.swagger.io/v2/swagger.json'></redoc>
    <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
  </body>

I use this as referent documentation: https://github.com/Rebilly/ReDoc

How can I add option object in tag and not use ReDoc object? And how can I use vendor extension e.g. x-logo? In documentation this is set via json file, but my json file is auto generate from Swagger.


Solution

  • You just place the options after the spec-url in the redoc tag like this:

    <body>
        <redoc spec-url='http://petstore.swagger.io/v2/swagger.json' YOUR_OPTIONS_HERE></redoc>
        <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
    </body>
    

    in this example on ReDoc repository you can verify it (line 22 at this moment):

    https://github.com/Rebilly/ReDoc/blob/master/config/docker/index.tpl.html#L22

    Important:

    Remember to "kebab-casing the ReDoc options", as an example if your options are:

    hideDownloadButton noAutoAuth disableSearch

    YOUR_OPTIONS_HERE

    should be (after kebab-casing them):

    hide-download-button no-auto-auth disable-search

    Your body with those options becomes like this:

    <body>
        <redoc spec-url='http://petstore.swagger.io/v2/swagger.json' hide-download-button no-auto-auth disable-search></redoc>
        <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
    </body>
    

    Hope it will be usefull to you.