Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger UI: Invariant Violation: Minified React error #37; visit http://facebook.github.io/react/docs/error-decoder.html?invariant=37 #5608

Closed
p4535992 opened this issue Sep 15, 2019 · 4 comments

Comments

@p4535992
Copy link

p4535992 commented Sep 15, 2019

Information

  • OS: CentoOS 7
  • Browser: chrome, firefox
  • Version:
  • Method of installation: dist
  • Swagger-UI version: 3.23.5 and 3.23.8
  • Swagger/OpenAPI version: Swagger 2.0

Content & configuration

Swagger-UI configuration options:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Swagger UI</title>
    
	<script src="./jquery-external/requirejs/require.js"></script>	
    <script src="./jquery-dist/jquery.js" type="text/javascript"></script>  
    <link rel="stylesheet" type="text/css" href="./swagger-ui-dist/swagger-ui.css" >
    <link rel="icon" type="image/png" href="./swagger-ui-dist/favicon-32x32.png" sizes="32x32" />
    <link rel="icon" type="image/png" href="./swagger-ui-dist/favicon-16x16.png" sizes="16x16" />
    <style>
      html
      {
        box-sizing: border-box;
        overflow: -moz-scrollbars-vertical;
        overflow-y: scroll;
      }

      *,
      *:before,
      *:after
      {
        box-sizing: inherit;
      }

      body
      {
        margin:0;
        background: #fafafa;
      }
    </style>
    
</head>

<body class="swagger-section">
	<div id="header">
	    <div class="swagger-ui-wrap">
	        <a id="logo" href="http://swagger.io">swagger</a>
	        <form id="api_selector">
	            <div class="input"><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
	            <div class="input"><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
	            <div class="input"><a id="explore" href="#" data-sw-translate>Explore</a></div>
	        </form>
	    </div>
	</div>

	<div id="message-bar" class="swagger-ui-wrap" data-sw-translate>&nbsp;</div>
	<div id="swagger-ui-container" class="swagger-ui-wrap"></div>

    <script src="./swagger-ui-dist/swagger-ui-bundle.js"> </script>
    <script src="./swagger-ui-dist/swagger-ui-standalone-preset.js"> </script>

    <script type="text/javascript">

    	window.onload = function() {
            var url = window.location.search.match(/url=([^&]+)/);
            if (url && url.length > 1) {
                url = decodeURIComponent(url[1]);
            } else {
                url = "/cxf/swagger/swagger.json";
            }

            // Pre load translate...
            if(window.SwaggerTranslator) {
                window.SwaggerTranslator.translate();
            }

            window.swaggerUi = new SwaggerUIBundle({
                url: url,
                dom_id: "swagger-ui-container",
                deepLinking: true,                
                presets: [
                  SwaggerUIBundle.presets.apis,
                  SwaggerUIStandalonePreset
                ],
                plugins: [
                  SwaggerUIBundle.plugins.DownloadUrl
                ],
                layout: "StandaloneLayout",
                supportedSubmitMethods: ["get", "post", "put", "delete", "patch"],
                onComplete: function(swaggerApi, swaggerUi){
                    if(typeof initOAuth == "function") {
                        initOAuth({
                            clientId: "your-client-id",
                            clientSecret: "your-client-secret",
                            realm: "your-realms",
                            appName: "your-app-name",
                            scopeSeparator: ","
                        });
                    }

                    if(window.SwaggerTranslator) {
                        window.SwaggerTranslator.translate();
                    }

                    $("pre code").each(function(i, e) {
                        hljs.highlightBlock(e)
                    });

                    addApiKeyAuthorization();
                },
                onFailure: function(data) {
                    log("Unable to Load SwaggerUI");
                },
                docExpansion: "none",
                apisSorter: "alpha",
                showRequestHeaders: false
                
            });

            function addApiKeyAuthorization(){
                var key = encodeURIComponent($("#input_apiKey")[0].value);
                if(key && key.trim() != "") {
                    var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
                    window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
                    log("added key " + key);
                }
            }

            $("#input_apiKey").change(addApiKeyAuthorization);
            window.swaggerUi.load();

            function log() {
                if ("console" in window) {
                    console.log.apply(console, arguments);
                }
            }
        }
    </script>
</body>
</html>

Screenshots

How can we help?

Hi this ticket is related to the ticket
#3955

I'm trying to use this project:
https://github.com/Code-House/karaf-swagger

on a osgi framework, but i can't load with success a SwaggerUI/SwaggerUIBunlde javascript object .

I obviously have forced the html to use the original reosurces of SwaggerUI under the "dist" folder instead (but the are the same) resources under the "webjars" library for maven.

The error i get on the client console i sthe following:

Invariant Violation: Minified React error #37; visit http://facebook.github.io/react/docs/error-decoder.html?invariant=37

Any idea way i get this error or a workaround for it?

@shockey
Copy link
Contributor

shockey commented Sep 28, 2019

@p4535992, you're mixing a lot of Swagger UI 2.0 and 30 syntax — for example, SwaggerTranslator is not in 3.0, SwaggerClient.ApiKeyAuthorization is not in 3.0, window.swaggerUi.api.clientAuthorizations.add will no longer work, and window.swaggerUi.load() no longer exists.

I'm not sure what's causing the Invariant Violation, but as a first move I'd recommend making a fresh go at your HTML based on ours in dist/index.html.

@josemigallas
Copy link

I am getting the exact error, using the bundle version but using the example:

<div id="swagger-ui-container" class="swagger-ui-wrap"></div>

<script type="text/javascript">
  (function () {
    SwaggerUIBundle({
      url: "https://petstore.swagger.io/v2/swagger.json",
      dom_id: 'swagger-ui-container',
      presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIBundle.SwaggerUIStandalonePreset
      ],
      layout: "StandaloneLayout"
    })
  }());
</script>

Screen Shot 2020-01-13 at 12 42 31

The error page says the full message is:

_registerComponent(...): Target container is not a DOM element.

But I don't know what DOM element is referring to, since the one I use swagger-ui-container does exist.

@josemigallas
Copy link

FWIW I found the solution:

- dom_id: "swagger-ui-container",
+ dom_id: "#swagger-ui-container",

@OnkelTem
Copy link

OnkelTem commented Feb 3, 2022

Thank you @josemigallas. Can't think of a reason which made (CRA?) developers to build their contraptions a way which rendered such a simple mistake so difficult to investigate.

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

No branches or pull requests

4 participants