Adding API templates

Better generator script
main
Tom Peltonen 2025-06-26 22:02:47 +10:00
parent f54173e46d
commit b002754c06
4 changed files with 135 additions and 20 deletions

View File

@ -0,0 +1,52 @@
# Sequence diagram
This represents the sequence diagram for
service names {{ range .ServiceNames}}**{{.}}** {{ end }}
```mermaid
sequenceDiagram
participant consumer as Consumer
participant gateway as Gateway
participant microservice as ServiceName
participant feature as Svc Feature
participant authz as Authorisation
participant log as Logger
{{ range .Apis}}participant {{ .Name }} as Svc{{ .Name }}
{{ end }}
consumer->>+gateway: {{.ServicePoints}}
activate consumer
note right of gateway: Authentication check at GW
gateway->>+microservice: {{.ServicePoints}}
microservice->>+authz: Validate requestor
note right of authz: Authorise to function
authz-->>-microservice: 200 or 401/403 status
microservice->>+feature: Check feature switch
feature-->>-microservice: 200 or 401/403 status
microservice-)log: log request/response
{{ range .Apis}}
microservice-->>+{{ .Name }}: link {{ .Url }}
note right of {{ .Name }}: Explanation of what happens
{{ .Name }}-->>-microservice: 200 OK response
{{ end }}
alt 200 OK
microservice-->>gateway: 200 OK response
gateway-->>consumer: 200 OK response
else not OK, error
microservice-->>-gateway: !200 ERR response
gateway-->>-consumer: !200 ERR response
end
deactivate consumer
```
***Note***: Adjust the default sequence diagram above
Copyright {{.QaskxDot.ServiceOwner}}
Contact {{.QaskxDot.ServiceOwnerEmail}}

View File

@ -0,0 +1,20 @@
{
"name": "errm01",
"guide": "{{.SelfFolder}}/errm01.md",
"description": "Default error model",
"templates": [
{
"engine": "",
"folder": "{{.SelfFolder}}/definitions/{{.TemplateName}}",
"file_name": "error-model.tmpl",
"output_folder": "^/docsxxx",
"output_name": "seqdgm01.md",
"section": "",
"model": {
"activity": {
"category": "OTHER"
}
}
}
]
}

View File

@ -91,13 +91,16 @@
{
"platform": "",
"script": "",
"deploy": {
"activity": {
"id": "CHANGE.ME",
"category": "DEPLOY",
"name": "rpm",
"url": ""
},
"guide": "",
"playbook": ""
"name": "CHANGE.ME",
"pre": "",
"post": ""
}
],
"devops_version": "0.0.1",

View File

@ -1,10 +1,11 @@
param (
[string] $OpenAPI = "*rediops"
[string] $OpenAPI = "*rediops",
[bool] $NoCache
)
$startCd = Get-Location
$prjDir = qaskx-cli tools dir
$prjDir = qaskx-cli tools dir ^/
if ($prjDir -eq "") {
Throw "No home project directory found"
@ -45,29 +46,65 @@ if ($OpenAPI -eq "*rediops") {
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"
if ($NoCache -ne $true -and $parts[3] -ne "") {
if ($parts[3].StartsWith("https://") -or $parts[3].StartsWith("http://")) {
# Note that file extension may not / unlikely be included
$fileName = $parts[0]
if ($fileName -eq "") {
# Falback name, though this may fail with invalid name
$partsRemote = $parts[3] -split "/"
$fileName = $partsRemote[$partsRemote.Count-1]
}
if ($fileName -ne "") {
$outPathFile = Join-Path -Path $prjDir -ChildPath ("build/cache/" + $fileName)
$null = Invoke-WebRequest -Uri $parts[3] -OutFile $outPathFile
}
}
}
if ($parts[3] -ne "" -and $parts[1] -eq "OpenAPI") {
$apiName = $parts[0]
if ($apiName -eq "") {
$apiName = "OPENAPI"
}
Write-Host "Generate $apiName from OpenAPI definition '$($parts[3])'" -ForegroundColor Yellow
if ($parts[3].StartsWith("https://") -or $parts[3].StartsWith("http://")) {
$OpenAPI = $parts[3]
} else {
$OpenAPI = qaskx-cli tools dir $parts[3]
}
# Check for matching config file
$configFile = Join-Path -Path $prjDir -ChildPath ("build/"+ $parts[0] + "_types.cfg.yaml")
if ( (Test-Path $configFile -PathType Leaf) -eq $false) {
$configFile = Join-Path -Path $prjDir -ChildPath "build/types.cfg.yaml"
}
$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
Write-Host "`n$apiName API Types generation error" -ForegroundColor Red
Set-Location $startCd
Throw "API Server generation error detected"
Throw "$apiName API Types generation error detected"
}
Write-Host "API server code generated"
Write-Host "$apiName API type code generated from $configFile"
# Check for matching config file
$configFile = Join-Path -Path $prjDir -ChildPath ("build/"+ $parts[0] + "_server.cfg.yaml")
if ( (Test-Path $configFile -PathType Leaf) -eq $false) {
$configFile = Join-Path -Path $prjDir -ChildPath "build/server.cfg.yaml"
}
& $oapigenItem --config $configFile $OpenAPI
if ($lastexitcode -ne 0) {
Write-Host "`n$apiName API Server generation error" -ForegroundColor Red
Set-Location $startCd
Throw "$apiName API Server generation error detected"
}
Write-Host "$apiName API server code generated from $configFile"
$processed = $true
break
#break
}
}
@ -97,5 +134,8 @@ if ($OpenAPI -eq "*rediops") {
Write-Host "API server code generated"
}
Set-Location $prjDir
go mod tidy
Set-Location $startCd
Write-Host "Generation complete. Please check logs." -ForegroundColor Yellow