mirror of https://github.com/usememos/memos
chore: rename router package
parent
8ae4bc95dc
commit
20dd3e17f7
@ -1,13 +0,0 @@
|
||||
# This file is used by gen-api-v1-docs.ps1 and gen-api-v1-docs.sh
|
||||
|
||||
# You should list additional dirs here if the API grows
|
||||
SWAG_API_DIRS=./server/route/api/v1
|
||||
|
||||
# Where general API info is documented
|
||||
SWAG_GENERAL_INFO=./server/route/api/v1/v1.go
|
||||
|
||||
# Possible output files: go (docs.go), json (swagger.json), yaml (swagger.yaml)
|
||||
SWAG_OUTPUT_TYPES=go,yaml
|
||||
|
||||
# Where generated files are outputted
|
||||
SWAG_OUTPUT=./server/route/api/v1
|
@ -1,108 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script generates API documentation using swaggo/swag
|
||||
|
||||
# For more details, check the docs:
|
||||
# * https://usememos.com/docs/contribution/development
|
||||
# * https://github.com/usememos/memos/blob/main/docs/api/documentation.md
|
||||
|
||||
# Requirements:
|
||||
# * go
|
||||
|
||||
# swag is configured via gen-api-v1-docs.cfg file.
|
||||
|
||||
# Usage:
|
||||
# chmod +x ./scripts/gen-api-v1-docs.sh
|
||||
# ./scripts/gen-api-v1-docs.sh
|
||||
|
||||
find_repo_root() {
|
||||
# Usage: find_repo_root <file_at_root> <dir1> <dir2> ...
|
||||
local looking_for="${1:-".gitignore"}"
|
||||
shift
|
||||
local default_dirs=("." "../")
|
||||
local dirs=("${@:-${default_dirs[@]}}")
|
||||
for dir in "${dirs[@]}"; do
|
||||
if [ -f "$dir/$looking_for" ]; then
|
||||
echo $(realpath "$dir")
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
find_binary() {
|
||||
# Usage: find_binary <binary> <dir1> <dir2> ...
|
||||
local looking_for="$1"
|
||||
shift
|
||||
local default_dirs=(".")
|
||||
|
||||
local binary=$(command -v $looking_for)
|
||||
if [ ! -z "$binary" ]; then
|
||||
echo "$binary"
|
||||
return
|
||||
fi
|
||||
|
||||
local dirs=("${@:-${default_dirs[@]}}")
|
||||
for dir in "${dirs[@]}"; do
|
||||
if [ -f "$dir/$looking_for" ]; then
|
||||
echo $(realpath "$dir")/$looking_for
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
repo_root=$(find_repo_root)
|
||||
if [ -z "$repo_root" ]; then
|
||||
echo -e "\033[0;31mRepository root not found! Exiting.\033[0m"
|
||||
exit 1
|
||||
else
|
||||
echo -e "Repository root: \033[0;34m$repo_root\033[0m"
|
||||
fi
|
||||
cd $repo_root
|
||||
|
||||
echo "Parsing gen-api-v1-docs.cfg..."
|
||||
source "$repo_root/scripts/gen-api-v1-docs.cfg"
|
||||
|
||||
echo -e "API directories: \033[0;34m$SWAG_API_DIRS\033[0m"
|
||||
echo -e "Output directory: \033[0;34m$SWAG_OUTPUT\033[0m"
|
||||
echo -e "General info: \033[0;34m$SWAG_GENERAL_INFO\033[0m"
|
||||
|
||||
if [ -z "$SWAG_API_DIRS" ]; then
|
||||
echo -e "\033[0;31mAPI directories not set! Exiting.\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
swag=$(find_binary swag "$HOME/go/bin" "$GOPATH/bin")
|
||||
if [ -z "$swag" ]; then
|
||||
echo "Swag is not installed. Installing..."
|
||||
go install github.com/swaggo/swag/cmd/swag@latest
|
||||
swag=$(find_binary swag "$HOME/go/bin" "$GOPATH/bin")
|
||||
fi
|
||||
|
||||
if [ -z "$swag" ]; then
|
||||
echo -e "\033[0;31mSwag binary not found! Exiting.\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "Swag binary: \033[0;34m$swag\033[0m"
|
||||
|
||||
general_info_path=$(dirname "$SWAG_GENERAL_INFO")
|
||||
if [ ! -d "$general_info_path" ]; then
|
||||
echo -e "\033[0;31mGeneral info directory does not exist!\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "\e[35mFormatting comments via \`swag fmt --dir "$general_info_path,$SWAG_API_DIRS"\`...\e[0m"
|
||||
$swag fmt --dir "$general_info_path,$SWAG_API_DIRS"
|
||||
|
||||
# This is just in case "swag fmt" do something non-conforming to "go fmt"
|
||||
go_fmt_dirs=$(echo $general_info_path $SWAG_API_DIRS | tr "," " ")
|
||||
echo -e "\e[35mFormatting code via \`go fmt $go_fmt_dirs\`...\e[0m"
|
||||
go fmt $go_fmt_dirs
|
||||
|
||||
echo -e "\e[35mGenerating Swagger API documentation...\e[0m"
|
||||
$swag init --output "$SWAG_OUTPUT" --outputTypes "$SWAG_OUTPUT_TYPES" --generalInfo "$SWAG_GENERAL_INFO" --dir "./,$SWAG_API_DIRS"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "\033[0;31mFailed to generate Swagger API documentation!\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "\033[0;32mSwagger API documentation updated!\033[0m"
|
@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Memos</title>
|
||||
</head>
|
||||
<body>
|
||||
No embeddable frontend found.
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue