mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
add swagger doc to mkdocs/website
This commit is contained in:
parent
c211c56f75
commit
7ccec5db8d
2
.github/workflows/pages.yml
vendored
2
.github/workflows/pages.yml
vendored
@ -20,7 +20,7 @@ jobs:
|
|||||||
python-version: 3.x
|
python-version: 3.x
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pip install mike mkdocs-material[imaging] mkdocs-minify-plugin
|
run: pip install mike mkdocs-material[imaging] mkdocs-minify-plugin mkdocs-swagger-ui-tag
|
||||||
|
|
||||||
- name: Publish documentation
|
- name: Publish documentation
|
||||||
run: mike deploy --push --update-aliases ${{ github.ref_name }} latest
|
run: mike deploy --push --update-aliases ${{ github.ref_name }} latest
|
||||||
|
@ -12,6 +12,10 @@ import (
|
|||||||
"github.com/swaggo/swag/gen"
|
"github.com/swaggo/swag/gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var apiRootPath = "/internal/app/api"
|
||||||
|
var apiDocPath = "core/assets/doc"
|
||||||
|
var apiMkDocPath = "/docs/documentation/rest-api"
|
||||||
|
|
||||||
// this replaces the call to: swag init --propertyStrategy pascalcase --parseDependency --parseInternal --generalInfo base.go
|
// this replaces the call to: swag init --propertyStrategy pascalcase --parseDependency --parseInternal --generalInfo base.go
|
||||||
func main() {
|
func main() {
|
||||||
wd, err := os.Getwd() // should be the project root
|
wd, err := os.Getwd() // should be the project root
|
||||||
@ -19,7 +23,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
apiBasePath := filepath.Join(wd, "/internal/app/api")
|
apiBasePath := filepath.Join(wd, apiRootPath)
|
||||||
apis := []string{"v0", "v1"}
|
apis := []string{"v0", "v1"}
|
||||||
|
|
||||||
hasError := false
|
hasError := false
|
||||||
@ -37,6 +41,15 @@ func main() {
|
|||||||
logrus.Errorf("failed to generate API docs for %s: %v", apiVersion, err)
|
logrus.Errorf("failed to generate API docs for %s: %v", apiVersion, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copy the latest version of the API docs for mkdocs
|
||||||
|
if apiVersion == apis[len(apis)-1] {
|
||||||
|
if err = copyDocForMkdocs(wd, apiBasePath, apiVersion); err != nil {
|
||||||
|
logrus.Errorf("failed to copy API docs for mkdocs: %v", err)
|
||||||
|
} else {
|
||||||
|
log.Println("Copied API docs " + apiVersion + " for mkdocs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("Generated swagger docs for API", apiVersion)
|
log.Println("Generated swagger docs for API", apiVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +64,7 @@ func generateApi(basePath, apiPath, version string) error {
|
|||||||
Excludes: "",
|
Excludes: "",
|
||||||
MainAPIFile: "base.go",
|
MainAPIFile: "base.go",
|
||||||
PropNamingStrategy: swag.PascalCase,
|
PropNamingStrategy: swag.PascalCase,
|
||||||
OutputDir: filepath.Join(basePath, "core/assets/doc"),
|
OutputDir: filepath.Join(basePath, apiDocPath),
|
||||||
OutputTypes: []string{"json", "yaml"},
|
OutputTypes: []string{"json", "yaml"},
|
||||||
ParseVendor: false,
|
ParseVendor: false,
|
||||||
ParseDependency: 3,
|
ParseDependency: 3,
|
||||||
@ -68,3 +81,21 @@ func generateApi(basePath, apiPath, version string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copyDocForMkdocs(workingDir, basePath, version string) error {
|
||||||
|
srcPath := filepath.Join(basePath, apiDocPath, fmt.Sprintf("%s_swagger.yaml", version))
|
||||||
|
dstPath := filepath.Join(workingDir, apiMkDocPath, "swagger.yaml")
|
||||||
|
|
||||||
|
// copy the file
|
||||||
|
input, err := os.ReadFile(srcPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error while reading swagger doc: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.WriteFile(dstPath, input, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error while writing swagger doc: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -21,7 +21,7 @@ The configuration portal supports using a database (SQLite, MySQL, MsSQL or Post
|
|||||||
* Support for multiple WireGuard interfaces
|
* Support for multiple WireGuard interfaces
|
||||||
* Peer Expiry Feature
|
* Peer Expiry Feature
|
||||||
* Handle route and DNS settings like wg-quick does
|
* Handle route and DNS settings like wg-quick does
|
||||||
* ~~REST API for management and client deployment~~ (coming soon)
|
* REST API for management and client deployment
|
||||||
|
|
||||||
## Quick-Start
|
## Quick-Start
|
||||||
|
|
||||||
|
1
docs/documentation/rest-api/api-doc.md
Normal file
1
docs/documentation/rest-api/api-doc.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
<swagger-ui src="./swagger.yaml"/>
|
@ -4,7 +4,7 @@ site_description: Manage WireGuard Peers and Interface using a beautiful and sim
|
|||||||
site_url: https://wgportal.org/
|
site_url: https://wgportal.org/
|
||||||
repo_name: h44z/wg-portal
|
repo_name: h44z/wg-portal
|
||||||
repo_url: https://github.com/h44z/wg-portal
|
repo_url: https://github.com/h44z/wg-portal
|
||||||
copyright: Copyright © 2023-2024 WireGuard Portal Project
|
copyright: Copyright © 2023-2025 WireGuard Portal Project
|
||||||
|
|
||||||
extra_css:
|
extra_css:
|
||||||
- stylesheets/extra.css
|
- stylesheets/extra.css
|
||||||
@ -27,6 +27,7 @@ plugins:
|
|||||||
- social
|
- social
|
||||||
- minify:
|
- minify:
|
||||||
minify_html: true
|
minify_html: true
|
||||||
|
- swagger-ui-tag
|
||||||
|
|
||||||
extra:
|
extra:
|
||||||
version:
|
version:
|
||||||
@ -60,3 +61,4 @@ nav:
|
|||||||
- Building: documentation/getting-started/building.md
|
- Building: documentation/getting-started/building.md
|
||||||
- Docker Container: documentation/getting-started/docker.md
|
- Docker Container: documentation/getting-started/docker.md
|
||||||
- Upgrade from V1: documentation/getting-started/upgrade.md
|
- Upgrade from V1: documentation/getting-started/upgrade.md
|
||||||
|
- REST API: documentation/rest-api/api-doc.md
|
||||||
|
Loading…
Reference in New Issue
Block a user