From 62f7d18710a958bcf4c90c5916f27302f90386b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Thu, 27 Feb 2025 14:44:30 +0100 Subject: [PATCH 01/20] fix: reenable cdn service after generator fix --- blacklist.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blacklist.txt b/blacklist.txt index 279694c..a3065e5 100644 --- a/blacklist.txt +++ b/blacklist.txt @@ -1,2 +1 @@ -# Transitional file to disable generation for selected services -cdn \ No newline at end of file +# Transitional file to disable generation for selected services \ No newline at end of file From 68fd38e61ebad6151dffd1b9db1d0020b288316f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Thu, 27 Feb 2025 14:45:20 +0100 Subject: [PATCH 02/20] fix: set import paths to fixed values as they are coming from a static, not dynamic, repository --- templates/go/api.mustache | 4 ++-- templates/go/api_test.mustache | 2 +- templates/go/client.mustache | 4 ++-- templates/go/configuration.mustache | 2 +- templates/go/go.mod.mustache | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/go/api.mustache b/templates/go/api.mustache index 4b3f6a4..3ce8436 100644 --- a/templates/go/api.mustache +++ b/templates/go/api.mustache @@ -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}} ) diff --git a/templates/go/api_test.mustache b/templates/go/api_test.mustache index 317d1cb..c677d23 100644 --- a/templates/go/api_test.mustache +++ b/templates/go/api_test.mustache @@ -19,7 +19,7 @@ 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) { diff --git a/templates/go/client.mustache b/templates/go/client.mustache index 4aebded..808a1d4 100644 --- a/templates/go/client.mustache +++ b/templates/go/client.mustache @@ -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" diff --git a/templates/go/configuration.mustache b/templates/go/configuration.mustache index 42adeda..50f1c33 100644 --- a/templates/go/configuration.mustache +++ b/templates/go/configuration.mustache @@ -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 diff --git a/templates/go/go.mod.mustache b/templates/go/go.mod.mustache index 4bbea27..907801a 100644 --- a/templates/go/go.mod.mustache +++ b/templates/go/go.mod.mustache @@ -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 ) From c861213d6251d8984f728f00809aca3552d2554f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Thu, 27 Feb 2025 14:47:34 +0100 Subject: [PATCH 03/20] fix: use unique variable name --- templates/go/api_test.mustache | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/go/api_test.mustache b/templates/go/api_test.mustache index c677d23..edc86b0 100644 --- a/templates/go/api_test.mustache +++ b/templates/go/api_test.mustache @@ -27,12 +27,12 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) { {{#operations}} {{#operation}} t.Run("Test {{classname}}Service {{{nickname}}}", func(t *testing.T) { - path := "{{{path}}}"{{#pathParams}} + _apiUrlPath := "{{{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 = 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") From 052b7c5851832ee9c844e9609eb6f33c77c674e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Thu, 27 Feb 2025 17:46:06 +0100 Subject: [PATCH 04/20] chore: Add convenience target to download alpha apis --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 75ad832..e59cf35 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,9 @@ project-tools: download-oas: @$(SCRIPTS_BASE)/download-oas.sh "$(OAS_REPO_NAME)" "$(OAS_REPO)" "$(ALLOW_ALPHA)" "$(API_VERSION)" +download-oas-alpha: + @$(SCRIPTS_BASE)/download-oas.sh "stackit-api-specifications-internal" "git@ssh.dev.azure.com:v3/schwarzit/schwarzit.stackit-public/stackit-api-specifications-internal" "true" "$(API_VERSION)" + generate-sdk: @$(SCRIPTS_BASE)/generate-sdk/generate-sdk.sh "$(GIT_HOST)" "$(GIT_USER_ID)" "$(GIT_REPO_ID)" "$(SDK_REPO_URL)" "$(LANGUAGE)" "$(SDK_BRANCH)" From 7f9976b64f98bdafd3fdebab75ea3720039ac623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Thu, 27 Feb 2025 17:46:29 +0100 Subject: [PATCH 05/20] fix: Workaround for a bug in the openapi generator that returns an unspecified type for a path parameter --- templates/go/api_test.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/go/api_test.mustache b/templates/go/api_test.mustache index edc86b0..3e4cbba 100644 --- a/templates/go/api_test.mustache +++ b/templates/go/api_test.mustache @@ -28,7 +28,7 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) { {{#operation}} t.Run("Test {{classname}}Service {{{nickname}}}", func(t *testing.T) { _apiUrlPath := "{{{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}} + {{paramName}}Value := {{#isAnyType}}"unspecified type"{{/isAnyType}}{{#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}} _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"{{baseName}}"+"}", url.PathEscape(ParameterValueToString({{paramName}}Value, "{{paramName}}")), -1){{/pathParams}} test{{classname}}ServeMux := http.NewServeMux() @@ -79,7 +79,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}} := {{#isAnyType}}"unspecified type"{{/isAnyType}}{{#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}} {{/isPathParam}} {{^isPathParam}} {{#isPrimitiveType}} From f273cd61054687b23f9cd6511a41738f279d0c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:35:59 +0100 Subject: [PATCH 06/20] fix: correctly handle bitsizes and nullability of numeric attributes --- templates/go/model_simple.mustache | 42 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/templates/go/model_simple.mustache b/templates/go/model_simple.mustache index 566506c..0fad61d 100644 --- a/templates/go/model_simple.mustache +++ b/templates/go/model_simple.mustache @@ -37,7 +37,7 @@ type {{classname}} struct { {{/isWriteOnly}} {{/isReadOnly}} {{/required}} - {{name}} *{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{{dataType}}}{{/isNumeric}} `json:"{{baseName}}{{#required}}{{#isReadOnly}},omitempty{{/isReadOnly}}{{/required}}{{#required}}{{#isWriteOnly}},omitempty{{/isWriteOnly}}{{/required}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` + {{name}} *{{#isNullable}}{{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}{{/isNullable}}{{^isNullable}}{{^isPrimitiveType}}{{dataType}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}{{/isPrimitiveType}}{{/isNullable}} `json:"{{baseName}}{{#required}}{{#isReadOnly}},omitempty{{/isReadOnly}}{{/required}}{{#required}}{{#isWriteOnly}},omitempty{{/isWriteOnly}}{{/required}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` {{#isAdditionalPropertiesTrue}} AdditionalProperties map[string]interface{} {{/isAdditionalPropertiesTrue}} @@ -59,7 +59,7 @@ type _{{{classname}}} {{{classname}}} // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} *{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{{dataType}}}{{/isNumeric}}{{^-last}}, {{/-last}}{{/requiredVars}}) *{{classname}} { +func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{datatype}}{{/isInteger}}{{^-last}}, {{/-last}}{{/requiredVars}}) *{{classname}} { this := {{classname}}{} {{#allVars}} {{#required}} @@ -69,12 +69,11 @@ func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} *{{#isNumber}}float64 {{#defaultValue}} {{^vendorExtensions.x-golang-is-container}} {{^isReadOnly}} + var {{nameInCamelCase}} {{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}} = {{{.}}} {{#isNullable}} - var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}} - this.{{name}} = *New{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{{dataType}}}{{/isNumeric}}(&{{nameInCamelCase}}) + this.{{name}} = *New{{dataType}}(&{{nameInCamelCase}}) {{/isNullable}} {{^isNullable}} - var {{nameInCamelCase}} {{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{{dataType}}}{{/isNumeric}} = {{{.}}} this.{{name}} = &{{nameInCamelCase}} {{/isNullable}} {{/isReadOnly}} @@ -94,13 +93,12 @@ func New{{classname}}WithDefaults() *{{classname}} { {{#defaultValue}} {{^vendorExtensions.x-golang-is-container}} {{^isReadOnly}} -{{#isNullable}} {{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}} - var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}} - this.{{name}} = *New{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{{dataType}}}{{/isNumeric}}(&{{nameInCamelCase}}) + var {{nameInCamelCase}} {{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}} = {{{.}}} +{{#isNullable}} + this.{{name}} = *New{{dataType}}(&{{nameInCamelCase}}) {{/isNullable}} {{^isNullable}} - var {{nameInCamelCase}} {{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{{dataType}}}{{/isNumeric}} = {{{.}}} this.{{name}} = &{{nameInCamelCase}} {{/isNullable}} {{/isReadOnly}} @@ -119,9 +117,9 @@ func New{{classname}}WithDefaults() *{{classname}} { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}() *{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}} { +func (o *{{classname}}) Get{{name}}() *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}} { if o == nil|| IsNil(o.{{name}}) {{#isNullable}}{{^vendorExtensions.x-golang-is-container}} || o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { - var ret *{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}} + var ret *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}} return ret } @@ -146,13 +144,13 @@ func (o *{{classname}}) Get{{name}}() *{{#isNumber}}float64{{/isNumber}}{{#isFlo {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}Ok() (*{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}}, bool) { +func (o *{{classname}}) Get{{name}}Ok() (*{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}, bool) { if o == nil{{#isNullable}}{{#vendorExtensions.x-golang-is-container}} || IsNil(o.{{name}}){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { {{^isFreeFormObject}} return nil, false {{/isFreeFormObject}} {{#isFreeFormObject}} - return &{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}}{}, false + return &{{datatype}}{}, false {{/isFreeFormObject}} } {{#isNullable}} @@ -172,7 +170,7 @@ func (o *{{classname}}) Get{{name}}Ok() (*{{#isNumber}}float64{{/isNumber}}{{#is {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Set{{name}}(v *{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}}) { +func (o *{{classname}}) Set{{name}}(v *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}) { {{#isNullable}} {{#vendorExtensions.x-golang-is-container}} o.{{name}} = v @@ -195,9 +193,9 @@ func (o *{{classname}}) Set{{name}}(v *{{#isNumber}}float64{{/isNumber}}{{#isFlo {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}() *{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}} { +func (o *{{classname}}) Get{{name}}() *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}} { if o == nil || IsNil(o.{{name}}) {{#isNullable}}{{^vendorExtensions.x-golang-is-container}} || IsNil(o.{{name}}.Get()){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { - var ret *{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}} + var ret *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}} return ret } {{#isNullable}} @@ -221,13 +219,13 @@ func (o *{{classname}}) Get{{name}}() *{{#isNumber}}float64{{/isNumber}}{{#isFlo {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}Ok() (*{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}}, bool) { +func (o *{{classname}}) Get{{name}}Ok() (*{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}}, bool) { if o == nil || IsNil(o.{{name}}) { {{^isFreeFormObject}} return nil, false {{/isFreeFormObject}} {{#isFreeFormObject}} - return &{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}}{}, false + return &{{datatype}}{}, false {{/isFreeFormObject}} } {{#isNullable}} @@ -256,14 +254,14 @@ func (o *{{classname}}) Has{{name}}() bool { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Set{{name}}(v *{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}}) { +func (o *{{classname}}) Set{{name}}(v *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}}) { {{#isNullable}} {{#vendorExtensions.x-golang-is-container}} o.{{name}} = v {{/vendorExtensions.x-golang-is-container}} {{^vendorExtensions.x-golang-is-container}} if IsNil(o.{{name}}) { - o.{{name}} = new({{dataType}}) + o.{{name}} = new({{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}) } o.{{name}}.Set(v) {{/vendorExtensions.x-golang-is-container}} @@ -277,7 +275,7 @@ func (o *{{classname}}) Set{{name}}(v *{{#isNumber}}float64{{/isNumber}}{{#isFlo // Set{{name}}Nil sets the value for {{name}} to be an explicit nil func (o *{{classname}}) Set{{name}}Nil() { if IsNil(o.{{name}}) { - o.{{name}} = new({{dataType}}) + o.{{name}} = new({{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}) } o.{{name}}.Set(nil) } @@ -285,7 +283,7 @@ func (o *{{classname}}) Set{{name}}Nil() { // Unset{{name}} ensures that no value is present for {{name}}, not even an explicit nil func (o *{{classname}}) Unset{{name}}() { if IsNil(o.{{name}}) { - o.{{name}} = new({{dataType}}) + o.{{name}} = new({{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}) } o.{{name}}.Unset() } From 0418d6fad801b4025aa0bf916b84694dd99a45dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Wed, 19 Feb 2025 14:26:35 +0100 Subject: [PATCH 07/20] fix: add exceptions for float32 and int32 to keep bug-compatibility with previous generated code --- scripts/generate-sdk/languages/go.sh | 2 +- templates/go/api_test.mustache | 4 +- templates/go/model_simple.mustache | 316 +++++++++++++-------------- templates/go/utils.mustache | 48 ++++ 4 files changed, 209 insertions(+), 161 deletions(-) diff --git a/scripts/generate-sdk/languages/go.sh b/scripts/generate-sdk/languages/go.sh index 10d9528..1483323 100644 --- a/scripts/generate-sdk/languages/go.sh +++ b/scripts/generate-sdk/languages/go.sh @@ -158,7 +158,7 @@ generate_go_sdk() { --git-host ${GIT_HOST} \ --git-user-id ${GIT_USER_ID} \ --git-repo-id ${GIT_REPO_ID} \ - --global-property apis,models,modelTests=true,modelDocs=false,apiDocs=false,supportingFiles \ + --global-property apis,models,modelTests=true,modelDocs=false,apiDocs=false,supportingFiles,debugModels=true \ --additional-properties=isGoSubmodule=true,enumClassPrefix=true,$regional_api # Remove unnecessary files rm ${SERVICES_FOLDER}/${service}/.openapi-generator-ignore diff --git a/templates/go/api_test.mustache b/templates/go/api_test.mustache index 3e4cbba..30cd639 100644 --- a/templates/go/api_test.mustache +++ b/templates/go/api_test.mustache @@ -41,7 +41,7 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) { {{/returnFormat}} {{^returnFormat}} {{#returnType}} - data := {{{.}}}{} + var data {{returnType}} w.Header().Add("Content-Type", "application/json") json.NewEncoder(w).Encode(data) {{/returnType}} @@ -98,7 +98,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}} diff --git a/templates/go/model_simple.mustache b/templates/go/model_simple.mustache index 0fad61d..c79a6a4 100644 --- a/templates/go/model_simple.mustache +++ b/templates/go/model_simple.mustache @@ -1,6 +1,107 @@ // checks if the {{classname}} type satisfies the MappedNullable interface at compile time var _ MappedNullable = &{{classname}}{} +{{#vars}} +// {{baseName}} +/* + {{{.}}} +*/ +{{#isArray}} +{{#isNullable}} +type {{classname}}{{name}}AttributeType = NullableValue[{{dataType}}] +type {{classname}}{{name}}ArgType = {{dataType}} +{{/isNullable}} +{{^isNullable}} +type {{classname}}{{name}}AttributeType = *{{dataType}} +type {{classname}}{{name}}ArgType = {{dataType}} +{{/isNullable}} +{{/isArray}} + +{{#isModel}} +{{#isNullable}} +type {{classname}}{{name}}AttributeType = NullableValue[{{dataType}}] +type {{classname}}{{name}}ArgType = {{dataType}} +{{/isNullable}} +{{^isNullable}} +type {{classname}}{{name}}AttributeType = *{{dataType}} +type {{classname}}{{name}}ArgType = {{dataType}} +{{/isNullable}} +{{/isModel}} +{{#isMap}} +type {{classname}}{{name}}AttributeType = {{dataType}} +type {{classname}}{{name}}ArgType = {{dataType}} +{{/isMap}} + + +{{^isContainer}} +{{#isNullable}} +{{#isNumber}} +type {{classname}}{{name}}AttributeType = NullableValue[float64] +type {{classname}}{{name}}ArgType = *float64 +{{/isNumber}} +{{#isShort}} +type {{classname}}{{name}}AttributeType = NullableValue[int16] +type {{classname}}{{name}}ArgType = *int16 +{{/isShort}} +{{#isInteger}} +type {{classname}}{{name}}AttributeType = NullableValue[int32] +type {{classname}}{{name}}ArgType = *int32 +{{/isInteger}} +{{#isLong}} +type {{classname}}{{name}}AttributeType = NullableValue[int64] +type {{classname}}{{name}}ArgType = *int64 +{{/isLong}} +{{#isDateTime}} +type {{classname}}{{name}}AttributeType = NullableTime +type {{classname}}{{name}}ArgType = *time.Time +{{/isDateTime}} +{{#isEnumRef}} +type {{classname}}{{name}}AttributeType = NullableString +type {{classname}}{{name}}ArgType = *string +{{/isEnumRef}} +{{/isNullable}} + +{{^isNullable}} +{{#isNumber}} +type {{classname}}{{name}}AttributeType = *float64 +type {{classname}}{{name}}ArgType = float64 +{{/isNumber}} +{{^isNumber}} +{{#isShort}} +type {{classname}}{{name}}AttributeType = *int16 +type {{classname}}{{name}}ArgType = int16 +{{/isShort}} +{{#isInteger}} +type {{classname}}{{name}}AttributeType = *int32 +type {{classname}}{{name}}ArgType = int32 +{{/isInteger}} +{{#isLong}} +type {{classname}}{{name}}AttributeType = *int64 +type {{classname}}{{name}}ArgType = int64 +{{/isLong}} +{{/isNumber}} +{{#isDateTime}} +type {{classname}}{{name}}AttributeType = *time.Time +type {{classname}}{{name}}ArgType = time.Time +{{/isDateTime}} +{{#isEnumRef}} +type {{classname}}{{name}}AttributeType = *{{datatype}} +type {{classname}}{{name}}ArgType = {{datatype}} +{{/isEnumRef}} +{{#isPrimitiveType}} +{{^isNumeric}} +{{^isEnumRef}} +type {{classname}}{{name}}AttributeType = *{{dataType}} +type {{classname}}{{name}}ArgType = {{dataType}} +{{/isEnumRef}} +{{/isNumeric}} +{{/isPrimitiveType}} +{{/isNullable}} + +{{/isContainer}} + +{{/vars}} + // {{classname}} {{{description}}}{{^description}}struct for {{{classname}}}{{/description}} type {{classname}} struct { {{#parent}} @@ -37,16 +138,19 @@ type {{classname}} struct { {{/isWriteOnly}} {{/isReadOnly}} {{/required}} - {{name}} *{{#isNullable}}{{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}{{/isNullable}}{{^isNullable}}{{^isPrimitiveType}}{{dataType}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}{{/isPrimitiveType}}{{/isNullable}} `json:"{{baseName}}{{#required}}{{#isReadOnly}},omitempty{{/isReadOnly}}{{/required}}{{#required}}{{#isWriteOnly}},omitempty{{/isWriteOnly}}{{/required}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` + {{name}} {{classname}}{{name}}AttributeType +{{/vars}} {{#isAdditionalPropertiesTrue}} AdditionalProperties map[string]interface{} {{/isAdditionalPropertiesTrue}} -{{/vars}} } {{#isAdditionalPropertiesTrue}} -type _{{{classname}}} {{{classname}}} +' +9. ++3+ +3. +typ.0e _{{{classname}}} {{{classname}}} {{/isAdditionalPropertiesTrue}} {{^isAdditionalPropertiesTrue}} @@ -59,26 +163,16 @@ type _{{{classname}}} {{{classname}}} // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{datatype}}{{/isInteger}}{{^-last}}, {{/-last}}{{/requiredVars}}) *{{classname}} { +func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} {{classname}}{{name}}ArgType{{^-last}}, {{/-last}}{{/requiredVars}}) *{{classname}} { this := {{classname}}{} {{#allVars}} {{#required}} - this.{{name}} = {{nameInCamelCase}} -{{/required}} -{{^required}} -{{#defaultValue}} -{{^vendorExtensions.x-golang-is-container}} -{{^isReadOnly}} - var {{nameInCamelCase}} {{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}} = {{{.}}} -{{#isNullable}} - this.{{name}} = *New{{dataType}}(&{{nameInCamelCase}}) -{{/isNullable}} -{{^isNullable}} + {{#isNullable}} + this.{{name}}.Set({{nameInCamelCase}}) + {{/isNullable}} + {{^isNullable}} this.{{name}} = &{{nameInCamelCase}} -{{/isNullable}} -{{/isReadOnly}} -{{/vendorExtensions.x-golang-is-container}} -{{/defaultValue}} + {{/isNullable}} {{/required}} {{/allVars}} return &this @@ -94,7 +188,7 @@ func New{{classname}}WithDefaults() *{{classname}} { {{^vendorExtensions.x-golang-is-container}} {{^isReadOnly}} {{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}} - var {{nameInCamelCase}} {{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}} = {{{.}}} + var {{nameInCamelCase}} {{#isInteger}}int64{{/isInteger}}{{#isNumber}}float64{{/isNumber}}{{^isNumber}}{{^isInteger}}{{dataType}}{{/isInteger}}{{/isNumber}} = {{{.}}} {{#isNullable}} this.{{name}} = *New{{dataType}}(&{{nameInCamelCase}}) {{/isNullable}} @@ -117,23 +211,9 @@ func New{{classname}}WithDefaults() *{{classname}} { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}() *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}} { - if o == nil|| IsNil(o.{{name}}) {{#isNullable}}{{^vendorExtensions.x-golang-is-container}} || o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { - var ret *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}} - return ret - } - -{{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} - return o.{{name}} -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} - return o.{{name}}.Get() -{{/vendorExtensions.x-golang-is-container}} -{{/isNullable}} -{{^isNullable}} - return o.{{name}} -{{/isNullable}} +func (o *{{classname}}) Get{{name}}() (ret {{classname}}{{name}}ArgType) { + ret,_ = o.Get{{name}}Ok() + return ret } // Get{{name}}Ok returns a tuple with the {{name}} field value @@ -144,47 +224,29 @@ func (o *{{classname}}) Get{{name}}() *{{#isInteger}}int64{{/isInteger}}{{^isInt {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}Ok() (*{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}, bool) { - if o == nil{{#isNullable}}{{#vendorExtensions.x-golang-is-container}} || IsNil(o.{{name}}){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { -{{^isFreeFormObject}} - return nil, false - {{/isFreeFormObject}} - {{#isFreeFormObject}} - return &{{datatype}}{}, false - {{/isFreeFormObject}} +func (o *{{classname}}) Get{{name}}Ok() (ret {{classname}}{{name}}ArgType, ok bool) { + {{#isNullable}} + return o.{{name}}.Get(),o.{{name}}.IsSet() + {{/isNullable}} + {{^isNullable}} + if IsNil(o.{{name}}) { + return ret,false } -{{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} - return {{^isArray}}{{^isFreeFormObject}}&{{/isFreeFormObject}}{{/isArray}}o.{{name}}, true -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} - return o.{{name}}.Get(), o.{{name}}.IsSet() -{{/vendorExtensions.x-golang-is-container}} -{{/isNullable}} -{{^isNullable}} - return o.{{name}}, true -{{/isNullable}} + return *o.{{name}},true + {{/isNullable}} } // Set{{name}} sets field value {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Set{{name}}(v *{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}) { -{{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} - o.{{name}} = v -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} - if IsNil(o.{{name}}) { - o.{{name}} = new({{dataType}}) - } +func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}ArgType) { + {{#isNullable}} o.{{name}}.Set(v) -{{/vendorExtensions.x-golang-is-container}} -{{/isNullable}} -{{^isNullable}} - o.{{name}} = v -{{/isNullable}} + {{/isNullable}} + {{^isNullable}} + o.{{name}} = &v + {{/isNullable}} } {{/required}} @@ -193,22 +255,9 @@ func (o *{{classname}}) Set{{name}}(v *{{#isInteger}}int64{{/isInteger}}{{^isInt {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}() *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}} { - if o == nil || IsNil(o.{{name}}) {{#isNullable}}{{^vendorExtensions.x-golang-is-container}} || IsNil(o.{{name}}.Get()){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { - var ret *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}} - return ret - } -{{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} - return o.{{name}} -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} - return o.{{name}}.Get() -{{/vendorExtensions.x-golang-is-container}} -{{/isNullable}} -{{^isNullable}} - return o.{{name}} -{{/isNullable}} +func (o *{{classname}}) Get{{name}}() (res {{classname}}{{name}}ArgType) { + res,_ = o.Get{{name}}Ok() + return } // Get{{name}}Ok returns a tuple with the {{name}} field value if set, nil otherwise @@ -219,72 +268,48 @@ func (o *{{classname}}) Get{{name}}() *{{#isContainer}}{{dataType}}{{/isContaine {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}Ok() (*{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}}, bool) { - if o == nil || IsNil(o.{{name}}) { - {{^isFreeFormObject}} - return nil, false - {{/isFreeFormObject}} - {{#isFreeFormObject}} - return &{{datatype}}{}, false - {{/isFreeFormObject}} +func (o *{{classname}}) Get{{name}}Ok() (ret {{classname}}{{name}}ArgType, ok bool) { + {{#isNullable}} + return o.{{name}}.Get(),o.{{name}}.IsSet() + {{/isNullable}} + {{^isNullable}} + if IsNil(o.{{name}}) { + return ret,false } -{{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} - return {{^isArray}}{{^isFreeFormObject}}{{^isAnyType}}&{{/isAnyType}}{{/isFreeFormObject}}{{/isArray}}o.{{name}}, true -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} - return o.{{name}}.Get(), o.{{name}}.IsSet() -{{/vendorExtensions.x-golang-is-container}} -{{/isNullable}} -{{^isNullable}} - return o.{{name}}, true -{{/isNullable}} + return *o.{{name}},true + {{/isNullable}} + } // Has{{name}} returns a boolean if a field has been set. func (o *{{classname}}) Has{{name}}() bool { - if o != nil && !IsNil(o.{{name}}){{#isNullable}}{{^vendorExtensions.x-golang-is-container}} && o.{{name}}.IsSet(){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { - return true - } - - return false + _,ok:=o.Get{{name}}Ok() + return ok } // Set{{name}} gets a reference to the given {{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{vendorExtensions.x-go-base-type}}{{/isNumeric}} and assigns it to the {{name}} field. {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Set{{name}}(v *{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}{{#isInteger}}int64{{/isInteger}}{{^isInteger}}{{baseType}}{{/isInteger}}{{/isContainer}}) { -{{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} - o.{{name}} = v -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} - if IsNil(o.{{name}}) { - o.{{name}} = new({{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}) - } +func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}ArgType) { + {{#isNullable}} o.{{name}}.Set(v) -{{/vendorExtensions.x-golang-is-container}} -{{/isNullable}} -{{^isNullable}} - o.{{name}} = v -{{/isNullable}} + {{/isNullable}} + {{^isNullable}} + o.{{name}} = &v + {{/isNullable}} } + + {{#isNullable}} {{^vendorExtensions.x-golang-is-container}} // Set{{name}}Nil sets the value for {{name}} to be an explicit nil func (o *{{classname}}) Set{{name}}Nil() { - if IsNil(o.{{name}}) { - o.{{name}} = new({{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}) - } o.{{name}}.Set(nil) } // Unset{{name}} ensures that no value is present for {{name}}, not even an explicit nil func (o *{{classname}}) Unset{{name}}() { - if IsNil(o.{{name}}) { - o.{{name}} = new({{#isInteger}}NullableInt64{{/isInteger}}{{^isInteger}}{{dataType}}{{/isInteger}}) - } o.{{name}}.Unset() } {{/vendorExtensions.x-golang-is-container}} @@ -325,35 +350,10 @@ func (o {{classname}}) ToMap() (map[string]interface{}, error) { {{/parent}} {{#vars}} {{! if argument is nullable, only serialize it if it is set}} - {{#isNullable}} - {{#vendorExtensions.x-golang-is-container}} - {{! support for container fields is not ideal at this point because of lack of Nullable* types}} - if o.{{name}} != nil { - toSerialize["{{{baseName}}}"] = o.{{name}} - } - {{/vendorExtensions.x-golang-is-container}} - {{^vendorExtensions.x-golang-is-container}} - {{#required}} - toSerialize["{{{baseName}}}"] = o.{{name}}.Get() - {{/required}} - {{^required}} - if o.{{name}}.IsSet() { - toSerialize["{{{baseName}}}"] = o.{{name}}.Get() - } - {{/required}} - {{/vendorExtensions.x-golang-is-container}} - {{/isNullable}} {{! if argument is not nullable, don't set it if it is nil}} - {{^isNullable}} - {{#required}} - toSerialize["{{{baseName}}}"] = o.{{name}} - {{/required}} - {{^required}} - if !IsNil(o.{{name}}) { - toSerialize["{{{baseName}}}"] = o.{{name}} + if o.{{nameInCamelCase}}.IsSet() { + toSerialize["{{{nameInCamelCase}}}"] = o.{{nameInCamelCase}}.Get() } - {{/required}} - {{/isNullable}} {{/vars}} {{#isAdditionalPropertiesTrue}} @@ -380,7 +380,7 @@ func (o *{{{classname}}}) UnmarshalJSON(data []byte) (err error) { // that every required field exists as a key in the generic map. requiredProperties := []string{ {{#requiredVars}} - "{{baseName}}", + "{{nameInCamelCase}}", {{/requiredVars}} } diff --git a/templates/go/utils.mustache b/templates/go/utils.mustache index 8ba1109..21eac91 100644 --- a/templates/go/utils.mustache +++ b/templates/go/utils.mustache @@ -31,6 +31,29 @@ func PtrString(v string) *string { return &v } // PtrTime is helper routine that returns a pointer to given Time value. func PtrTime(v time.Time) *time.Time { return &v } +type NullableValue[T any] struct { + value *T + isSet bool +} + +func (v NullableValue[T]) Get() *T { + return v.value +} + +func (v *NullableValue[T]) Set(val *T) { + v.value = val + v.isSet = true +} + +func (v NullableValue[T]) IsSet() bool { + return v.isSet +} + +func (v *NullableValue[T]) Unset() { + v.value = nil + v.isSet = false +} + type NullableBool struct { value *bool isSet bool @@ -324,6 +347,9 @@ func IsNil(i interface{}) bool { if i == nil { return true } + if t,ok:=i.(interface{ IsSet() bool});ok { + return !t.IsSet() + } switch reflect.TypeOf(i).Kind() { case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: return reflect.ValueOf(i).IsNil() @@ -336,3 +362,25 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } + + + +// ----------------------------------------------------------------------------- +// --- NotNullableValue +// ----------------------------------------------------------------------------- +type NotNullableValue[T any] struct { + value T +} + +func (v NotNullableValue[T]) Get() T { + return v.value +} + +func (v NotNullableValue[T]) Set(a T) { + v.value = a +} + +func (v NotNullableValue[T]) IsSet() bool { + return true +} + From 8e21d0b3d854b914f709494dcb07c4a696bdd775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Tue, 4 Mar 2025 13:03:05 +0100 Subject: [PATCH 08/20] fix: introduced specialized types --- templates/go/model_simple.mustache | 382 ++++++++++++++++++++--------- templates/go/utils.mustache | 22 -- 2 files changed, 264 insertions(+), 140 deletions(-) diff --git a/templates/go/model_simple.mustache b/templates/go/model_simple.mustache index c79a6a4..3e61bee 100644 --- a/templates/go/model_simple.mustache +++ b/templates/go/model_simple.mustache @@ -2,103 +2,276 @@ var _ MappedNullable = &{{classname}}{} {{#vars}} -// {{baseName}} +// {{baseName}} /* - {{{.}}} +{{{.}}} */ -{{#isArray}} -{{#isNullable}} -type {{classname}}{{name}}AttributeType = NullableValue[{{dataType}}] -type {{classname}}{{name}}ArgType = {{dataType}} -{{/isNullable}} -{{^isNullable}} -type {{classname}}{{name}}AttributeType = *{{dataType}} -type {{classname}}{{name}}ArgType = {{dataType}} -{{/isNullable}} -{{/isArray}} - -{{#isModel}} -{{#isNullable}} -type {{classname}}{{name}}AttributeType = NullableValue[{{dataType}}] -type {{classname}}{{name}}ArgType = {{dataType}} -{{/isNullable}} -{{^isNullable}} -type {{classname}}{{name}}AttributeType = *{{dataType}} -type {{classname}}{{name}}ArgType = {{dataType}} -{{/isNullable}} -{{/isModel}} -{{#isMap}} -type {{classname}}{{name}}AttributeType = {{dataType}} -type {{classname}}{{name}}ArgType = {{dataType}} -{{/isMap}} - - -{{^isContainer}} -{{#isNullable}} {{#isNumber}} -type {{classname}}{{name}}AttributeType = NullableValue[float64] -type {{classname}}{{name}}ArgType = *float64 -{{/isNumber}} -{{#isShort}} -type {{classname}}{{name}}AttributeType = NullableValue[int16] -type {{classname}}{{name}}ArgType = *int16 -{{/isShort}} -{{#isInteger}} -type {{classname}}{{name}}AttributeType = NullableValue[int32] -type {{classname}}{{name}}ArgType = *int32 -{{/isInteger}} -{{#isLong}} -type {{classname}}{{name}}AttributeType = NullableValue[int64] -type {{classname}}{{name}}ArgType = *int64 -{{/isLong}} -{{#isDateTime}} -type {{classname}}{{name}}AttributeType = NullableTime -type {{classname}}{{name}}ArgType = *time.Time -{{/isDateTime}} -{{#isEnumRef}} -type {{classname}}{{name}}AttributeType = NullableString -type {{classname}}{{name}}ArgType = *string -{{/isEnumRef}} -{{/isNullable}} +type {{classname}}{{name}}AttributeType = float64 +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}float64 +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}float64 +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} -{{^isNullable}} -{{#isNumber}} -type {{classname}}{{name}}AttributeType = *float64 -type {{classname}}{{name}}ArgType = float64 +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} {{/isNumber}} -{{^isNumber}} {{#isShort}} -type {{classname}}{{name}}AttributeType = *int16 -type {{classname}}{{name}}ArgType = int16 +type {{classname}}{{name}}AttributeType = *int64 +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}int64 +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}int64 +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} {{/isShort}} {{#isInteger}} -type {{classname}}{{name}}AttributeType = *int32 -type {{classname}}{{name}}ArgType = int32 +type {{classname}}{{name}}AttributeType = *int64 +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}int64 +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}int64 +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} {{/isInteger}} {{#isLong}} type {{classname}}{{name}}AttributeType = *int64 -type {{classname}}{{name}}ArgType = int64 +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}int64 +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}int64 +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} {{/isLong}} -{{/isNumber}} {{#isDateTime}} type {{classname}}{{name}}AttributeType = *time.Time -type {{classname}}{{name}}ArgType = time.Time +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}time.Time +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}time.Time +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} {{/isDateTime}} {{#isEnumRef}} -type {{classname}}{{name}}AttributeType = *{{datatype}} -type {{classname}}{{name}}ArgType = {{datatype}} +type {{classname}}{{name}}AttributeType = *string +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}string +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}string +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} {{/isEnumRef}} -{{#isPrimitiveType}} -{{^isNumeric}} -{{^isEnumRef}} +{{#isModel}} type {{classname}}{{name}}AttributeType = *{{dataType}} -type {{classname}}{{name}}ArgType = {{dataType}} -{{/isEnumRef}} -{{/isNumeric}} -{{/isPrimitiveType}} +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isModel}} +{{#isArray}} +type {{classname}}{{name}}AttributeType = *{{dataType}} +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isArray}} + +{{#isString}} +{{#isNullable}} +type {{classname}}{{name}}AttributeType = *{{dataType}} +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return arg.Get(),true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + if IsNil(*arg) { + *arg = NewNullableString(val) + } else { + (*arg).Set(val) + } +} {{/isNullable}} +{{^isNullable}} +type {{classname}}{{name}}AttributeType = *string +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} -{{/isContainer}} +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isNullable}} +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}string +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}string +{{/isString}} + +{{#isFreeFormObject}} +type {{classname}}{{name}}AttributeType = *map[string]any +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}map[string]any +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}map[string]any +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isFreeFormObject}} +{{#isByteArray}} +type {{classname}}{{name}}AttributeType = *[]byte +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}[]byte +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}[]byte +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isByteArray}} +{{#isBoolean}} +type {{classname}}{{name}}AttributeType = *bool +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}bool +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}bool +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isBoolean}} {{/vars}} @@ -211,7 +384,7 @@ func New{{classname}}WithDefaults() *{{classname}} { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}() (ret {{classname}}{{name}}ArgType) { +func (o *{{classname}}) Get{{name}}() (ret {{classname}}{{name}}RetType) { ret,_ = o.Get{{name}}Ok() return ret } @@ -224,29 +397,16 @@ func (o *{{classname}}) Get{{name}}() (ret {{classname}}{{name}}ArgType) { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}Ok() (ret {{classname}}{{name}}ArgType, ok bool) { - {{#isNullable}} - return o.{{name}}.Get(),o.{{name}}.IsSet() - {{/isNullable}} - {{^isNullable}} - if IsNil(o.{{name}}) { - return ret,false - } - return *o.{{name}},true - {{/isNullable}} +func (o *{{classname}}) Get{{name}}Ok() (ret {{classname}}{{name}}RetType, ok bool) { + return get{{classname}}{{name}}AttributeTypeOk(o.{{name}}) } // Set{{name}} sets field value {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}ArgType) { - {{#isNullable}} - o.{{name}}.Set(v) - {{/isNullable}} - {{^isNullable}} - o.{{name}} = &v - {{/isNullable}} +func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}RetType) { + set{{classname}}{{name}}AttributeType(&o.{{name}},v) } {{/required}} @@ -255,7 +415,7 @@ func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}ArgType) { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}() (res {{classname}}{{name}}ArgType) { +func (o *{{classname}}) Get{{name}}() (res {{classname}}{{name}}RetType) { res,_ = o.Get{{name}}Ok() return } @@ -268,17 +428,8 @@ func (o *{{classname}}) Get{{name}}() (res {{classname}}{{name}}ArgType) { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}Ok() (ret {{classname}}{{name}}ArgType, ok bool) { - {{#isNullable}} - return o.{{name}}.Get(),o.{{name}}.IsSet() - {{/isNullable}} - {{^isNullable}} - if IsNil(o.{{name}}) { - return ret,false - } - return *o.{{name}},true - {{/isNullable}} - +func (o *{{classname}}) Get{{name}}Ok() (ret {{classname}}{{name}}RetType, ok bool) { + return get{{classname}}{{name}}AttributeTypeOk(o.{{name}}) } // Has{{name}} returns a boolean if a field has been set. @@ -291,13 +442,8 @@ func (o *{{classname}}) Has{{name}}() bool { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}ArgType) { - {{#isNullable}} - o.{{name}}.Set(v) - {{/isNullable}} - {{^isNullable}} - o.{{name}} = &v - {{/isNullable}} +func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}RetType) { + set{{classname}}{{name}}AttributeType(&o.{{name}},v) } @@ -305,12 +451,12 @@ func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}ArgType) { {{^vendorExtensions.x-golang-is-container}} // Set{{name}}Nil sets the value for {{name}} to be an explicit nil func (o *{{classname}}) Set{{name}}Nil() { - o.{{name}}.Set(nil) + o.{{name}} = nil } // Unset{{name}} ensures that no value is present for {{name}}, not even an explicit nil func (o *{{classname}}) Unset{{name}}() { - o.{{name}}.Unset() + o.{{name}} = nil } {{/vendorExtensions.x-golang-is-container}} {{/isNullable}} @@ -351,8 +497,8 @@ func (o {{classname}}) ToMap() (map[string]interface{}, error) { {{#vars}} {{! if argument is nullable, only serialize it if it is set}} {{! if argument is not nullable, don't set it if it is nil}} - if o.{{nameInCamelCase}}.IsSet() { - toSerialize["{{{nameInCamelCase}}}"] = o.{{nameInCamelCase}}.Get() + if !IsNil(o.{{name}}) { + toSerialize["{{{name}}}"] = {{#isNullable}}*{{/isNullable}}o.{{name}} } {{/vars}} {{#isAdditionalPropertiesTrue}} diff --git a/templates/go/utils.mustache b/templates/go/utils.mustache index 21eac91..4bd0284 100644 --- a/templates/go/utils.mustache +++ b/templates/go/utils.mustache @@ -362,25 +362,3 @@ func IsNil(i interface{}) bool { type MappedNullable interface { ToMap() (map[string]interface{}, error) } - - - -// ----------------------------------------------------------------------------- -// --- NotNullableValue -// ----------------------------------------------------------------------------- -type NotNullableValue[T any] struct { - value T -} - -func (v NotNullableValue[T]) Get() T { - return v.value -} - -func (v NotNullableValue[T]) Set(a T) { - v.value = a -} - -func (v NotNullableValue[T]) IsSet() bool { - return true -} - From 59ebd0d8d50f7d91d02f438a1a532aa7b1685963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Tue, 4 Mar 2025 14:47:30 +0100 Subject: [PATCH 09/20] fix: generation working without compile issues, but broken tests --- templates/go/model_simple.mustache | 126 ++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 36 deletions(-) diff --git a/templates/go/model_simple.mustache b/templates/go/model_simple.mustache index 3e61bee..3d6c46c 100644 --- a/templates/go/model_simple.mustache +++ b/templates/go/model_simple.mustache @@ -6,8 +6,9 @@ var _ MappedNullable = &{{classname}}{} /* {{{.}}} */ +{{^isEnum}} {{#isNumber}} -type {{classname}}{{name}}AttributeType = float64 +type {{classname}}{{name}}AttributeType = *float64 type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}float64 type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}float64 func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { @@ -27,6 +28,7 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy } {{/isNumber}} {{#isShort}} +{{^isInteger}} type {{classname}}{{name}}AttributeType = *int64 type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}int64 type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}int64 @@ -45,6 +47,7 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } +{{/isInteger}} {{/isShort}} {{#isInteger}} type {{classname}}{{name}}AttributeType = *int64 @@ -86,6 +89,52 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy *arg={{^isNullable}}&{{/isNullable}}val } {{/isLong}} +{{#isString}} +{{#isNullable}} +type {{classname}}{{name}}AttributeType = *{{dataType}} +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return arg.Get(),true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + if IsNil(*arg) { + *arg = NewNullableString(val) + } else { + (*arg).Set(val) + } +} +{{/isNullable}} +{{^isNullable}} +type {{classname}}{{name}}AttributeType = *string +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isNullable}} +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}string +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}string +{{/isString}} +{{/isEnum}} + {{#isDateTime}} type {{classname}}{{name}}AttributeType = *time.Time type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}time.Time @@ -107,9 +156,9 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy } {{/isDateTime}} {{#isEnumRef}} -type {{classname}}{{name}}AttributeType = *string -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}string -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}string +type {{classname}}{{name}}AttributeType = *{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { if arg == nil { {{#isNullable}} @@ -146,7 +195,13 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy *arg={{^isNullable}}&{{/isNullable}}val } {{/isModel}} -{{#isArray}} +{{^isPrimitiveType}} +{{^isModel}} +{{^isMap}} +{{^isArray}} +{{^isDateTime}} +{{^isEnumRef}} +// fallback type {{classname}}{{name}}AttributeType = *{{dataType}} type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} @@ -165,11 +220,16 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } +{{/isEnumRef}} +{{/isDateTime}} {{/isArray}} - -{{#isString}} -{{#isNullable}} +{{/isMap}} +{{/isModel}} +{{/isPrimitiveType}} +{{#isArray}} type {{classname}}{{name}}AttributeType = *{{dataType}} +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { if arg == nil { {{#isNullable}} @@ -179,19 +239,20 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return ret,false {{/isNullable}} } - return arg.Get(),true + return {{^isNullable}}*{{/isNullable}}arg,true } func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { - if IsNil(*arg) { - *arg = NewNullableString(val) - } else { - (*arg).Set(val) - } + *arg={{^isNullable}}&{{/isNullable}}val } -{{/isNullable}} -{{^isNullable}} -type {{classname}}{{name}}AttributeType = *string +{{/isArray}} + + +{{#isFreeFormObject}} +// freeform +type {{classname}}{{name}}AttributeType = *{{dataType}} +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { if arg == nil { {{#isNullable}} @@ -207,15 +268,14 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } -{{/isNullable}} -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}string -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}string -{{/isString}} - -{{#isFreeFormObject}} -type {{classname}}{{name}}AttributeType = *map[string]any -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}map[string]any -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}map[string]any +{{/isFreeFormObject}} +{{#isContainer}} +{{^isFreeFormObject}} +{{^isArray}} +// container +type {{classname}}{{name}}AttributeType = *{{dataType}} +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { if arg == nil { {{#isNullable}} @@ -231,7 +291,9 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } +{{/isArray}} {{/isFreeFormObject}} +{{/isContainer}} {{#isByteArray}} type {{classname}}{{name}}AttributeType = *[]byte type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}[]byte @@ -320,10 +382,7 @@ type {{classname}} struct { {{#isAdditionalPropertiesTrue}} -' +9. -+3+ -3. -typ.0e _{{{classname}}} {{{classname}}} +type _{{{classname}}} {{{classname}}} {{/isAdditionalPropertiesTrue}} {{^isAdditionalPropertiesTrue}} @@ -340,12 +399,7 @@ func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} {{classname}}{{name}} this := {{classname}}{} {{#allVars}} {{#required}} - {{#isNullable}} - this.{{name}}.Set({{nameInCamelCase}}) - {{/isNullable}} - {{^isNullable}} - this.{{name}} = &{{nameInCamelCase}} - {{/isNullable}} + set{{classname}}{{name}}AttributeType(&this.{{name}}, {{nameInCamelCase}}) {{/required}} {{/allVars}} return &this From 4131da3b5e7471b7b2d3bbc20f9b77ba4d9b0f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Tue, 4 Mar 2025 17:33:04 +0100 Subject: [PATCH 10/20] fix: beta apis compiling now --- templates/go/api_test.mustache | 4 +- templates/go/model_simple.mustache | 108 +++++++++++++++++++++++++++-- 2 files changed, 105 insertions(+), 7 deletions(-) diff --git a/templates/go/api_test.mustache b/templates/go/api_test.mustache index 30cd639..29778ec 100644 --- a/templates/go/api_test.mustache +++ b/templates/go/api_test.mustache @@ -28,7 +28,7 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) { {{#operation}} t.Run("Test {{classname}}Service {{{nickname}}}", func(t *testing.T) { _apiUrlPath := "{{{path}}}"{{#pathParams}} - {{paramName}}Value := {{#isAnyType}}"unspecified type"{{/isAnyType}}{{#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}}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() @@ -79,7 +79,7 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) { {{#allParams}} {{#required}} {{#isPathParam}} - {{paramName}} := {{#isAnyType}}"unspecified type"{{/isAnyType}}{{#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}} diff --git a/templates/go/model_simple.mustache b/templates/go/model_simple.mustache index 3d6c46c..a2c28d1 100644 --- a/templates/go/model_simple.mustache +++ b/templates/go/model_simple.mustache @@ -8,6 +8,7 @@ var _ MappedNullable = &{{classname}}{} */ {{^isEnum}} {{#isNumber}} +// isNumber type {{classname}}{{name}}AttributeType = *float64 type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}float64 type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}float64 @@ -27,8 +28,51 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy *arg={{^isNullable}}&{{/isNullable}}val } {{/isNumber}} +{{#isFloat}} +// isFloat +type {{classname}}{{name}}AttributeType = *float64 +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}float64 +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}float64 +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isFloat}} +{{#isDouble}} +// isDouble +type {{classname}}{{name}}AttributeType = *float64 +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}float64 +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}float64 +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isDouble}} {{#isShort}} {{^isInteger}} +// isShort type {{classname}}{{name}}AttributeType = *int64 type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}int64 type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}int64 @@ -50,6 +94,7 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{/isInteger}} {{/isShort}} {{#isInteger}} +// isInteger type {{classname}}{{name}}AttributeType = *int64 type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}int64 type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}int64 @@ -70,6 +115,7 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy } {{/isInteger}} {{#isLong}} +// isLong type {{classname}}{{name}}AttributeType = *int64 type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}int64 type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}int64 @@ -90,8 +136,10 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy } {{/isLong}} {{#isString}} +{{^isArray}} {{#isNullable}} -type {{classname}}{{name}}AttributeType = *{{dataType}} +// isNullableString +type {{classname}}{{name}}AttributeType = *NullableString func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { if arg == nil { {{#isNullable}} @@ -113,6 +161,7 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy } {{/isNullable}} {{^isNullable}} +// isNotNullableString type {{classname}}{{name}}AttributeType = *string func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { if arg == nil { @@ -132,10 +181,33 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{/isNullable}} type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}string type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}string +{{/isArray}} {{/isString}} +{{#isAnyType}} +// isAny +type {{classname}}{{name}}AttributeType = any +type {{classname}}{{name}}ArgType = any +type {{classname}}{{name}}RetType = any +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isAnyType}} {{/isEnum}} {{#isDateTime}} +// isDateTime type {{classname}}{{name}}AttributeType = *time.Time type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}time.Time type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}time.Time @@ -155,7 +227,29 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy *arg={{^isNullable}}&{{/isNullable}}val } {{/isDateTime}} +{{#isDate}} +// isDate +type {{classname}}{{name}}AttributeType = *time.Time +type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}time.Time +type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}time.Time +func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { + if arg == nil { + {{#isNullable}} + return nil,false + {{/isNullable}} + {{^isNullable}} + return ret,false + {{/isNullable}} + } + return {{^isNullable}}*{{/isNullable}}arg,true +} + +func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { + *arg={{^isNullable}}&{{/isNullable}}val +} +{{/isDate}} {{#isEnumRef}} +// isEnumRef type {{classname}}{{name}}AttributeType = *{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} @@ -176,6 +270,7 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy } {{/isEnumRef}} {{#isModel}} +// isModel type {{classname}}{{name}}AttributeType = *{{dataType}} type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} @@ -227,6 +322,7 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{/isModel}} {{/isPrimitiveType}} {{#isArray}} +// isArray type {{classname}}{{name}}AttributeType = *{{dataType}} type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} @@ -249,7 +345,7 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{#isFreeFormObject}} -// freeform +// isFreeform type {{classname}}{{name}}AttributeType = *{{dataType}} type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} @@ -272,7 +368,7 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{#isContainer}} {{^isFreeFormObject}} {{^isArray}} -// container +// isContainer type {{classname}}{{name}}AttributeType = *{{dataType}} type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} @@ -295,6 +391,7 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{/isFreeFormObject}} {{/isContainer}} {{#isByteArray}} +// isByteArray type {{classname}}{{name}}AttributeType = *[]byte type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}[]byte type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}[]byte @@ -315,6 +412,7 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy } {{/isByteArray}} {{#isBoolean}} +// isBoolean type {{classname}}{{name}}AttributeType = *bool type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}bool type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}bool @@ -551,8 +649,8 @@ func (o {{classname}}) ToMap() (map[string]interface{}, error) { {{#vars}} {{! if argument is nullable, only serialize it if it is set}} {{! if argument is not nullable, don't set it if it is nil}} - if !IsNil(o.{{name}}) { - toSerialize["{{{name}}}"] = {{#isNullable}}*{{/isNullable}}o.{{name}} + if val,ok:=get{{classname}}{{name}}AttributeTypeOk(o.{{name}});ok { + toSerialize["{{{name}}}"] = val } {{/vars}} {{#isAdditionalPropertiesTrue}} From 1e4643521b131895dec07b6b870357c1e8344fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Tue, 4 Mar 2025 17:52:24 +0100 Subject: [PATCH 11/20] fix: use getter-id instead of plain name to generate non-conflicting names --- templates/go/model_simple.mustache | 248 ++++++++++++++++------------- 1 file changed, 139 insertions(+), 109 deletions(-) diff --git a/templates/go/model_simple.mustache b/templates/go/model_simple.mustache index a2c28d1..4343c69 100644 --- a/templates/go/model_simple.mustache +++ b/templates/go/model_simple.mustache @@ -2,17 +2,37 @@ var _ MappedNullable = &{{classname}}{} {{#vars}} -// {{baseName}} + /* -{{{.}}} + types and functions for {{baseName}} + {{!.}} */ + +{{! The basic approach is as follows: To avoid checking the various datatypes, }} +{{! exceptions and non-orthogonal model states we introduce go type-alias }} +{{! These are compatible with their basic types (this maintains backwards)}} +{{! compatibility with existing code). This allows to concentrate the decision what }} +{{! actual type the openapi represents in a single place. Reusing the generated}} +{{! type in all other places avoids repetion of the non-trivial decision matrix}} +{{! which type is to be used.}} +{{! We define three basic types:}} +{{! - FooAttributeType: The type used for the model-struct definitions, i.e. the struct attribute type}} +{{! - FooArgType: The type used for parameter passing, i.e. in function calls}} +{{! - FooRetType: The type used for function returns.}} +{{! To simplify reading and writing values even further, type-safe}} +{{! helper methods for getting and setting valuesare generated as well}} +{{! (these are not rendered as methods, as the structs themselves may be nil)}} +{{! (a pure function avoids possible nil-pointer exceptions)}} + + +{{! address primitives types, excluding enums (they are handled explicitly below) }} {{^isEnum}} {{#isNumber}} // isNumber -type {{classname}}{{name}}AttributeType = *float64 -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}float64 -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}float64 -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *float64 +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}float64 +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}float64 +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -24,16 +44,16 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isNumber}} {{#isFloat}} // isFloat -type {{classname}}{{name}}AttributeType = *float64 -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}float64 -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}float64 -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *float64 +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}float64 +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}float64 +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -45,16 +65,16 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isFloat}} {{#isDouble}} // isDouble -type {{classname}}{{name}}AttributeType = *float64 -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}float64 -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}float64 -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *float64 +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}float64 +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}float64 +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -66,17 +86,18 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isDouble}} {{#isShort}} +{{! isShort and isInteger may be true at the same time, so select one}} {{^isInteger}} // isShort -type {{classname}}{{name}}AttributeType = *int64 -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}int64 -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}int64 -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *int64 +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}int64 +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}int64 +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -88,17 +109,17 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isInteger}} {{/isShort}} {{#isInteger}} // isInteger -type {{classname}}{{name}}AttributeType = *int64 -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}int64 -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}int64 -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *int64 +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}int64 +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}int64 +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -110,16 +131,16 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isInteger}} {{#isLong}} // isLong -type {{classname}}{{name}}AttributeType = *int64 -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}int64 -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}int64 -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *int64 +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}int64 +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}int64 +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -131,16 +152,19 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isLong}} {{#isString}} +{{! string-types are definitely used non-orthogonally, so we have to exclude some possibilities}} {{^isArray}} +{{! skip arrays, they are addressed explicitly below}} {{#isNullable}} +{{! nullable strings have a special type}} // isNullableString -type {{classname}}{{name}}AttributeType = *NullableString -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *NullableString +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -152,7 +176,7 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return arg.Get(),true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { if IsNil(*arg) { *arg = NewNullableString(val) } else { @@ -161,9 +185,10 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy } {{/isNullable}} {{^isNullable}} +{{! non nullable strings are plain string pointers}} // isNotNullableString -type {{classname}}{{name}}AttributeType = *string -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *string +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -175,20 +200,20 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isNullable}} -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}string -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}string +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}string +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}string {{/isArray}} {{/isString}} {{#isAnyType}} // isAny -type {{classname}}{{name}}AttributeType = any -type {{classname}}{{name}}ArgType = any -type {{classname}}{{name}}RetType = any -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = any +type {{classname}}{{getter}}ArgType = any +type {{classname}}{{getter}}RetType = any +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -200,18 +225,19 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isAnyType}} {{/isEnum}} {{#isDateTime}} +{{! special handling for date-time}} // isDateTime -type {{classname}}{{name}}AttributeType = *time.Time -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}time.Time -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}time.Time -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *time.Time +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}time.Time +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}time.Time +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -223,16 +249,17 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isDateTime}} {{#isDate}} +{{! special handling for date}} // isDate -type {{classname}}{{name}}AttributeType = *time.Time -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}time.Time -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}time.Time -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *time.Time +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}time.Time +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}time.Time +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -244,16 +271,17 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isDate}} {{#isEnumRef}} +{{! special handling for enums}} // isEnumRef -type {{classname}}{{name}}AttributeType = *{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -265,16 +293,17 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isEnumRef}} {{#isModel}} +{{! special handling for recursive datatypes}} // isModel -type {{classname}}{{name}}AttributeType = *{{dataType}} -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *{{dataType}} +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -286,7 +315,7 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isModel}} @@ -297,10 +326,11 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{^isDateTime}} {{^isEnumRef}} // fallback -type {{classname}}{{name}}AttributeType = *{{dataType}} -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +{{! everything else will end up here}} +type {{classname}}{{getter}}AttributeType = *{{dataType}} +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -312,7 +342,7 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isEnumRef}} @@ -323,10 +353,10 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{/isPrimitiveType}} {{#isArray}} // isArray -type {{classname}}{{name}}AttributeType = *{{dataType}} -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *{{dataType}} +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -338,7 +368,7 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isArray}} @@ -346,10 +376,10 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{#isFreeFormObject}} // isFreeform -type {{classname}}{{name}}AttributeType = *{{dataType}} -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *{{dataType}} +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -361,7 +391,7 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isFreeFormObject}} @@ -369,10 +399,10 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{^isFreeFormObject}} {{^isArray}} // isContainer -type {{classname}}{{name}}AttributeType = *{{dataType}} -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *{{dataType}} +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -384,7 +414,7 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isArray}} @@ -392,10 +422,10 @@ func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeTy {{/isContainer}} {{#isByteArray}} // isByteArray -type {{classname}}{{name}}AttributeType = *[]byte -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}[]byte -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}[]byte -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *[]byte +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}[]byte +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}[]byte +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -407,16 +437,16 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isByteArray}} {{#isBoolean}} // isBoolean -type {{classname}}{{name}}AttributeType = *bool -type {{classname}}{{name}}ArgType = {{#isNullable}}*{{/isNullable}}bool -type {{classname}}{{name}}RetType = {{#isNullable}}*{{/isNullable}}bool -func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeType) (ret {{classname}}{{name}}RetType, ok bool) { +type {{classname}}{{getter}}AttributeType = *bool +type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}bool +type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}bool +func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { if arg == nil { {{#isNullable}} return nil,false @@ -428,7 +458,7 @@ func get{{classname}}{{name}}AttributeTypeOk(arg {{classname}}{{name}}AttributeT return {{^isNullable}}*{{/isNullable}}arg,true } -func set{{classname}}{{name}}AttributeType(arg *{{classname}}{{name}}AttributeType, val {{classname}}{{name}}RetType) { +func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { *arg={{^isNullable}}&{{/isNullable}}val } {{/isBoolean}} @@ -471,7 +501,7 @@ type {{classname}} struct { {{/isWriteOnly}} {{/isReadOnly}} {{/required}} - {{name}} {{classname}}{{name}}AttributeType + {{name}} {{classname}}{{getter}}AttributeType {{/vars}} {{#isAdditionalPropertiesTrue}} AdditionalProperties map[string]interface{} @@ -493,11 +523,11 @@ type _{{{classname}}} {{{classname}}} // This constructor will assign default values to properties that have it defined, // and makes sure properties required by API are set, but the set of arguments // will change when the set of required properties is changed -func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} {{classname}}{{name}}ArgType{{^-last}}, {{/-last}}{{/requiredVars}}) *{{classname}} { +func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} {{classname}}{{getter}}ArgType{{^-last}}, {{/-last}}{{/requiredVars}}) *{{classname}} { this := {{classname}}{} {{#allVars}} {{#required}} - set{{classname}}{{name}}AttributeType(&this.{{name}}, {{nameInCamelCase}}) + set{{classname}}{{getter}}AttributeType(&this.{{name}}, {{nameInCamelCase}}) {{/required}} {{/allVars}} return &this @@ -536,7 +566,7 @@ func New{{classname}}WithDefaults() *{{classname}} { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}() (ret {{classname}}{{name}}RetType) { +func (o *{{classname}}) Get{{name}}() (ret {{classname}}{{getter}}RetType) { ret,_ = o.Get{{name}}Ok() return ret } @@ -549,16 +579,16 @@ func (o *{{classname}}) Get{{name}}() (ret {{classname}}{{name}}RetType) { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}Ok() (ret {{classname}}{{name}}RetType, ok bool) { - return get{{classname}}{{name}}AttributeTypeOk(o.{{name}}) +func (o *{{classname}}) Get{{name}}Ok() (ret {{classname}}{{getter}}RetType, ok bool) { + return get{{classname}}{{getter}}AttributeTypeOk(o.{{name}}) } // Set{{name}} sets field value {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}RetType) { - set{{classname}}{{name}}AttributeType(&o.{{name}},v) +func (o *{{classname}}) Set{{name}}(v {{classname}}{{getter}}RetType) { + set{{classname}}{{getter}}AttributeType(&o.{{name}},v) } {{/required}} @@ -567,7 +597,7 @@ func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}RetType) { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}() (res {{classname}}{{name}}RetType) { +func (o *{{classname}}) Get{{name}}() (res {{classname}}{{getter}}RetType) { res,_ = o.Get{{name}}Ok() return } @@ -580,8 +610,8 @@ func (o *{{classname}}) Get{{name}}() (res {{classname}}{{name}}RetType) { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Get{{name}}Ok() (ret {{classname}}{{name}}RetType, ok bool) { - return get{{classname}}{{name}}AttributeTypeOk(o.{{name}}) +func (o *{{classname}}) Get{{name}}Ok() (ret {{classname}}{{getter}}RetType, ok bool) { + return get{{classname}}{{getter}}AttributeTypeOk(o.{{name}}) } // Has{{name}} returns a boolean if a field has been set. @@ -594,8 +624,8 @@ func (o *{{classname}}) Has{{name}}() bool { {{#deprecated}} // Deprecated {{/deprecated}} -func (o *{{classname}}) Set{{name}}(v {{classname}}{{name}}RetType) { - set{{classname}}{{name}}AttributeType(&o.{{name}},v) +func (o *{{classname}}) Set{{name}}(v {{classname}}{{getter}}RetType) { + set{{classname}}{{getter}}AttributeType(&o.{{name}},v) } @@ -649,7 +679,7 @@ func (o {{classname}}) ToMap() (map[string]interface{}, error) { {{#vars}} {{! if argument is nullable, only serialize it if it is set}} {{! if argument is not nullable, don't set it if it is nil}} - if val,ok:=get{{classname}}{{name}}AttributeTypeOk(o.{{name}});ok { + if val,ok:=get{{classname}}{{getter}}AttributeTypeOk(o.{{name}});ok { toSerialize["{{{name}}}"] = val } {{/vars}} From 185530709ee4a0564cba69b780b09510e8eb0b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Wed, 5 Mar 2025 13:16:19 +0100 Subject: [PATCH 12/20] fix: Readd json tags --- templates/go/model_simple.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/go/model_simple.mustache b/templates/go/model_simple.mustache index 4343c69..28709a9 100644 --- a/templates/go/model_simple.mustache +++ b/templates/go/model_simple.mustache @@ -501,7 +501,7 @@ type {{classname}} struct { {{/isWriteOnly}} {{/isReadOnly}} {{/required}} - {{name}} {{classname}}{{getter}}AttributeType + {{name}} {{classname}}{{getter}}AttributeType `json:"{{baseName}}{{#required}}{{#isReadOnly}},omitempty{{/isReadOnly}}{{/required}}{{#required}}{{#isWriteOnly}},omitempty{{/isWriteOnly}}{{/required}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` {{/vars}} {{#isAdditionalPropertiesTrue}} AdditionalProperties map[string]interface{} From da2b53fe4cbb3bcbf4565aaa40f4d0ceeb52ceba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Wed, 5 Mar 2025 14:57:01 +0100 Subject: [PATCH 13/20] chore: remove debug code --- Makefile | 3 --- scripts/generate-sdk/languages/go.sh | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index e59cf35..75ad832 100644 --- a/Makefile +++ b/Makefile @@ -14,9 +14,6 @@ project-tools: download-oas: @$(SCRIPTS_BASE)/download-oas.sh "$(OAS_REPO_NAME)" "$(OAS_REPO)" "$(ALLOW_ALPHA)" "$(API_VERSION)" -download-oas-alpha: - @$(SCRIPTS_BASE)/download-oas.sh "stackit-api-specifications-internal" "git@ssh.dev.azure.com:v3/schwarzit/schwarzit.stackit-public/stackit-api-specifications-internal" "true" "$(API_VERSION)" - generate-sdk: @$(SCRIPTS_BASE)/generate-sdk/generate-sdk.sh "$(GIT_HOST)" "$(GIT_USER_ID)" "$(GIT_REPO_ID)" "$(SDK_REPO_URL)" "$(LANGUAGE)" "$(SDK_BRANCH)" diff --git a/scripts/generate-sdk/languages/go.sh b/scripts/generate-sdk/languages/go.sh index 1483323..10d9528 100644 --- a/scripts/generate-sdk/languages/go.sh +++ b/scripts/generate-sdk/languages/go.sh @@ -158,7 +158,7 @@ generate_go_sdk() { --git-host ${GIT_HOST} \ --git-user-id ${GIT_USER_ID} \ --git-repo-id ${GIT_REPO_ID} \ - --global-property apis,models,modelTests=true,modelDocs=false,apiDocs=false,supportingFiles,debugModels=true \ + --global-property apis,models,modelTests=true,modelDocs=false,apiDocs=false,supportingFiles \ --additional-properties=isGoSubmodule=true,enumClassPrefix=true,$regional_api # Remove unnecessary files rm ${SERVICES_FOLDER}/${service}/.openapi-generator-ignore From 936bf0e75c7a386d90d3c10097712ee5ad4f6290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Wed, 5 Mar 2025 14:57:19 +0100 Subject: [PATCH 14/20] fix: correct testcase generation --- templates/go/api_test.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/go/api_test.mustache b/templates/go/api_test.mustache index 29778ec..3e0c15a 100644 --- a/templates/go/api_test.mustache +++ b/templates/go/api_test.mustache @@ -41,7 +41,7 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) { {{/returnFormat}} {{^returnFormat}} {{#returnType}} - var data {{returnType}} + data := {{{.}}}{} w.Header().Add("Content-Type", "application/json") json.NewEncoder(w).Encode(data) {{/returnType}} From 7c4ba79198d37ac7b3b5043fce9274f571df939e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Fri, 7 Mar 2025 13:26:43 +0100 Subject: [PATCH 15/20] fix: fix return type instantiation in testcase --- templates/go/api_test.mustache | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/go/api_test.mustache b/templates/go/api_test.mustache index 3e0c15a..d96204e 100644 --- a/templates/go/api_test.mustache +++ b/templates/go/api_test.mustache @@ -41,7 +41,12 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) { {{/returnFormat}} {{^returnFormat}} {{#returnType}} + {{#returnTypeIsPrimitive}} + var data {{{.}}} + {{/returnTypeIsPrimitive}} + {{^returnTypeIsPrimitive}} data := {{{.}}}{} + {{/returnTypeIsPrimitive}} w.Header().Add("Content-Type", "application/json") json.NewEncoder(w).Encode(data) {{/returnType}} From 57ec14f40a66f731ce840720514e472f69bcb87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Thu, 13 Mar 2025 09:23:08 +0100 Subject: [PATCH 16/20] fix: correct instantiation of returntype in testcase --- templates/go/api_test.mustache | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/templates/go/api_test.mustache b/templates/go/api_test.mustache index d96204e..cd38b64 100644 --- a/templates/go/api_test.mustache +++ b/templates/go/api_test.mustache @@ -41,12 +41,18 @@ func Test_{{packageName}}_{{classname}}Service(t *testing.T) { {{/returnFormat}} {{^returnFormat}} {{#returnType}} - {{#returnTypeIsPrimitive}} + {{#returnProperty.isPrimitiveType}} + {{! according to the model, freeform objects might be primitive...}} + {{#returnProperty.isFreeFormObject}} + data := {{{.}}}{} + {{/returnProperty.isFreeFormObject}} + {{^returnProperty.isFreeFormObject}} var data {{{.}}} - {{/returnTypeIsPrimitive}} - {{^returnTypeIsPrimitive}} + {{/returnProperty.isFreeFormObject}} + {{/returnProperty.isPrimitiveType}} + {{^returnProperty.isPrimitiveType}} data := {{{.}}}{} - {{/returnTypeIsPrimitive}} + {{/returnProperty.isPrimitiveType}} w.Header().Add("Content-Type", "application/json") json.NewEncoder(w).Encode(data) {{/returnType}} From 47c601cd0d0050ac0ea1ffa91c1c4a1bb20100b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Thu, 13 Mar 2025 11:01:19 +0100 Subject: [PATCH 17/20] feat: provide service-individual, explicit api versions via json file --- Makefile | 4 ++-- api-versions.json | 5 +++++ api_version | 3 --- scripts/download-oas.sh | 25 ++++++++++++++++--------- 4 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 api-versions.json delete mode 100644 api_version diff --git a/Makefile b/Makefile index 75ad832..b5fbca2 100644 --- a/Makefile +++ b/Makefile @@ -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.json SDK_BRANCH ?= main # SETUP AND TOOL INITIALIZATION TASKS @@ -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)" diff --git a/api-versions.json b/api-versions.json new file mode 100644 index 0000000..c63b8b7 --- /dev/null +++ b/api-versions.json @@ -0,0 +1,5 @@ +{ + "load-balancer": "9c9de238a3e650f4bed9b9d9ade151da9a97e1d6", + "service-enablement": "c592757243833f9b506a7d23ec5a80a9b3c984ae", + "certificates": "c592757243833f9b506a7d23ec5a80a9b3c984ae" +} \ No newline at end of file diff --git a/api_version b/api_version deleted file mode 100644 index 76fd610..0000000 --- a/api_version +++ /dev/null @@ -1,3 +0,0 @@ -# 2e3768b7b65237391fc587eddd559451f2b183a6 -# comments are allowed! -main \ No newline at end of file diff --git a/scripts/download-oas.sh b/scripts/download-oas.sh index 8336a1f..883eb02 100755 --- a/scripts/download-oas.sh +++ b/scripts/download-oas.sh @@ -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." @@ -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.json" + OAS_API_VERSIONS="${ROOTDIR}/api-versions.json" fi # Create temp directory to clone OAS repo @@ -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 < /dev/null + git checkout -q $apiVersion + cd - > /dev/null + # Prioritize GA over Beta over Alpha versions # GA priority = 3, Beta priority = 2, Alpha priority = 1 max_version_priority=1 From f283af0c6e1210d5da4b4ee480c5145ad6e1abfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Thu, 13 Mar 2025 11:13:51 +0100 Subject: [PATCH 18/20] fix: switch back to main for service-enablement api --- api-versions.json | 1 - 1 file changed, 1 deletion(-) diff --git a/api-versions.json b/api-versions.json index c63b8b7..083d47a 100644 --- a/api-versions.json +++ b/api-versions.json @@ -1,5 +1,4 @@ { "load-balancer": "9c9de238a3e650f4bed9b9d9ade151da9a97e1d6", - "service-enablement": "c592757243833f9b506a7d23ec5a80a9b3c984ae", "certificates": "c592757243833f9b506a7d23ec5a80a9b3c984ae" } \ No newline at end of file From 8e3e13fd186fbec93dbcadc201ec66b9190b561b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Thu, 13 Mar 2025 11:37:13 +0100 Subject: [PATCH 19/20] fix: handle non-existing version gracefully by falling back to main --- scripts/download-oas.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/download-oas.sh b/scripts/download-oas.sh index 883eb02..2ecb94f 100755 --- a/scripts/download-oas.sh +++ b/scripts/download-oas.sh @@ -20,7 +20,7 @@ fi if [[ -z ${OAS_API_VERSIONS} ]]; then echo "No API version passed, using ${ROOTDIR}/api-versions.json" - OAS_API_VERSIONS="${ROOTDIR}/api-versions.json" + OAS_API_VERSIONS="${ROOT_DIR}/api-versions.json" fi # Create temp directory to clone OAS repo @@ -55,7 +55,7 @@ EOF echo "Using ${apiVersion} for ${service}" fi cd ${work_dir}/${OAS_REPO_NAME} > /dev/null - git checkout -q $apiVersion + 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 From 430dc9b0305d2a583188f60467b2fd901b5d4cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Schmitz?= <152157960+bahkauv70@users.noreply.github.com> Date: Fri, 14 Mar 2025 16:27:35 +0100 Subject: [PATCH 20/20] feat: rename file to api-versions-lock.json to emphasize semantics --- Makefile | 2 +- api-versions.json => api-versions-lock.json | 0 scripts/download-oas.sh | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename api-versions.json => api-versions-lock.json (100%) diff --git a/Makefile b/Makefile index b5fbca2..dd8ad66 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ROOT_DIR ?= $(shell git rev-parse --show-toplevel) SCRIPTS_BASE ?= $(ROOT_DIR)/scripts -API_VERSIONS ?= $(ROOT_DIR)/api-versions.json +API_VERSIONS ?= $(ROOT_DIR)/api-versions-lock.json SDK_BRANCH ?= main # SETUP AND TOOL INITIALIZATION TASKS diff --git a/api-versions.json b/api-versions-lock.json similarity index 100% rename from api-versions.json rename to api-versions-lock.json diff --git a/scripts/download-oas.sh b/scripts/download-oas.sh index 2ecb94f..d0a8b7c 100755 --- a/scripts/download-oas.sh +++ b/scripts/download-oas.sh @@ -19,8 +19,8 @@ if [[ ! ${OAS_REPO} || -d ${OAS_REPO} ]]; then fi if [[ -z ${OAS_API_VERSIONS} ]]; then - echo "No API version passed, using ${ROOTDIR}/api-versions.json" - OAS_API_VERSIONS="${ROOT_DIR}/api-versions.json" + 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