Skip to content

Instantly share code, notes, and snippets.

@ano
Created April 24, 2020 20:47
Show Gist options
  • Save ano/6aa608f2007a3192bc928c14740cfaa6 to your computer and use it in GitHub Desktop.
Save ano/6aa608f2007a3192bc928c14740cfaa6 to your computer and use it in GitHub Desktop.
One Page Swagger / OpenAPI
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>ServiceDesk Service Swagger</title>
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui.css">
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui-standalone-preset.js"></script>
<script src="https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui-bundle.js"></script>
<script>
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
url: "<enter url to swagger.json here>",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
})
window.ui = ui
}
</script>
</body>
</html>
@magarrent
Copy link

Thank you, mate!

In my case, I used specs instead of URL. if anyone has the JSON but not the URL:

const ui = SwaggerUIBundle({
    spec:  JSON.parse(json),
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIStandalonePreset
    ],
    plugins: [
        SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout",
})
window.ui = ui

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