swaggeropenapiredoc

redoc not showing authentication section


I have an openapi.yml that I edit with IntelliJ.

When I preview the file using the OpenApi Editor plugin (with redoc), there is an authentication section (literally <div id="section/authentication" ...) that shows the auth options from components/securitySchemes.

When I view the same file using my standalone html page, this section does not appear

<!DOCTYPE html>
<html>
  <head>
    <title>Redoc</title>
    <!-- needed for adaptive design -->
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link
      href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700"
      rel="stylesheet"
    />

    <!--
    Redoc doesn't change outer page styles
    -->
    <style>
      body {
        margin: 0;
        padding: 0;
      }
    </style>
  </head>
  <body>
    <!--
    Redoc element with link to your OpenAPI definition
    -->
    <redoc spec-url="openapi.yml"></redoc>
    <!--
    Link to Redoc JavaScript on CDN for rendering standalone element
    -->
    <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>
  </body>
</html>

MWE openapi.yml

openapi: '3.0.3'
info:
  version: '2.0.0'
  title: My Api
paths:
  /bob:
    get:
      responses:
        '200':
          description: ok
components:
  securitySchemes:
    Basic:
      type: http
      scheme: basic
    OAuth2:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: /oauth2
          refreshUrl: /oauth2
          scopes:
            bob: bob
security:
  - Basic: []
  - OAuth2:
     - bob

What could be causing this? How can I make the section appear?


Solution

  • The security definitions section have been moved to each operations. To use the old behavior (with a security definition under the Authentication section), you must add the following tag where you want the section to appear in the global description field : <SecurityDefinitions />