|
|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
param (
|
|
|
|
|
[Parameter(Mandatory=$true)][string] $OpenAPI
|
|
|
|
|
[string] $OpenAPI = "*rediops"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$startCd = Get-Location
|
|
|
|
|
@ -14,19 +14,20 @@ Write-Host "Project home dir: $prjDir"
|
|
|
|
|
Set-Location $prjDir
|
|
|
|
|
|
|
|
|
|
# Fetch oapigen if it does not exist
|
|
|
|
|
$binFolder = Join-Path -Path $prjDir -Child "build"
|
|
|
|
|
$oapigenItem = Join-Path -Path $binFolder -Child "oapigen.exe"
|
|
|
|
|
if ( (Test-Path $oapigenItem -PathType Leaf) -eq $false) {
|
|
|
|
|
$binTmpFolder = "tmp"
|
|
|
|
|
$oapigenItem = Join-Path -Path $binTmpFolder -Child "oapigen.exe"
|
|
|
|
|
if ( (Test-Path $oapigenItem -PathType Leaf) -eq $false) {
|
|
|
|
|
# TODO: Download artefact
|
|
|
|
|
}
|
|
|
|
|
$oapigenItem = "oapi-codegen"
|
|
|
|
|
$version = cmd.exe /c $oapigenItem -version
|
|
|
|
|
if ($lastexitcode -ne 0 -or $version -eq "") {
|
|
|
|
|
|
|
|
|
|
if ( (Test-Path $oapigenItem -PathType Leaf) -eq $false) {
|
|
|
|
|
throw "oapigen.exe not found nor downloaded"
|
|
|
|
|
Write-Host "Fetching oapi-codegen software" -ForegroundColor Cyan
|
|
|
|
|
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest
|
|
|
|
|
$version = cmd.exe /c $oapigenItem -version
|
|
|
|
|
if ($lastexitcode -ne 0 -or $version -eq "") {
|
|
|
|
|
Set-Location $startCd
|
|
|
|
|
Throw "$oapigenItem not found nor downloaded"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Write-Host "Using software '$version'" -ForegroundColor Cyan
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$genFolder = Join-Path -Path $prjDir -ChildPath "internal/controller/http/api/gen"
|
|
|
|
|
@ -35,13 +36,66 @@ if ( (Test-Path $genFolder -PathType Container) -eq $false) {
|
|
|
|
|
New-Item -Path $genFolder -Name "gen" -ItemType Directory -Force
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$configFile = Join-Path -Path $prjDir -ChildPath ".\build\types.cfg.yaml"
|
|
|
|
|
& $oapigenItem --config $configFile $OpenAPI
|
|
|
|
|
Write-Host "API type code generated"
|
|
|
|
|
|
|
|
|
|
$configFile = Join-Path -Path $prjDir -ChildPath ".\build\server.cfg.yaml"
|
|
|
|
|
& $oapigenItem --config $configFile $OpenAPI
|
|
|
|
|
Write-Host "API server code generated"
|
|
|
|
|
# Fetch first OpenAPI from definition
|
|
|
|
|
if ($OpenAPI -eq "*rediops") {
|
|
|
|
|
$list = qaskx-cli rediops get --section API --silent
|
|
|
|
|
|
|
|
|
|
$processed = $false
|
|
|
|
|
foreach ($api in $list) {
|
|
|
|
|
$parts = $api -split "`t"
|
|
|
|
|
|
|
|
|
|
if ($parts[3] -ne "" -and $parts[1] -eq "OpenAPI") {
|
|
|
|
|
Write-Host "Generate from OpenAPI definition '$($parts[3])'" -ForegroundColor Yellow
|
|
|
|
|
$OpenAPI = $parts[3]
|
|
|
|
|
$configFile = Join-Path -Path $prjDir -ChildPath ".\build\types.cfg.yaml"
|
|
|
|
|
& $oapigenItem --config $configFile $OpenAPI
|
|
|
|
|
if ($lastexitcode -ne 0) {
|
|
|
|
|
Write-Host "`nAPI Types generation error" -ForegroundColor Red
|
|
|
|
|
Set-Location $startCd
|
|
|
|
|
Throw "API Types generation error detected"
|
|
|
|
|
}
|
|
|
|
|
Write-Host "API type code generated"
|
|
|
|
|
|
|
|
|
|
$configFile = Join-Path -Path $prjDir -ChildPath ".\build\server.cfg.yaml"
|
|
|
|
|
& $oapigenItem --config $configFile $OpenAPI
|
|
|
|
|
if ($lastexitcode -ne 0) {
|
|
|
|
|
Write-Host "`nAPI Server generation error" -ForegroundColor Red
|
|
|
|
|
Set-Location $startCd
|
|
|
|
|
Throw "API Server generation error detected"
|
|
|
|
|
}
|
|
|
|
|
Write-Host "API server code generated"
|
|
|
|
|
|
|
|
|
|
$processed = $true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($processed -eq $false) {
|
|
|
|
|
Write-Host "`nNo OpenAPI definitions detected in rediOps" -ForegroundColor Red
|
|
|
|
|
Set-Location $startCd
|
|
|
|
|
Throw "No OpenAPI definitions detected in rediOps"
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
$configFile = Join-Path -Path $prjDir -ChildPath ".\build\types.cfg.yaml"
|
|
|
|
|
& $oapigenItem --config $configFile $OpenAPI
|
|
|
|
|
if ($lastexitcode -ne 0) {
|
|
|
|
|
Write-Host "`nAPI Types generation error" -ForegroundColor Red
|
|
|
|
|
Set-Location $startCd
|
|
|
|
|
Throw "API Types generation error detected"
|
|
|
|
|
}
|
|
|
|
|
Write-Host "API type code generated"
|
|
|
|
|
|
|
|
|
|
$configFile = Join-Path -Path $prjDir -ChildPath ".\build\server.cfg.yaml"
|
|
|
|
|
& $oapigenItem --config $configFile $OpenAPI
|
|
|
|
|
if ($lastexitcode -ne 0) {
|
|
|
|
|
Write-Host "`nAPI Server generation error" -ForegroundColor Red
|
|
|
|
|
Set-Location $startCd
|
|
|
|
|
Throw "API Server generation error detected"
|
|
|
|
|
}
|
|
|
|
|
Write-Host "API server code generated"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set-Location $startCd
|
|
|
|
|
Write-Host "Generation complete. Please check logs." -ForegroundColor Yellow
|
|
|
|
|
|