How to use the redoc.createStore function in redoc

To help you get started, we’ve selected a few redoc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Redocly / redoc / cli / index.ts View on Github external
title,
    disableGoogleFont,
    templateFileName,
    templateOptions,
    redocOptions = {},
  }: Options,
) {
  let html;
  let css;
  let state;
  let redocStandaloneSrc;
  if (ssr) {
    console.log('Prerendering docs');

    const specUrl = redocOptions.specUrl || (isURL(pathToSpec) ? pathToSpec : undefined);
    const store = await createStore(spec, specUrl, redocOptions);
    const sheet = new ServerStyleSheet();
    html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
    css = sheet.getStyleTags();
    state = await store.toJS();

    if (!cdn) {
      redocStandaloneSrc = readFileSync(join(BUNDLES_DIR, 'redoc.standalone.js'));
    }
  }

  templateFileName = templateFileName ? templateFileName : join(__dirname, './template.hbs');
  const template = compile(readFileSync(templateFileName).toString());
  return template({
    redocHTML: `
    <div id="redoc">${(ssr &amp;&amp; html) || ''}</div>
github openpitrix / website / gatsby-node.js View on Github external
const genAllAPI = new Promise((resolve) => {
    const specJson=require('./api.swagger.json');
    createStore(specJson, './api.swagger.json', apiDocOptions).then(store=> {
      const sheet = new ServerStyleSheet();
      const html=renderToString(sheet.collectStyles(React.createElement(Redoc, {store})));
      const css=sheet.getStyleTags();

      store.toJS().then(state=> {
        createPage({
          path: `/api/`,
          component: path.resolve(`./src/templates/api.js`),
          context: {
            html,
            css,
            state
          },
        })

        resolve()

redoc

ReDoc

MIT
Latest version published 4 months ago

Package Health Score

82 / 100
Full package analysis