Hangar/frontend/pages/api.vue

96 lines
2.8 KiB
Vue
Raw Normal View History

2021-01-22 03:47:58 +08:00
<template>
2021-01-31 03:55:24 +08:00
<v-card color="grey lighten-2">
<div id="swagger-ui"></div>
</v-card>
2021-01-22 03:47:58 +08:00
</template>
<script lang="ts">
2021-03-21 10:06:09 +08:00
import { Component } from 'nuxt-property-decorator';
2021-01-31 03:55:24 +08:00
import SwaggerUIBundle from 'swagger-ui';
2021-01-31 10:00:11 +08:00
import { SwaggerConfigs, SwaggerUIBundle as SwaggerUIBundleType } from 'swagger-ui-dist';
2021-03-21 10:06:09 +08:00
import { HangarComponent } from '~/components/mixins';
2021-01-31 10:00:11 +08:00
declare global {
interface Window {
ui: SwaggerUIBundleType;
}
}
2021-01-31 02:50:12 +08:00
2021-01-22 03:47:58 +08:00
@Component
2021-03-21 10:06:09 +08:00
export default class ApiPage extends HangarComponent {
2021-04-06 16:41:02 +08:00
head() {
return {
title: this.$t('apiDocs.title'),
};
}
2021-01-31 03:55:24 +08:00
mounted() {
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) {
// TODO update this once api auth is in
// const promise = this.$api.getSession().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
// @ts-ignore
// promise.url = req.url;
// return promise;
// just fix url for now
if (req.url.startsWith('http://localhost:8080')) {
req.url = req.url.replace('http://localhost:8080', 'http://localhost:3000');
}
return req;
} else {
return req;
}
},
} as SwaggerConfigs) as SwaggerUIBundleType;
2021-01-31 03:55:24 +08:00
}
}
2021-01-22 03:47:58 +08:00
</script>
2021-01-31 03:55:24 +08:00
<style lang="scss">
2021-02-11 19:48:52 +08:00
//noinspection CssUnknownTarget - IJ you are dum
2021-01-31 03:55:24 +08:00
@import '@/node_modules/swagger-ui/dist/swagger-ui.css';
.swagger-ui {
.topbar .download-url-wrapper,
.info hgroup.main a {
display: none;
}
.wrapper .info {
background-color: unset !important;
border-color: unset !important;
margin: 2rem 0;
.title small pre {
background-color: unset;
border: unset;
}
.description h2 {
padding-top: 1.5rem;
margin: 1.5rem 0 0;
border-top: 3px solid #333333;
}
.scheme-container {
border-top: 1px solid rgba(0, 0, 0, 0.15);
}
.markdown {
min-height: 0;
}
}
2021-01-31 03:55:24 +08:00
}
.model-container,
.responses-inner {
overflow-x: auto;
}
</style>