Skip to content

How to initiate Rapidoc from JS? #908

Open

Description

@darkWolf-PR

Is there a way to init Rapidoc completely from JS?

I have this in ajax-loaded content:

<div>
<script type="module" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rapidoc-min.min.js"></script>
<rapi-doc id="thedoc" data-json = "{$openApiJson}" ... some config options ...> </rapi-doc>
</div>

$openApiJson variable inserts the OpenApi json into this data-element.

In JS which runs on load after ajax is this:

    const docEl = document.getElementById('thedoc');
    if (docEl) {
            let strSpec = docEl.dataset.json;
            let objSpec = JSON.parse(strSpec);
            docEl.loadSpec(objSpec);
    }

That works, it loads the spec etc., but only, if I enter the page by browser url, without ajax.

If I´m going through app menu and content is being loaded by ajax, I have to enter that page twice to get Rapidoc rendered. Checking the browser network analysis, at first entry, rapidoc-min.js is loaded, but nothing gets rendered, I have to click menu again to load the page for second time to get the Rapidoc rendered.

It seems I need to somehow call "render Rapidoc" on the element manually from my JS, but I can´t find how?

Thx for any tips.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions