Skip to content

Commit

Permalink
版本升级
Browse files Browse the repository at this point in the history
  • Loading branch information
soonio committed Jan 16, 2023
1 parent 02595f2 commit 1e834cb
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 241 deletions.
26 changes: 2 additions & 24 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,13 @@
- 根据[模版配置](./nginx.conf)配置nginx
- 把swagger生成的接口文件命名为项目名+环境名+json。如`project.env.json`
-`project.env.json`放到docs目录下
- 执行`./swag-ui`即可
- 执行`python3 run.py`即可

## 自定义

- 修改main文件
- 重新编译swag-ui命令

```
go build -ldflags "-s -w" -trimpath -o swag-ui .
```

## 开发
- 初始化
```bash
go run . init
```
- 运行
```bash
go run . serve
```

## 说明

- page目录下的文件来自[swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui/releases) v4

## TODO
- page目录下的文件来自[swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui/releases) v4.15.5

- 优化配置
- 优化切换的select框

## Sponsor

Expand Down
5 changes: 0 additions & 5 deletions go.mod

This file was deleted.

12 changes: 0 additions & 12 deletions go.sum

This file was deleted.

133 changes: 67 additions & 66 deletions index-template.html
Original file line number Diff line number Diff line change
@@ -1,90 +1,91 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css"/>
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32"/>
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16"/>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll
}
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll
}

*, *:before, *:after {
box-sizing: inherit
}
*, *:before, *:after {
box-sizing: inherit
}

body {
margin: 0;
background: #fafafa
}
#api-select {
height: 40px;
line-height: 40px;
position: absolute;
top: 10px;
left: 0;
cursor: pointer;
color: white;
background-color: #1b1b1b;
border: 2px solid #62a03f;
border-radius: 4px;
outline:none;
}
body {
margin: 0;
background: #fafafa
}
#api-select {
height: 40px;
line-height: 40px;
position: absolute;
top: 10px;
left: 0;
cursor: pointer;
color: white;
background-color: #1b1b1b;
border: 2px solid #62a03f;
border-radius: 4px;
outline:none;
}
</style>
</head>
</head>

<body>
<div style="background-color: #1f1f1f">
<label for="api-select"></label><select id="api-select"></select>
</div>
<div id="swagger-ui">
</div>
<script src="./swagger-ui-bundle.js"></script>
<script src="./swagger-ui-standalone-preset.js"></script>
<script>
let sites = ['ConfigPlaceholder']
window.onload = function () {
<body>
<div style="background-color: #1f1f1f">
<label for="api-select"></label><select id="api-select"></select>
</div>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="./swagger-initializer.js" charset="UTF-8"> </script>
<script>
let sites = ['ConfigPlaceholder']
window.onload = function () {

let prefix = document.location.origin
sites.map((v) => {
v.url = prefix + "/" + v.url.replace('./', "")
return v
v.url = prefix + "/" + v.url.replace('./', "")
return v
})

let selectUrl = function (url) {
window.ui = SwaggerUIBundle({
url: url,
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
window.ui = SwaggerUIBundle({
url: url,
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
}
selectUrl(sites[0].url)
let items = document.getElementById('api-select');
sites.forEach(site => {
let option = document.createElement('option')
option.innerHTML = site.name
option.value = site.url
items.appendChild(option)
let option = document.createElement('option')
option.innerHTML = site.name
option.value = site.url
items.appendChild(option)
});
items.onchange = function () {
let valOption = this.options[this.selectedIndex].value
history.pushState({title: "", url: window.location.url}, '', "?url=" + encodeURIComponent(valOption))
selectUrl(valOption)
let valOption = this.options[this.selectedIndex].value
history.pushState({title: "", url: window.location.url}, '', "?url=" + encodeURIComponent(valOption))
selectUrl(valOption)
}
}
</script>
</body>
}
</script>
</body>
</html>
90 changes: 0 additions & 90 deletions init.go

This file was deleted.

44 changes: 0 additions & 44 deletions main.go

This file was deleted.

30 changes: 30 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import json

envs = {'test': '测试', 'prev': '预发', 'prod': '生产'}
config = []
files = os.listdir('./docs')

for x in files:
filename = './docs/{name}'.format(name=x)
if not os.path.isfile(filename) or not x.endswith('.json'):
continue
one = {}
for e in envs:
if e in x:
one['env'] = envs.get(e)
break
with open(filename, 'r') as f:
data = json.load(f)
one['title'] = data.get('info').get('title')
one['version'] = data.get('info').get('version')
f.close()

config.append(one)

with open('./index-template.html') as template:
content = template.read().replace("['ConfigPlaceholder']", json.dumps(config, ensure_ascii=False))
template.close()
with open("./page/index.html", 'w+') as index:
index.write(content)
index.close()

0 comments on commit 1e834cb

Please sign in to comment.