Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/base/CoaSwagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { CoaRouter } from '../service/CoaRouter'
export interface CoaSwaggerConfig {
swaggerFilter: boolean
swaggerDocExpansion: 'full' | 'list' | 'none'
swaggerLibrarySite: string
}

const DEFAULT_LIBRARY_SITE = 'https://cdn.jsdelivr.net/npm/[email protected]'

export class CoaSwagger {
private data = {
openapi: '3.0.0',
Expand Down Expand Up @@ -39,7 +42,8 @@ export class CoaSwagger {

constructor(router: CoaRouter<any>, config: CoaSwaggerConfig) {
this.router = router
this.config = Object.assign({ swaggerFilter: false, swaggerDocExpansion: 'list' }, config)
this.config = Object.assign({ swaggerFilter: false, swaggerDocExpansion: 'list', swaggerLibrarySite: DEFAULT_LIBRARY_SITE }, config)
this.config.swaggerLibrarySite = this.config.swaggerLibrarySite.replace(/\/+$/, '')
}

getData(matchGroup: string, serverUrl: string, codeUrl: string, version: string) {
Expand Down Expand Up @@ -203,9 +207,9 @@ const getHtml = (urls: object[], config: CoaSwaggerConfig) => `
<head>
<meta charset="UTF-8">
<title>接口文档</title>
<link rel="icon" type="image/png" href="https://cdn.jsdelivr.net/npm/[email protected]/favicon-32x32.png" sizes="32x32"/>
<link rel="icon" type="image/png" href="https://cdn.jsdelivr.net/npm/[email protected]/favicon-16x16.png" sizes="16x16"/>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui.css">
<link rel="icon" type="image/png" href="${config.swaggerLibrarySite}/favicon-32x32.png" sizes="32x32"/>
<link rel="icon" type="image/png" href="${config.swaggerLibrarySite}/favicon-16x16.png" sizes="16x16"/>
<link rel="stylesheet" type="text/css" href="${config.swaggerLibrarySite}/swagger-ui.css">
<style>
html {
box-sizing: border-box;
Expand Down Expand Up @@ -290,9 +294,14 @@ const getHtml = (urls: object[], config: CoaSwaggerConfig) => `
padding: 0 20px 0 10px;
margin-bottom: 0;
}

/* 标题框轮廓 */
.swagger-ui .opblock-summary-control {
outline: none !important;
}

/* 接口标题上下间距 */
.opblock-tag-section > div {
.swagger-ui .opblock-tag-section > div {
margin-top: 15px !important;
}

Expand Down Expand Up @@ -350,8 +359,8 @@ const getHtml = (urls: object[], config: CoaSwaggerConfig) => `
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-standalone-preset.js"></script>
<script src="${config.swaggerLibrarySite}/swagger-ui-bundle.js"></script>
<script src="${config.swaggerLibrarySite}/swagger-ui-standalone-preset.js"></script>
<script>
window.onload = function () {

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
},
"dependencies": {
"coa-echo": "^1.1.1",
"coa-env": "^1.1.1",
"coa-env": "^1.2.0",
"coa-error": "^1.5.2",
"coa-helper": "^1.2.1",
"coa-secure": "^1.1.2"
"coa-secure": "^1.2.0"
},
"devDependencies": {
"@types/node": "^15.6.1",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"eslint": "^7.27.0",
"@types/node": "^16.3.3",
"@typescript-eslint/eslint-plugin": "^4.28.3",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard-with-typescript": "^20.0.0",
"eslint-plugin-import": "^2.23.3",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"prettier": "^2.3.0",
"prettier": "^2.3.2",
"tsc-watch": "^4.4.0",
"typescript": "^4.3.2"
"typescript": "^4.3.5"
}
}
Loading