Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
62f7d18
fix: reenable cdn service after generator fix
bahkauv70 Feb 27, 2025
68fd38e
fix: set import paths to fixed values as they are coming from a stati…
bahkauv70 Feb 27, 2025
c861213
fix: use unique variable name
bahkauv70 Feb 27, 2025
052b7c5
chore: Add convenience target to download alpha apis
bahkauv70 Feb 27, 2025
7f9976b
fix: Workaround for a bug in the openapi generator that returns an un…
bahkauv70 Feb 27, 2025
f273cd6
fix: correctly handle bitsizes and nullability of numeric attributes
bahkauv70 Feb 18, 2025
0418d6f
fix: add exceptions for float32 and int32 to keep bug-compatibility w…
bahkauv70 Feb 19, 2025
8e21d0b
fix: introduced specialized types
bahkauv70 Mar 4, 2025
59ebd0d
fix: generation working without compile issues, but broken tests
bahkauv70 Mar 4, 2025
4131da3
fix: beta apis compiling now
bahkauv70 Mar 4, 2025
1e46435
fix: use getter-id instead of plain name to generate non-conflicting …
bahkauv70 Mar 4, 2025
1855307
fix: Readd json tags
bahkauv70 Mar 5, 2025
da2b53f
chore: remove debug code
bahkauv70 Mar 5, 2025
936bf0e
fix: correct testcase generation
bahkauv70 Mar 5, 2025
7c4ba79
fix: fix return type instantiation in testcase
bahkauv70 Mar 7, 2025
57ec14f
fix: correct instantiation of returntype in testcase
bahkauv70 Mar 13, 2025
47c601c
feat: provide service-individual, explicit api versions via json file
bahkauv70 Mar 13, 2025
f283af0
fix: switch back to main for service-enablement api
bahkauv70 Mar 13, 2025
8e3e13f
fix: handle non-existing version gracefully by falling back to main
bahkauv70 Mar 13, 2025
430dc9b
feat: rename file to api-versions-lock.json to emphasize semantics
bahkauv70 Mar 14, 2025
f9ba02c
Merge branch 'main' into fix/generator-issues
bahkauv70 Mar 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ROOT_DIR ?= $(shell git rev-parse --show-toplevel)
SCRIPTS_BASE ?= $(ROOT_DIR)/scripts
API_VERSION ?= $(shell cat api_version|grep -v '^\#'|head -n 1)
API_VERSIONS ?= $(ROOT_DIR)/api-versions-lock.json
SDK_BRANCH ?= main

# SETUP AND TOOL INITIALIZATION TASKS
Expand All @@ -12,7 +12,7 @@ project-tools:

# GENERATE
download-oas:
@$(SCRIPTS_BASE)/download-oas.sh "$(OAS_REPO_NAME)" "$(OAS_REPO)" "$(ALLOW_ALPHA)" "$(API_VERSION)"
@$(SCRIPTS_BASE)/download-oas.sh "$(OAS_REPO_NAME)" "$(OAS_REPO)" "$(ALLOW_ALPHA)" "$(API_VERSIONS)"

generate-sdk:
@$(SCRIPTS_BASE)/generate-sdk/generate-sdk.sh "$(GIT_HOST)" "$(GIT_USER_ID)" "$(GIT_REPO_ID)" "$(SDK_REPO_URL)" "$(LANGUAGE)" "$(SDK_BRANCH)"
Expand Down
4 changes: 4 additions & 0 deletions api-versions-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"load-balancer": "9c9de238a3e650f4bed9b9d9ade151da9a97e1d6",
"certificates": "c592757243833f9b506a7d23ec5a80a9b3c984ae"
}
3 changes: 0 additions & 3 deletions api_version

This file was deleted.

3 changes: 1 addition & 2 deletions blacklist.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# Transitional file to disable generation for selected services
cdn
# Transitional file to disable generation for selected services
25 changes: 16 additions & 9 deletions scripts/download-oas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ROOT_DIR=$(git rev-parse --show-toplevel)
OAS_REPO_NAME=$1
OAS_REPO=$2
ALLOW_ALPHA=$3
OAS_API_VERSION=$4
OAS_API_VERSIONS=$4

if [[ -z ${OAS_REPO_NAME} ]]; then
echo "Repo name is empty, default public OAS repo name will be used."
Expand All @@ -18,9 +18,9 @@ if [[ ! ${OAS_REPO} || -d ${OAS_REPO} ]]; then
OAS_REPO="https://github.com/stackitcloud/${OAS_REPO_NAME}.git"
fi

if [[ -z ${OAS_API_VERSION} ]]; then
echo "No API version passed, main branch will be used"
OAS_API_VERSION="main"
if [[ -z ${OAS_API_VERSIONS} ]]; then
echo "No API version passed, using ${ROOTDIR}/api-versions-lock.json"
OAS_API_VERSIONS="${ROOT_DIR}/api-versions-lock.json"
fi

# Create temp directory to clone OAS repo
Expand All @@ -41,16 +41,23 @@ mkdir ${ROOT_DIR}/oas
cd ${work_dir}
git clone ${OAS_REPO} --quiet

echo "Using api version ${OAS_API_VERSION}"
cd ${OAS_REPO_NAME}
git checkout --quiet ${OAS_API_VERSION}
cd -

for service_dir in ${work_dir}/${OAS_REPO_NAME}/services/*; do

max_version_dir=""
max_version=-1
service=$(basename "$service_dir")

apiVersion=$(jq -r -f <(cat <<EOF
if has("${service}") then ."${service}" else "main" end
EOF
) ${OAS_API_VERSIONS})
if [ "${apiVersion}" != "main" ]; then
echo "Using ${apiVersion} for ${service}"
fi
cd ${work_dir}/${OAS_REPO_NAME} > /dev/null
git checkout -q $apiVersion || (echo "version ${apiVersion} does not exist, using main instead" && git checkout -q main)
cd - > /dev/null

# Prioritize GA over Beta over Alpha versions
# GA priority = 3, Beta priority = 2, Alpha priority = 1
max_version_priority=1
Expand Down
4 changes: 2 additions & 2 deletions templates/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"io"
"net/http"
"net/url"
"{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/core/config"
"{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
{{#imports}} "{{import}}"
{{/imports}}
)
Expand Down
25 changes: 18 additions & 7 deletions templates/go/api_test.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ import (
"net/url"
"strings"
"testing"
"{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/config"
)

func Test_{{packageName}}_{{classname}}Service(t *testing.T) {

{{#operations}}
{{#operation}}
t.Run("Test {{classname}}Service {{{nickname}}}", func(t *testing.T) {
path := "{{{path}}}"{{#pathParams}}
{{paramName}}Value := {{#isString}}"{{paramName}}"{{/isString}}{{#isNumber}}123{{/isNumber}}{{#isFloat}}float32(123){{/isFloat}}{{#isDouble}}float64(123){{/isDouble}}{{#isInteger}}int32(123){{/isInteger}}{{#isLong}}int64(123){{/isLong}}{{^isString}}{{^isInteger}}{{defaultValue}}{{/isInteger}}{{/isString}}
path = strings.Replace(path, "{"+"{{baseName}}"+"}", url.PathEscape(ParameterValueToString({{paramName}}Value, "{{paramName}}")), -1){{/pathParams}}
_apiUrlPath := "{{{path}}}"{{#pathParams}}
{{paramName}}Value := {{#isAnyType}}"unspecified type"{{/isAnyType}}{{#isString}}{{#isUuid}}uuid.NewString(){{/isUuid}}{{^isUuid}}"{{paramName}}"{{/isUuid}}{{/isString}}{{#isNumber}}123{{/isNumber}}{{#isFloat}}float32(123){{/isFloat}}{{#isDouble}}float64(123){{/isDouble}}{{#isInteger}}int32(123){{/isInteger}}{{#isLong}}int64(123){{/isLong}}{{^isString}}{{^isInteger}}{{defaultValue}}{{/isInteger}}{{/isString}}
_apiUrlPath = strings.Replace(_apiUrlPath, "{"+"{{baseName}}"+"}", url.PathEscape(ParameterValueToString({{paramName}}Value, "{{paramName}}")), -1){{/pathParams}}

test{{classname}}ServeMux := http.NewServeMux()
test{{classname}}ServeMux.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) {
test{{classname}}ServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) {
{{! Only binary data sets a ReturnFormat}}
{{#returnFormat}}
w.Header().Add("Content-Type", "application/octet-stream")
Expand All @@ -41,7 +41,18 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) {
{{/returnFormat}}
{{^returnFormat}}
{{#returnType}}
{{#returnProperty.isPrimitiveType}}
{{! according to the model, freeform objects might be primitive...}}
{{#returnProperty.isFreeFormObject}}
data := {{{.}}}{}
{{/returnProperty.isFreeFormObject}}
{{^returnProperty.isFreeFormObject}}
var data {{{.}}}
{{/returnProperty.isFreeFormObject}}
{{/returnProperty.isPrimitiveType}}
{{^returnProperty.isPrimitiveType}}
data := {{{.}}}{}
{{/returnProperty.isPrimitiveType}}
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(data)
{{/returnType}}
Expand Down Expand Up @@ -79,7 +90,7 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) {
{{#allParams}}
{{#required}}
{{#isPathParam}}
{{paramName}} := {{#isString}}"{{paramName}}"{{/isString}}{{#isNumber}}123{{/isNumber}}{{#isFloat}}float32(123){{/isFloat}}{{#isDouble}}float64(123){{/isDouble}}{{#isInteger}}int32(123){{/isInteger}}{{#isLong}}int64(123){{/isLong}}{{^isString}}{{^isInteger}}{{defaultValue}}{{/isInteger}}{{/isString}}
{{paramName}} := {{paramName}}Value
{{/isPathParam}}
{{^isPathParam}}
{{#isPrimitiveType}}
Expand All @@ -98,7 +109,7 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) {
t.Fatalf("error in call: %v", reqErr)
}
{{#returnType}}
if resp == nil {
if IsNil(resp) {
t.Fatalf("response not present")
}
{{/returnType}}
Expand Down
4 changes: 2 additions & 2 deletions templates/go/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"strings"
"time"
"unicode/utf8"
"{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/core/config"
"{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/core/auth"
"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/auth"

{{#hasOAuthMethods}}
"golang.org/x/oauth2"
Expand Down
2 changes: 1 addition & 1 deletion templates/go/configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package {{packageName}}

import (
"{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/config"
)

// NewConfiguration returns a new Configuration object
Expand Down
2 changes: 1 addition & 1 deletion templates/go/go.mod.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module {{gitHost}}/{{gitUserId}}/{{gitRepoId}}/services{{#isGoSubmodule}}/{{pack
go 1.21

require (
{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/core v0.16.0
github.com/stackitcloud/stackit-sdk-go/core v0.16.0
)
Loading
Loading