Files
ServerStatistics/script/goctl/GenApi.ps1
2025-10-04 12:48:09 +08:00

35 lines
878 B
PowerShell

# script should be execute in current `script` directory.
# Usage: ./genApi.ps1 [-s]
# -s : also run swagger generation and convert to OpenAPI3
param(
[switch]$s
)
# Save the original location
$originalLocation = Get-Location
# Change to the target directory
Set-Location -Path (Resolve-Path "../../api")
# format api files
goctl api format -dir .
# generate go-zero code
goctl api go -api ServerStatistics.api -dir ../src --style=gozero
# generate swagger and convert to openapi3 only when -s is provided
if ($s) {
# generate swagger
goctl api swagger --api ServerStatistics.api --dir .
# swagger to openapi3
npx swagger2openapi -o ServerStatistics.yaml -p ServerStatistics.json
} else {
Write-Host "Skipping swagger and openapi conversion (pass -s to execute)."
}
# Restore original location (optional but good practice)
Set-Location -Path $originalLocation