0

I am using Redoc standalone with our API server. After redoc.standalone.js is loaded, redoc tries to fetch schema.yaml from the API server. However, our server needs an Authorization header with token, which Redoc does not include by default. I am looking for a solution to either download and save the schema file locally or add the Authorization header as a default header for all requests sent from the page. Is there another way to read schema.yaml locally by Redoc without making a request to the private API server? Below is the current HTML code I am using with Redoc:

<!DOCTYPE html>
<html>
   <head>
      <title>Example API</title>
      <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">
      <style>
         body {
         margin: 0;
         padding: 0;
         }
      </style>
   </head>
   <body>
      <redoc spec-url='https://api.example.com/schema.yaml'></redoc>
      <script src="redoc.standalone.js"></script>
   </body>
</html>
rzlvmp
  • 7,512
  • 5
  • 16
  • 45

1 Answers1

1

I think this can be done with a different approach. Instead of using the react rendering with Redoc, build the HTML documentation with the redocly build-docs command (see docs: https://redocly.com/docs/cli/commands/build-docs/) from a location where you do have access to the schema, or can download it before generating the docs. Then publish the HTML output.

(disclaimer, I work at Redocly, who make Redoc)

Lorna Mitchell
  • 1,819
  • 13
  • 22
  • Thank you for suggestion, but building of static HTML brings extra costs and problems: what person in team should generate static contents? Or it should be CI pipeline? What is timing of HTML generating? on merge to `develop`? on release? Where implement pipeline? etc... So it will be a really convenient feature if you add a way to customize security settings – rzlvmp Jun 20 '23 at 09:13
  • 1
    Specifically in the CLI docs, you might also find the resolve feature useful https://redocly.com/docs/cli/configuration/#resolve-object if you do go that route. It feels wrong to plug a commercial option in response to a question about an open source tool, but just in case it's helpful in for your situation: Redocly also has a hosted API docs option that can accept/fetch an OpenAPI from a selection of sources, and host it. More information https://redocly.com/reference/ – Lorna Mitchell Jun 21 '23 at 10:22