JuliaDocs / Documenter.jl

A documentation generator for Julia.
https://documenter.juliadocs.org
MIT License
803 stars 477 forks source link

RequireJS prevents integrating SwaggerUI with a user script #2471

Open JanisErdmanis opened 5 months ago

JanisErdmanis commented 5 months ago

I am incorporating a Swagger generated docs within a documenter, which looks promising:

Screenshot 2024-03-04 at 13 58 02

However, I have stumbled on a blocking issue where the code above works only if the swagger is loaded before the require.min.js is loaded, but the user assets provided to makedocs in format argument are loaded only afterwards. The code that renders the page is as follows and is included with @raw html:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.11.9/swagger-ui.css">

<style>
  .swagger-ui .information-container {
    display: none !important;
  }

  .swagger-ui #operations-tag-default {
    display: none !important;
  }
</style>

<div id="swagger-ui"></div>
<script>
  window.onload = () => {
      window.ui = SwaggerUIBundle({
          url: window.location.origin + "/assets/swagger/schema.json", 
          dom_id: '#swagger-ui',
      });
  };
</script>

A simple solution I see is that user asset_links in render_head function could be loaded before requirejs_cdn, which would only involve reordering.

Another more sophisticated approach is to make SwaggerUI to be integrated in the same way as higlighting and math rendering is. This involves understanding how requirejs works, documenter internals which is more complex task for which I can’t allocate time.

JanisErdmanis commented 5 months ago

After resolving some hurdles I managed to deploy swagger docs in a documenter generated documentation with a #2472 change. Thus I am eager to see this issue resolved.