Adding default content

Fine tuning existing content
main
Tom Peltonen 2025-06-18 21:29:56 +10:00
parent 8a0528977c
commit f54173e46d
5 changed files with 86 additions and 19 deletions

View File

@ -20,7 +20,7 @@
{
"engine": "",
"folder": "{{.SelfFolder}}/definitions/{{.TemplateName}}/build",
"file_name": "*",
"file_name": "",
"output_folder": "^/build",
"output_name": ""
}

View File

@ -0,0 +1,4 @@
# Build Directory
The build directory contains documentation and
scripts for building/testing/deploying the asset.

View File

@ -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
}
# 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

View File

@ -0,0 +1,5 @@
package: gen
generate:
echo-server: true
embedded-spec: true
output: internal/controller/http/api/gen/general-server.gen.go

View File

@ -0,0 +1,4 @@
package: gen
generate:
models: true
output: internal/controller/http/api/gen/general-type.gen.go