parent
8a0528977c
commit
f54173e46d
|
|
@ -20,7 +20,7 @@
|
||||||
{
|
{
|
||||||
"engine": "",
|
"engine": "",
|
||||||
"folder": "{{.SelfFolder}}/definitions/{{.TemplateName}}/build",
|
"folder": "{{.SelfFolder}}/definitions/{{.TemplateName}}/build",
|
||||||
"file_name": "*",
|
"file_name": "",
|
||||||
"output_folder": "^/build",
|
"output_folder": "^/build",
|
||||||
"output_name": ""
|
"output_name": ""
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Build Directory
|
||||||
|
|
||||||
|
The build directory contains documentation and
|
||||||
|
scripts for building/testing/deploying the asset.
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory=$true)][string] $OpenAPI
|
[string] $OpenAPI = "*rediops"
|
||||||
)
|
)
|
||||||
|
|
||||||
$startCd = Get-Location
|
$startCd = Get-Location
|
||||||
|
|
@ -14,19 +14,20 @@ Write-Host "Project home dir: $prjDir"
|
||||||
Set-Location $prjDir
|
Set-Location $prjDir
|
||||||
|
|
||||||
# Fetch oapigen if it does not exist
|
# Fetch oapigen if it does not exist
|
||||||
$binFolder = Join-Path -Path $prjDir -Child "build"
|
$oapigenItem = "oapi-codegen"
|
||||||
$oapigenItem = Join-Path -Path $binFolder -Child "oapigen.exe"
|
$version = cmd.exe /c $oapigenItem -version
|
||||||
if ( (Test-Path $oapigenItem -PathType Leaf) -eq $false) {
|
if ($lastexitcode -ne 0 -or $version -eq "") {
|
||||||
$binTmpFolder = "tmp"
|
|
||||||
$oapigenItem = Join-Path -Path $binTmpFolder -Child "oapigen.exe"
|
|
||||||
if ( (Test-Path $oapigenItem -PathType Leaf) -eq $false) {
|
|
||||||
# TODO: Download artefact
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( (Test-Path $oapigenItem -PathType Leaf) -eq $false) {
|
Write-Host "Fetching oapi-codegen software" -ForegroundColor Cyan
|
||||||
throw "oapigen.exe not found nor downloaded"
|
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"
|
$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
|
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"
|
# Fetch first OpenAPI from definition
|
||||||
& $oapigenItem --config $configFile $OpenAPI
|
if ($OpenAPI -eq "*rediops") {
|
||||||
Write-Host "API server code generated"
|
$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
|
Set-Location $startCd
|
||||||
Write-Host "Generation complete. Please check logs." -ForegroundColor Yellow
|
Write-Host "Generation complete. Please check logs." -ForegroundColor Yellow
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package: gen
|
||||||
|
generate:
|
||||||
|
echo-server: true
|
||||||
|
embedded-spec: true
|
||||||
|
output: internal/controller/http/api/gen/general-server.gen.go
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package: gen
|
||||||
|
generate:
|
||||||
|
models: true
|
||||||
|
output: internal/controller/http/api/gen/general-type.gen.go
|
||||||
Loading…
Reference in New Issue