Skip to content

Commit

Permalink
Allow generation from root and simplify version by making it a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
janpieterz committed Aug 14, 2024
1 parent 295fa95 commit 8de480a
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 40 deletions.
7 changes: 7 additions & 0 deletions openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.7.0"
}
}
5 changes: 2 additions & 3 deletions server/csharp.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
$version = &"$PSScriptRoot\get-version.ps1" -patchVersion "1"
$additionalProperties = @{
packageName = "Trinsic.Connect.BackendClient"
packageVersion = $version
packageVersion = "[VERSION]"
nullableReferenceTypes = "true"
modelPropertySorting = "alphabetical"
library = "httpclient"
useDateTimeOffset = "true"
validatable = "false"
}
& "$PSScriptRoot\generate-client.ps1" -language "csharp" -additionalProperties $additionalProperties
& "$PSScriptRoot/generate-client.ps1" -language "csharp" -patchVersion "1" -additionalProperties $additionalProperties
7 changes: 0 additions & 7 deletions server/generate-all.ps1

This file was deleted.

14 changes: 8 additions & 6 deletions server/generate-client.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
param (
[Parameter(Mandatory = $true)]
[string]$language,
[Parameter(Mandatory = $true)]
[string]$patchVersion,
[string]$swaggerFileOrUrl = "https://connect.trinsic.id/swagger/api/swagger.json",
[string]$outputFolder = "../dist/$language",
[string]$outputFolder = "$PSScriptRoot/../dist/$language",
[Parameter(Mandatory = $true)]
[hashtable]$additionalProperties
)
#Ensure we run this "from this folder" as we run it personally in a command line as well as through the perspective of builds.
Set-Location -Path "$PSScriptRoot"

$localSwaggerFilePath = "";
if ($swaggerFileOrUrl -like "https://*") {
Write-Host "The URL starts with https://, retrieving the file"
Write-Host "Downloading specification from $swaggerFileOrUrl";
$localSwaggerFilePath = "./swagger.json";
$localSwaggerFilePath = "$PSScriptRoot/swagger.json";

$response = Invoke-WebRequest -Uri $swaggerFileOrUrl
$response.Content | Out-File -FilePath $localSwaggerFilePath -Encoding utf8
Expand All @@ -41,9 +41,11 @@ else {
Write-Host "Created output folder";
}

# Concatenate the hashtable into a comma-separated string
$version = &"$PSScriptRoot\get-version.ps1" -patchVersion $patchVersion;

# Concatenate the hashtable into a comma-separated string and replace version variable
$concatenatedAdditionalProperties = (($additionalProperties.GetEnumerator() | ForEach-Object {
"$($_.Key)=$($_.Value)"
"$($_.Key)=$($_.Value -replace "\[VERSION\]", $version)"
}) -join ',');

Write-Host "Generating $language SDK from $localSwaggerFilePath in $outputFolder with additional properties: $concatenatedAdditionalProperties";
Expand Down
6 changes: 3 additions & 3 deletions server/get-version.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ param (
)
# Because there's a lot of small variations in version number usage across generators, generate version first and provide it via additonal properties to the generate-client.ps1 file.
# Other option was a lot of if language specific if statements inside of generate-client.
$jsonContent = Get-Content -Path "version.json" -Raw | ConvertFrom-Json
$apiVersion = $jsonContent.apiVersion
$packageVersion = "$apiVersion.$patchVersion"
$jsonContent = Get-Content -Path "$PSScriptRoot\..\versions.json" -Raw | ConvertFrom-Json
$backendVersion = $jsonContent.backendVersion
$packageVersion = "$backendVersion.$patchVersion"
Write-Host "Package will be created with version $packageVersion from file based API Version $version and patchVersion $patchVersion"

return $packageVersion;
5 changes: 2 additions & 3 deletions server/go.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
$version = &"$PSScriptRoot\get-version.ps1" -patchVersion "1"
$additionalProperties = @{
packageName = "trinsic.id/connect-sdks/go"
packageVersion = $version
packageVersion = "[VERSION]"
}
& "$PSScriptRoot\generate-client.ps1" -language "go" -additionalProperties $additionalProperties
& "$PSScriptRoot\generate-client.ps1" -language "go" -patchVersion "1" -additionalProperties $additionalProperties
5 changes: 2 additions & 3 deletions server/java.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
$version = &"$PSScriptRoot\get-version.ps1" -patchVersion "1"
$additionalProperties = @{
apiPackage = "id.trinsic.connect.backendclient"
artifactVersion = $version
artifactVersion = "[VERSION]"
library = "native"
modelPackage = "id.trinsic.connect.backendclient.models"
artifactId = "connect-backendclient"
Expand All @@ -16,4 +15,4 @@ $additionalProperties = @{
developerOrganizationUrl = "https://trinsic.id"
artifactDescription = "'Trinsic Connect Backend Client'"
}
& "$PSScriptRoot\generate-client.ps1" -language "java" -additionalProperties $additionalProperties
& "$PSScriptRoot/generate-client.ps1" -language "java" -patchVersion "1" -additionalProperties $additionalProperties
5 changes: 2 additions & 3 deletions server/node.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
$version = &"$PSScriptRoot\get-version.ps1" -patchVersion "1"
$additionalProperties = @{
npmName = "@trinsic/connect-backend-client"
npmVersion = $version
npmVersion = "[VERSION]"
supportsES6 = "true"
npmRepository = "https://github.com/trinsic-id"
}
& "$PSScriptRoot\generate-client.ps1" -language "typescript-fetch" -additionalProperties $additionalProperties
& "$PSScriptRoot/generate-client.ps1" -language "typescript-fetch" -patchVersion "1" -additionalProperties $additionalProperties
5 changes: 2 additions & 3 deletions server/php.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
$version = &"$PSScriptRoot\get-version.ps1" -patchVersion "1"
$additionalProperties = @{
artifactVersion = $version
artifactVersion = "[VERSION]"
invokerPackage = "TrinsicConnect\\BackendClient"
artifactUrl = "https://trinsic.id"
developerOrganization = "Trinsic"
developerOrganizationUrl = "https://trinsic.id"
composerPackageName = "trinsic/connect-backend-client"
}
& "$PSScriptRoot\generate-client.ps1" -language "php" -additionalProperties $additionalProperties
& "$PSScriptRoot/generate-client.ps1" -language "php" -patchVersion "1" -additionalProperties $additionalProperties
5 changes: 2 additions & 3 deletions server/python.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
$version = &"$PSScriptRoot\get-version.ps1" -patchVersion "1"
$additionalProperties = @{
packageName = "trinsic_connect_backend_client"
packageVersion = $version
packageVersion = "[VERSION]"
packageUrl = "https://trinsic.id"
projectName = "Trinsic-Connect-Backend-Client"
}
& "$PSScriptRoot\generate-client.ps1" -language "python" -additionalProperties $additionalProperties
& "$PSScriptRoot/generate-client.ps1" -language "python" -patchVersion "1" -additionalProperties $additionalProperties
5 changes: 2 additions & 3 deletions server/ruby.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
$version = &"$PSScriptRoot\get-version.ps1" -patchVersion "1"
$additionalProperties = @{
gemAuthor = "Trinsic"
gemAuthorEmail = "[email protected]"
gemDescription = "'Trinsic Connect Backend Client'"
gemHomepage = "https://trinsic.id"
gemName = "trinsic_connect_backendclient"
gemSummary = "'Trinsic Connect Backend Client'"
gemVersion = $version
gemVersion = "[VERSION]"
moduleName = "TrinsicConnectBackendClient"
}
& "$PSScriptRoot\generate-client.ps1" -language "ruby" -additionalProperties $additionalProperties
& "$PSScriptRoot/generate-client.ps1" -language "ruby" -patchVersion "1" -additionalProperties $additionalProperties
3 changes: 0 additions & 3 deletions server/version.json

This file was deleted.

3 changes: 3 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"backendVersion": "0.1"
}

0 comments on commit 8de480a

Please sign in to comment.