Skip to content

Commit 5fa1212

Browse files
committed
feat: no iframe, use swagger-ui component
Signed-off-by: Sebastien Marinier <seb@smarinier.net>
1 parent fdb27f5 commit 5fa1212

File tree

8 files changed

+1604
-3310
lines changed

8 files changed

+1604
-3310
lines changed

package-lock.json

Lines changed: 1564 additions & 3279 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@nextcloud/dialogs": "^5.2.0",
2525
"@nextcloud/router": "^3.0.0",
2626
"@nextcloud/vue": "^8.10.0",
27-
"@stoplight/elements": "^8.1.0",
27+
"swagger-ui": "^5.17.14",
2828
"vue": "^2.7.16"
2929
},
3030
"browserslist": [

src/App.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
</NcAppNavigation>
1616
<NcAppContent>
1717
<div v-if="currentAppID" style="height: 100%">
18-
<iframe height="100%" width="100%" :src="generateUrl(`/apps/ocs_api_viewer/view/${currentAppID}`)" />
18+
<SwaggerUI :key="currentAppID" :appid="currentAppID" :openapi="generateUrl(`/apps/ocs_api_viewer/apps/${currentAppID}`)" />
1919
</div>
20-
<div v-if="!currentAppID">
20+
<div v-else>
2121
<NcEmptyContent :name="t('ocs_api_viewer', 'Select an app to get started')" />
2222
</div>
2323
</NcAppContent>
@@ -33,6 +33,7 @@ import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
3333
import { generateUrl } from '@nextcloud/router'
3434
import { showError } from '@nextcloud/dialogs'
3535
import axios from '@nextcloud/axios'
36+
import SwaggerUI from './SwaggerUI.vue'
3637
3738
export default {
3839
name: 'App',
@@ -42,6 +43,7 @@ export default {
4243
NcAppNavigationItem,
4344
NcContent,
4445
NcEmptyContent,
46+
SwaggerUI,
4547
},
4648
data() {
4749
return {

src/SwaggerUI.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<div id="swagger-ui" />
3+
</template>
4+
<script>
5+
import JSSwaggerUI from 'swagger-ui'
6+
7+
const DisableAuthorizePlugin = function() {
8+
return {
9+
wrapComponents: {
10+
authorizeBtn: () => () => null,
11+
},
12+
}
13+
}
14+
export default {
15+
name: 'SwaggerUI',
16+
props: {
17+
appid: { type: String, default: '' },
18+
openapi: { type: String, default: '' },
19+
},
20+
mounted() {
21+
JSSwaggerUI({
22+
url: this.openapi,
23+
dom_id: '#swagger-ui',
24+
presets: [
25+
JSSwaggerUI.presets.apis,
26+
],
27+
plugins: [
28+
DisableAuthorizePlugin,
29+
],
30+
layout: 'BaseLayout',
31+
})
32+
},
33+
}
34+
</script>

src/iframe-theme.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { generateFilePath } from '@nextcloud/router'
77

88
import Vue from 'vue'
99
import App from './App.vue'
10+
import 'swagger-ui/dist/swagger-ui.css'
1011

1112
// eslint-disable-next-line
1213
__webpack_public_path__ = generateFilePath(appName, '', 'js/')

templates/iframe.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

webpack.config.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const webpackConfig = require('@nextcloud/webpack-vue-config')
44
const ESLintPlugin = require('eslint-webpack-plugin')
55
const StyleLintPlugin = require('stylelint-webpack-plugin')
6-
const CopyPlugin = require('copy-webpack-plugin')
76
const path = require('path');
87

98
const buildMode = process.env.NODE_ENV
@@ -18,7 +17,6 @@ webpackConfig.stats = {
1817
const appId = 'ocs_api_viewer'
1918
webpackConfig.entry = {
2019
main: { import: path.join(__dirname, 'src', 'main.js'), filename: appId + '-main.js' },
21-
'iframe-theme': { import: path.join(__dirname, 'src', 'iframe-theme.js'), filename: appId + '-iframe-theme.js' },
2220
}
2321

2422
webpackConfig.plugins.push(
@@ -34,13 +32,5 @@ webpackConfig.plugins.push(
3432
failOnError: !isDev,
3533
}),
3634
)
37-
webpackConfig.plugins.push(
38-
new CopyPlugin({
39-
patterns: [
40-
{ from: 'node_modules/@stoplight/elements/web-components.min.js', to: 'stoplight-elements.js' },
41-
{ from: 'node_modules/@stoplight/elements/styles.min.css', to: 'stoplight-elements.css' },
42-
],
43-
}),
44-
)
4535

4636
module.exports = webpackConfig

0 commit comments

Comments
 (0)