Skip to content

RequireJS prevents integrating SwaggerUI with a user script #2471

@JanisErdmanis

Description

@JanisErdmanis

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions