removed swagger-ui webjar

This commit is contained in:
Jake Potrebic 2020-09-25 20:35:54 -07:00 committed by MiniDigger
parent 3c0127f3eb
commit adb725ddb8
7 changed files with 878 additions and 115 deletions

View File

@ -203,11 +203,6 @@
<artifactId>chart.js</artifactId> <artifactId>chart.js</artifactId>
<version>${chart.js.version}</version> <version>${chart.js.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>${swagger-ui.version}</version>
</dependency>
<!-- runtime --> <!-- runtime -->
<dependency> <dependency>

View File

@ -24,6 +24,7 @@
"lodash": "4.17.20", "lodash": "4.17.20",
"popper.js": "^1.16.1", "popper.js": "^1.16.1",
"query-string": "6.13.1", "query-string": "6.13.1",
"swagger-ui": "^3.34.0",
"vue": "^3.0.0", "vue": "^3.0.0",
"webpack-jquery-ui": "^2.0.1" "webpack-jquery-ui": "^2.0.1"
}, },

View File

@ -0,0 +1,87 @@
<template>
<div id="swagger-ui"></div>
</template>
<script>
import { getApiSession } from '@/js/apiRequests';
import SwaggerUIBundle from 'swagger-ui';
export default {
name: 'SwaggerUI',
mounted() {
// console.log(SwaggerUIBundle);
window.onload = () => {
window.ui = SwaggerUIBundle({
url: '/v2/api-docs',
dom_id: '#swagger-ui',
deepLinking: true,
presets: [SwaggerUIBundle.presets.apis, SwaggerUIBundle.SwaggerUIStandalonePreset],
plugins: [SwaggerUIBundle.plugins.DownloadUrl],
layout: 'BaseLayout',
requestInterceptor: req => {
if (!req.loadSpec) {
const promise = getApiSession().then(session => {
req.headers.authorization = 'HangarApi session=' + session;
return req;
});
// Workaround for fixing the curl URL
// https://github.com/swagger-api/swagger-ui/issues/4778#issuecomment-456403631
promise.url = req.url;
return promise;
} else {
return req;
}
}
});
};
}
};
</script>
<style lang="scss">
@import '~swagger-ui/dist/swagger-ui.css';
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
margin: 0;
background: #fafafa;
}
.swagger-ui .topbar .download-url-wrapper,
.swagger-ui .info hgroup.main a {
display: none;
}
.swagger-ui .info {
margin: 2rem 0;
}
.swagger-ui .info .title small pre {
background-color: unset;
border: unset;
}
.model-container,
.responses-inner {
overflow-x: auto;
}
.swagger-ui .info .description h2 {
padding-top: 1.5rem;
margin: 1.5rem 0 0;
border-top: 3px solid #333333;
}
.swagger-ui .scheme-container {
border-top: 1px solid rgba(0, 0, 0, 0.15);
}
</style>

View File

@ -0,0 +1,4 @@
import { createApp } from 'vue';
import Swagger from '@/components/Swagger';
createApp(Swagger).mount('#swagger-ui-vue');

View File

@ -42,7 +42,7 @@ export function apiV2Request(url, method = 'GET', data = {}) {
}); });
} }
function getApiSession() { export function getApiSession() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
let session; let session;
const date = new Date(); const date = new Date();

File diff suppressed because it is too large Load Diff

View File

@ -6,94 +6,14 @@ Mostly copied from swagger-ui's index file
<#import "*/utils/hangar.ftlh" as hangar /> <#import "*/utils/hangar.ftlh" as hangar />
<#import "*/layout/base.ftlh" as base /> <#import "*/layout/base.ftlh" as base />
<#macro scripts> <#assign scriptsVar>
<script type="text/javascript" src="<@hangar.url "lib/jquery/dist/jquery.min.js" />"></script> <script type="text/javascript" src="<@hangar.url "js/swagger.js" />"></script>
<script src="<@hangar.url "lib/swagger-ui/swagger-ui-bundle.js" />"></script> </#assign>
<script src="<@hangar.url "lib/swagger-ui/swagger-ui-standalone-preset.js" />"></script> <#assign styleVar>
<script src="<@hangar.url "js/apiRequests.js" />"></script> <link rel="stylesheet" type="text/css" href="<@hangar.url "css/swagger.css" />">
<script <#--@CSPNonce.attr-->> </#assign>
window.onload = () => {
window.ui = SwaggerUIBundle({
url: "/v2/api-docs",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "BaseLayout",
requestInterceptor: (req) => {
if (!req.loadSpec) {
const promise = getApiSession().then((session) => {
req.headers.authorization = 'HangarApi session=' + session;
return req;
});
// Workaround for fixing the curl URL
// https://github.com/swagger-api/swagger-ui/issues/4778#issuecomment-456403631
promise.url = req.url;
return promise;
} else {
return req;
}
}
})
}
</script>
<#if request??>
<script <#--@CSPNonce.attr-->>
csrf = '@play.filters.csrf.CSRF.getToken.get.value';
isLoggedIn = ${request.hasUser};
</script>
</#if>
</#macro>
<#macro stylesheets>
<link rel="stylesheet" type="text/css" href="<@hangar.url "lib/swagger-ui/swagger-ui.css" />">
<style>
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
margin:0;
background: #fafafa;
}
.swagger-ui .topbar .download-url-wrapper, .swagger-ui .info hgroup.main a {
display: none;
}
.swagger-ui .info {
margin: 2rem 0;
}
.swagger-ui .info .title small pre {
background-color: unset;
border: unset;
}
.model-container, .responses-inner {
overflow-x: auto;
}
.swagger-ui .info .description h2 {
padding-top: 1.5rem;
margin: 1.5rem 0 0;
border-top: 3px solid #333333;
}
.swagger-ui .scheme-container {
border-top: 1px solid rgba(0,0,0,.15);
}
</style>
</#macro>
<#assign message><@spring.message "general.openapi" /></#assign> <#assign message><@spring.message "general.openapi" /></#assign>
<#assign scriptsVar><@scripts /></#assign> <@base.base title="${message}" additionalScripts=scriptsVar additionalStyling=styleVar>
<#assign stylesheetsVar><@stylesheets /></#assign> <div id="swagger-ui-vue"></div>
<@base.base title="${message}" additionalScripts=scriptsVar additionalStyling=stylesheetsVar>
<div id="swagger-ui"></div>
</@base.base> </@base.base>