Skip to content

Commit 1221c22

Browse files
authored
Add swagger site config (#10)
* Upgrade dependencies * Add swagger site config
1 parent 9830a5c commit 1221c22

File tree

3 files changed

+440
-429
lines changed

3 files changed

+440
-429
lines changed

lib/base/CoaSwagger.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import { CoaRouter } from '../service/CoaRouter'
44
export interface CoaSwaggerConfig {
55
swaggerFilter: boolean
66
swaggerDocExpansion: 'full' | 'list' | 'none'
7+
swaggerLibrarySite: string
78
}
89

10+
const DEFAULT_LIBRARY_SITE = 'https://cdn.jsdelivr.net/npm/[email protected]'
11+
912
export class CoaSwagger {
1013
private data = {
1114
openapi: '3.0.0',
@@ -39,7 +42,8 @@ export class CoaSwagger {
3942

4043
constructor(router: CoaRouter<any>, config: CoaSwaggerConfig) {
4144
this.router = router
42-
this.config = Object.assign({ swaggerFilter: false, swaggerDocExpansion: 'list' }, config)
45+
this.config = Object.assign({ swaggerFilter: false, swaggerDocExpansion: 'list', swaggerLibrarySite: DEFAULT_LIBRARY_SITE }, config)
46+
this.config.swaggerLibrarySite = this.config.swaggerLibrarySite.replace(/\/+$/, '')
4347
}
4448

4549
getData(matchGroup: string, serverUrl: string, codeUrl: string, version: string) {
@@ -203,9 +207,9 @@ const getHtml = (urls: object[], config: CoaSwaggerConfig) => `
203207
<head>
204208
<meta charset="UTF-8">
205209
<title>接口文档</title>
206-
<link rel="icon" type="image/png" href="https://cdn.jsdelivr.net/npm/[email protected]/favicon-32x32.png" sizes="32x32"/>
207-
<link rel="icon" type="image/png" href="https://cdn.jsdelivr.net/npm/[email protected]/favicon-16x16.png" sizes="16x16"/>
208-
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui.css">
210+
<link rel="icon" type="image/png" href="${config.swaggerLibrarySite}/favicon-32x32.png" sizes="32x32"/>
211+
<link rel="icon" type="image/png" href="${config.swaggerLibrarySite}/favicon-16x16.png" sizes="16x16"/>
212+
<link rel="stylesheet" type="text/css" href="${config.swaggerLibrarySite}/swagger-ui.css">
209213
<style>
210214
html {
211215
box-sizing: border-box;
@@ -290,9 +294,14 @@ const getHtml = (urls: object[], config: CoaSwaggerConfig) => `
290294
padding: 0 20px 0 10px;
291295
margin-bottom: 0;
292296
}
297+
298+
/* 标题框轮廓 */
299+
.swagger-ui .opblock-summary-control {
300+
outline: none !important;
301+
}
293302
294303
/* 接口标题上下间距 */
295-
.opblock-tag-section > div {
304+
.swagger-ui .opblock-tag-section > div {
296305
margin-top: 15px !important;
297306
}
298307
@@ -350,8 +359,8 @@ const getHtml = (urls: object[], config: CoaSwaggerConfig) => `
350359
</head>
351360
<body>
352361
<div id="swagger-ui"></div>
353-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-bundle.js"></script>
354-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-standalone-preset.js"></script>
362+
<script src="${config.swaggerLibrarySite}/swagger-ui-bundle.js"></script>
363+
<script src="${config.swaggerLibrarySite}/swagger-ui-standalone-preset.js"></script>
355364
<script>
356365
window.onload = function () {
357366

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@
2626
},
2727
"dependencies": {
2828
"coa-echo": "^1.1.1",
29-
"coa-env": "^1.1.1",
29+
"coa-env": "^1.2.0",
3030
"coa-error": "^1.5.2",
3131
"coa-helper": "^1.2.1",
32-
"coa-secure": "^1.1.2"
32+
"coa-secure": "^1.2.0"
3333
},
3434
"devDependencies": {
35-
"@types/node": "^15.6.1",
36-
"@typescript-eslint/eslint-plugin": "^4.25.0",
37-
"eslint": "^7.27.0",
35+
"@types/node": "^16.3.3",
36+
"@typescript-eslint/eslint-plugin": "^4.28.3",
37+
"eslint": "^7.31.0",
3838
"eslint-config-prettier": "^8.3.0",
3939
"eslint-config-standard-with-typescript": "^20.0.0",
40-
"eslint-plugin-import": "^2.23.3",
40+
"eslint-plugin-import": "^2.23.4",
4141
"eslint-plugin-node": "^11.1.0",
4242
"eslint-plugin-promise": "^5.1.0",
43-
"prettier": "^2.3.0",
43+
"prettier": "^2.3.2",
4444
"tsc-watch": "^4.4.0",
45-
"typescript": "^4.3.2"
45+
"typescript": "^4.3.5"
4646
}
4747
}

0 commit comments

Comments
 (0)