Swagger UI ignores query-param "url=" and opens PetStore instead

Viewed 91

After updating Swagger UI from 3.x to 4.x, loading my custom schema via a parameter in the application-url breaks.

Before https://example.com/swagger/index.html?url=https://example.com/docs/simrws.yaml would load my custom specs. Now that just loads the default example Swagger Petstore.

There are no errors on the console. The docs say, that the fourth method to configure Swagger UI is to use URL-params.

1 Answers

A breaking security-feature was added in V4.1.3:

root@server:/opt/swagger-ui-git# git diff v4.1.2 v4.1.3 src/core/index.js
diff --git a/src/core/index.js b/src/core/index.js
index 677e3786..621b095f 100644
--- a/src/core/index.js
+++ b/src/core/index.js
@@ -77,6 +77,7 @@ export default function SwaggerUI(opts) {

+    queryConfigEnabled: false,

@@ -108,7 +109,7 @@ export default function SwaggerUI(opts) {


-  let queryConfig = parseSearch()
+  let queryConfig = opts.queryConfigEnabled ? parseSearch() : {}

You will find that mentioned in the docs linked above.

Edit the file dist/swagger-initializer.js to add the following line under url:...petstore... to revert to the old behavior:

queryConfigEnabled: true,

As this was a security fix, there might be a better way than to just to revert to the old behavior.

Related