diff --git a/languages/golang/compat-layer/.openapi-generator-ignore b/languages/golang/compat-layer/.openapi-generator-ignore deleted file mode 100644 index 550ec0fa..00000000 --- a/languages/golang/compat-layer/.openapi-generator-ignore +++ /dev/null @@ -1,14 +0,0 @@ -git_push.sh -.travis.yml -.gitignore -README.md -response.go -api/openapi.yaml -.openapi-generator/* -.gitlab-ci.yml -setup.cfg -setup.py -test-requirements.txt -requirements.txt -tox.ini -*/.github/* diff --git a/languages/golang/compat-layer/allow-list.txt b/languages/golang/compat-layer/allow-list.txt deleted file mode 100644 index e84a43f8..00000000 --- a/languages/golang/compat-layer/allow-list.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Transitional file to enable compatibility layer generation for selected services. -# Note: It shouldn't be needed to add any services here! -alb -auditlog -authorization -cdn -certificates -consumption -dns -edge -git -iaas -intake -kms -loadbalancer -logme -logs -mariadb -modelserving -mongodbflex -objectstorage -observability -opensearch -postgresflex -rabbitmq -redis -resourcemanager -runcommand -scf -secretsmanager -serverbackup -serverupdate -serviceaccount -serviceenablement -sfs -ske -sqlserverflex diff --git a/languages/golang/compat-layer/openapi-generator-config.yml b/languages/golang/compat-layer/openapi-generator-config.yml deleted file mode 100644 index 1942baab..00000000 --- a/languages/golang/compat-layer/openapi-generator-config.yml +++ /dev/null @@ -1,8 +0,0 @@ -useOneOfDiscriminatorLookup: true -templateDir: languages/golang/compat-layer/templates -files: - custom/model_test.mustache: - # TODO: this should be 'ModelTests' instead of 'Model' - # 'Model' was used because 'ModelTests' didn't stick to golangs file naming conventions - templateType: Model - destinationFilename: _test.go diff --git a/languages/golang/compat-layer/regional-allowlist.txt b/languages/golang/compat-layer/regional-allowlist.txt deleted file mode 100644 index 0339a2f7..00000000 --- a/languages/golang/compat-layer/regional-allowlist.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Transitional file to force generation of the new regional api for selected services -# It will be removed when all services have been migrated to the new regional api -objectstorage -sqlserverflex -postgresflex -serviceenablement -loadbalancer -alb -cdn -serverbackup -serverupdate -certificates -kms - diff --git a/languages/golang/compat-layer/templates/README.mustache b/languages/golang/compat-layer/templates/README.mustache deleted file mode 100644 index 05d6fda2..00000000 --- a/languages/golang/compat-layer/templates/README.mustache +++ /dev/null @@ -1,223 +0,0 @@ -# Go API client for {{packageName}} - -{{#appDescriptionWithNewLines}} -{{{.}}} -{{/appDescriptionWithNewLines}} - -## Overview -This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. - -- API version: {{appVersion}} -- Package version: {{packageVersion}} -{{^hideGenerationTimestamp}} -- Build date: {{generatedDate}} -{{/hideGenerationTimestamp}} -- Build package: {{generatorClass}} -{{#infoUrl}} -For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) -{{/infoUrl}} - -## Installation - -Install the following dependencies: - -```shell -go get github.com/stretchr/testify/assert -{{#hasOAuthMethods}} -go get golang.org/x/oauth2 -{{/hasOAuthMethods}} -go get golang.org/x/net/context -``` - -Put the package under your project folder and add the following in import: - -```golang -import {{packageName}} "{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/services{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}}" -``` - -To use a proxy, set the environment variable `HTTP_PROXY`: - -```golang -os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port") -``` - -## Configuration of Server URL - -Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. - -### Select Server Configuration - -For using other server than the one defined on index 0 set context value `sw.ContextServerIndex` of type `int`. - -```golang -ctx := context.WithValue(context.Background(), {{packageName}}.ContextServerIndex, 1) -``` - -### Templated Server URL - -Templated server URL is formatted using default variables from configuration or from context value `sw.ContextServerVariables` of type `map[string]string`. - -```golang -ctx := context.WithValue(context.Background(), {{packageName}}.ContextServerVariables, map[string]string{ - "basePath": "v2", -}) -``` - -Note, enum values are always validated and all unused variables are silently ignored. - -### URLs Configuration per Operation - -Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. -An operation is uniquely identified by `"{classname}Service.{nickname}"` string. -Similar rules for overriding default operation server index and variables applies by using `sw.ContextOperationServerIndices` and `sw.ContextOperationServerVariables` context maps. - -```golang -ctx := context.WithValue(context.Background(), {{packageName}}.ContextOperationServerIndices, map[string]int{ - "{classname}Service.{nickname}": 2, -}) -ctx = context.WithValue(context.Background(), {{packageName}}.ContextOperationServerVariables, map[string]map[string]string{ - "{classname}Service.{nickname}": { - "port": "8443", - }, -}) -``` - -## Documentation for API Endpoints - -All URIs are relative to *{{basePath}}* - -Class | Method | HTTP request | Description ------------- | ------------- | ------------- | ------------- -{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{summary}} -{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} - -## Documentation For Models - -{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md) -{{/model}}{{/models}} - -## Documentation For Authorization - -{{^authMethods}} Endpoints do not require authorization. -{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}} -{{#authMethods}} - -### {{{name}}} - -{{#isApiKey}} -- **Type**: API key -- **API key parameter name**: {{{keyParamName}}} -- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} - -Note, each API key must be added to a map of `map[string]APIKey` where the key is: {{keyParamName}} and passed in as the auth context for each request. - -{{/isApiKey}} -{{#isBasic}} -{{#isBasicBearer}} -- **Type**: HTTP Bearer token authentication - -Example - -```golang -auth := context.WithValue(context.Background(), sw.ContextAccessToken, "BEARER_TOKEN_STRING") -r, err := client.Service.Operation(auth, args) -``` - -{{/isBasicBearer}} -{{#isBasicBasic}} -- **Type**: HTTP basic authentication - -Example - -```golang -auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{ - UserName: "username", - Password: "password", -}) -r, err := client.Service.Operation(auth, args) -``` - -{{/isBasicBasic}} -{{#isHttpSignature}} -- **Type**: HTTP signature authentication - -Example - -```golang - authConfig := client.HttpSignatureAuth{ - KeyId: "my-key-id", - PrivateKeyPath: "rsa.pem", - Passphrase: "my-passphrase", - SigningScheme: sw.HttpSigningSchemeHs2019, - SignedHeaders: []string{ - sw.HttpSignatureParameterRequestTarget, // The special (request-target) parameter expresses the HTTP request target. - sw.HttpSignatureParameterCreated, // Time when request was signed, formatted as a Unix timestamp integer value. - "Host", // The Host request header specifies the domain name of the server, and optionally the TCP port number. - "Date", // The date and time at which the message was originated. - "Content-Type", // The Media type of the body of the request. - "Digest", // A cryptographic digest of the request body. - }, - SigningAlgorithm: sw.HttpSigningAlgorithmRsaPSS, - SignatureMaxValidity: 5 * time.Minute, - } - var authCtx context.Context - var err error - if authCtx, err = authConfig.ContextWithValue(context.Background()); err != nil { - // Process error - } - r, err = client.Service.Operation(auth, args) - -``` -{{/isHttpSignature}} -{{/isBasic}} -{{#isOAuth}} - -- **Type**: OAuth -- **Flow**: {{{flow}}} -- **Authorization URL**: {{{authorizationUrl}}} -- **Scopes**: {{^scopes}}N/A{{/scopes}} -{{#scopes}} - **{{{scope}}}**: {{{description}}} -{{/scopes}} - -Example - -```golang -auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING") -r, err := client.Service.Operation(auth, args) -``` - -Or via OAuth2 module to automatically refresh tokens and perform user authentication. - -```golang -import "golang.org/x/oauth2" - -/* Perform OAuth2 round trip request and obtain a token */ - -tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) -auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource) -r, err := client.Service.Operation(auth, args) -``` - -{{/isOAuth}} -{{/authMethods}} - -## Documentation for Utility Methods - -Due to the fact that model structure members are all pointers, this package contains -a number of utility functions to easily obtain pointers to values of basic types. -Each of these functions takes a value of the given basic type and returns a pointer to it: - -* `PtrBool` -* `PtrInt` -* `PtrInt32` -* `PtrInt64` -* `PtrFloat` -* `PtrFloat32` -* `PtrFloat64` -* `PtrString` -* `PtrTime` - -## Author - -{{#apiInfo}}{{#apis}}{{#-last}}{{infoEmail}} -{{/-last}}{{/apis}}{{/apiInfo}} diff --git a/languages/golang/compat-layer/templates/api.mustache b/languages/golang/compat-layer/templates/api.mustache deleted file mode 100644 index e2740981..00000000 --- a/languages/golang/compat-layer/templates/api.mustache +++ /dev/null @@ -1,448 +0,0 @@ -{{>partial_header}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -package {{packageName}} - -{{#operations}} -import ( - "bytes" - "context" - "io" - "net/http" - "net/url" - "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/core/oapierror" -{{#imports}} "{{import}}" -{{/imports}} -) - -{{#generateInterfaces}} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}} interface { - {{#operation}} - /* -{{operationId}} {{{summary}}}{{^summary}}Method for {{operationId}}{{/summary}} -{{#notes}} -{{#isDeprecated}}Deprecated: {{/isDeprecated}}{{{unescapedNotes}}} -{{/notes}} - -@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{{#pathParams}} -@param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}} -@return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - */ - {{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request - /* -{{nickname}}Execute executes the request{{#returnType}} - -@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{{#pathParams}} -@param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}} -@return {{{.}}}{{/returnType}} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - */ - {{nickname}}Execute(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}{{^isResponseFile}}*{{/isResponseFile}}{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}} error) - {{/operation}} -} - -{{#operation}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request interface { -{{#allParams}} -{{^isPathParam}} -{{#description}} -// {{.}} -{{/description}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -{{vendorExtensions.x-export-param-name}}({{paramName}} {{{dataType}}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request -{{/isPathParam}} -{{/allParams}} - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - Execute() ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}{{^isResponseFile}}*{{/isResponseFile}}{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}} error) -} - -{{/operation}} -{{/generateInterfaces}} - -// {{classname}}Service {{classname}} service -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}Service service -{{#operation}} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request struct { - ctx context.Context - apiService *{{classname}}Service -{{#allParams}} - {{paramName}} {{^isPathParam}}{{^isFile}}*{{/isFile}}{{/isPathParam}}{{{dataType}}} -{{/allParams}} -} - -{{#allParams}} -{{^isPathParam}} -{{#description}} -// {{.}} -{{/description}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request) {{vendorExtensions.x-export-param-name}}({{paramName}} {{{dataType}}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request { - r.{{paramName}} = {{^isFile}}&{{/isFile}}{{paramName}} - return r -} - -{{/isPathParam}} -{{/allParams}} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request) Execute() ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}{{^isResponseFile}}*{{/isResponseFile}}{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}} error) { - var ( - localVarHTTPMethod = http.Method{{httpMethod}} - localVarPostBody interface{} - formFiles []formFile - {{#returnType}} - localVarReturnValue {{^isArray}}{{^returnTypeIsPrimitive}}{{^isResponseFile}}*{{/isResponseFile}}{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}} - {{/returnType}} - ) - a := r.apiService - client, ok := a.client.(*APIClient) - if !ok { - return {{#returnType}}localVarReturnValue, {{/returnType}} fmt.Errorf("could not parse client to type APIClient") - } - localBasePath, err := client.cfg.ServerURLWithContext(r.ctx, "{{{classname}}}Service.{{{nickname}}}") - if err != nil { - return {{#returnType}}localVarReturnValue, {{/returnType}} &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} - } - - localVarPath := localBasePath + "{{{path}}}"{{#pathParams}} - localVarPath = strings.Replace(localVarPath, "{"+"{{baseName}}"+"}", url.PathEscape(ParameterValueToString(r.{{paramName}}, "{{paramName}}")), -1){{/pathParams}} - - localVarHeaderParams := make(map[string]string) - localVarQueryParams := url.Values{} - localVarFormParams := url.Values{} - {{#allParams}} - {{#required}} - {{^isPathParam}} - if r.{{paramName}} == nil { - return {{#returnType}}localVarReturnValue, {{/returnType}} fmt.Errorf("{{paramName}} is required and must be specified") - } - {{/isPathParam}} - {{#minItems}} - if len({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) < {{minItems}} { - return {{#returnType}}localVarReturnValue, {{/returnType}} fmt.Errorf("{{paramName}} must have at least {{minItems}} elements") - } - {{/minItems}} - {{#maxItems}} - if len({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) > {{maxItems}} { - return {{#returnType}}localVarReturnValue, {{/returnType}} fmt.Errorf("{{paramName}} must have less than {{maxItems}} elements") - } - {{/maxItems}} - {{#minLength}} - if strlen({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) < {{minLength}} { - return {{#returnType}}localVarReturnValue, {{/returnType}} fmt.Errorf("{{paramName}} must have at least {{minLength}} elements") - } - {{/minLength}} - {{#maxLength}} - if strlen({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) > {{maxLength}} { - return {{#returnType}}localVarReturnValue, {{/returnType}} fmt.Errorf("{{paramName}} must have less than {{maxLength}} elements") - } - {{/maxLength}} - {{#minimum}} - {{#isString}} - {{paramName}}Txt, err := atoi({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) - if {{paramName}}Txt < {{minimum}} { - {{/isString}} - {{^isString}} - if {{^isPathParam}}*{{/isPathParam}}r.{{paramName}} < {{minimum}} { - {{/isString}} - return {{#returnType}}localVarReturnValue, {{/returnType}} fmt.Errorf("{{paramName}} must be greater than {{minimum}}") - } - {{/minimum}} - {{#maximum}} - {{#isString}} - {{paramName}}Txt, err := atoi({{^isPathParam}}*{{/isPathParam}}r.{{paramName}}) - if {{paramName}}Txt > {{maximum}} { - {{/isString}} - {{^isString}} - if {{^isPathParam}}*{{/isPathParam}}r.{{paramName}} > {{maximum}} { - {{/isString}} - return {{#returnType}}localVarReturnValue, {{/returnType}} fmt.Errorf("{{paramName}} must be less than {{maximum}}") - } - {{/maximum}} - {{/required}} - {{/allParams}} - - {{#queryParams}} - {{#required}} - {{#isCollectionFormatMulti}} - { - t := *r.{{paramName}} - if reflect.TypeOf(t).Kind() == reflect.Slice { - s := reflect.ValueOf(t) - for i := 0; i < s.Len(); i++ { - parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", s.Index(i).Interface(), "{{collectionFormat}}") - } - } else { - parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", t, "{{collectionFormat}}") - } - } - {{/isCollectionFormatMulti}} - {{^isCollectionFormatMulti}} - parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") - {{/isCollectionFormatMulti}} - {{/required}} - {{^required}} - if r.{{paramName}} != nil { - {{#isCollectionFormatMulti}} - t := *r.{{paramName}} - if reflect.TypeOf(t).Kind() == reflect.Slice { - s := reflect.ValueOf(t) - for i := 0; i < s.Len(); i++ { - parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", s.Index(i).Interface(), "{{collectionFormat}}") - } - } else { - parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", t, "{{collectionFormat}}") - } - {{/isCollectionFormatMulti}} - {{^isCollectionFormatMulti}} - parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") - {{/isCollectionFormatMulti}} - } - {{/required}} - {{/queryParams}} - // to determine the Content-Type header - {{=<% %>=}} - localVarHTTPContentTypes := []string{<%#consumes%>"<%&mediaType%>"<%^-last%>, <%/-last%><%/consumes%>} - <%={{ }}=%> - - // set Content-Type header - localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) - if localVarHTTPContentType != "" { - localVarHeaderParams["Content-Type"] = localVarHTTPContentType - } - - // to determine the Accept header - {{=<% %>=}} - localVarHTTPHeaderAccepts := []string{<%#produces%>"<%&mediaType%>"<%^-last%>, <%/-last%><%/produces%>} - <%={{ }}=%> - - // set Accept header - localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) - if localVarHTTPHeaderAccept != "" { - localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept - } - {{#headerParams}} - {{#required}} - parameterAddToHeaderOrQuery(localVarHeaderParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") - {{/required}} - {{^required}} - if r.{{paramName}} != nil { - parameterAddToHeaderOrQuery(localVarHeaderParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") - } - {{/required}} - {{/headerParams}} - {{#formParams}} - {{#isFile}} - var {{paramName}}LocalVarFormFileName string - var {{paramName}}LocalVarFileName string - var {{paramName}}LocalVarFileBytes []byte - - {{paramName}}LocalVarFormFileName = "{{baseName}}" - - - {{paramName}}LocalVarFile := r.{{paramName}} - - if {{paramName}}LocalVarFile != nil { - fbs, _ := io.ReadAll({{paramName}}LocalVarFile) - - {{paramName}}LocalVarFileBytes = fbs - {{paramName}}LocalVarFileName = {{paramName}}LocalVarFile.Name() - {{paramName}}LocalVarFile.Close() - formFiles = append(formFiles, formFile{fileBytes: {{paramName}}LocalVarFileBytes, fileName: {{paramName}}LocalVarFileName, formFileName: {{paramName}}LocalVarFormFileName}) - } - {{/isFile}} - {{^isFile}} - {{#required}} - parameterAddToHeaderOrQuery(localVarFormParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") - {{/required}} - {{^required}} - {{#isModel}} - if r.{{paramName}} != nil { - paramJson, err := parameterToJson(*r.{{paramName}}) - if err != nil { - return {{#returnType}}localVarReturnValue, {{/returnType}}nil, err - } - localVarFormParams.Add("{{baseName}}", paramJson) - } - {{/isModel}} - {{^isModel}} - if r.{{paramName}} != nil { - parameterAddToHeaderOrQuery(localVarFormParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") - } - {{/isModel}} - {{/required}} - {{/isFile}} - {{/formParams}} - {{#bodyParams}} - // body params - localVarPostBody = r.{{paramName}} - {{/bodyParams}} - {{#authMethods}} - {{#isApiKey}} - {{^isKeyInCookie}} - if r.ctx != nil { - // API Key Authentication - if auth, ok := r.ctx.Value(config.ContextAPIKeys).(map[string]config.APIKey); ok { - {{#vendorExtensions.x-auth-id-alias}} - if apiKey, ok := auth["{{.}}"]; ok { - var key string - if prefix, ok := auth["{{name}}"]; ok && prefix.Prefix != "" { - key = prefix.Prefix + " " + apiKey.Key - } else { - key = apiKey.Key - } - {{/vendorExtensions.x-auth-id-alias}} - {{^vendorExtensions.x-auth-id-alias}} - if apiKey, ok := auth["{{name}}"]; ok { - var key string - if apiKey.Prefix != "" { - key = apiKey.Prefix + " " + apiKey.Key - } else { - key = apiKey.Key - } - {{/vendorExtensions.x-auth-id-alias}} - {{#isKeyInHeader}} - localVarHeaderParams["{{keyParamName}}"] = key - {{/isKeyInHeader}} - {{#isKeyInQuery}} - localVarQueryParams.Add("{{keyParamName}}", key) - {{/isKeyInQuery}} - } - } - } - {{/isKeyInCookie}} - {{/isApiKey}} - {{/authMethods}} - req, err := client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) - if err != nil { - return {{#returnType}}localVarReturnValue, {{/returnType}} err - } - - contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) - if ok { - *contextHTTPRequest = req - } - - localVarHTTPResponse, err := client.callAPI(req) - contextHTTPResponse, ok := r.ctx.Value(config.ContextHTTPResponse).(**http.Response) - if ok { - *contextHTTPResponse = localVarHTTPResponse - } - if err != nil || localVarHTTPResponse == nil { - return {{#returnType}}localVarReturnValue, {{/returnType}} err - } - - localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) - localVarHTTPResponse.Body.Close() - localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) - if err != nil { - return {{#returnType}}localVarReturnValue, {{/returnType}} err - } - - if localVarHTTPResponse.StatusCode >= 300 { - newErr := &oapierror.GenericOpenAPIError{ - StatusCode: localVarHTTPResponse.StatusCode, - Body: localVarBody, - ErrorMessage: localVarHTTPResponse.Status, - } - {{#responses}} - {{#dataType}} - {{^is1xx}} - {{^is2xx}} - {{#range}} - {{#is3xx}} - if localVarHTTPResponse.StatusCode >= 300 && localVarHTTPResponse.StatusCode < 400 { - {{/is3xx}} - {{#is4xx}} - if localVarHTTPResponse.StatusCode >= 400 && localVarHTTPResponse.StatusCode < 500 { - {{/is4xx}} - {{#is5xx}} - if localVarHTTPResponse.StatusCode >= 500 { - {{/is5xx}} - {{/range}} - {{^range}} - {{^wildcard}} - if localVarHTTPResponse.StatusCode == {{{code}}} { - {{/wildcard}} - {{/range}} - var v {{{dataType}}} - err = client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr.ErrorMessage = err.Error() - return {{#returnType}}localVarReturnValue, {{/returnType}} newErr - } - newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) - newErr.Model = v - {{^-last}} - return {{#returnType}}localVarReturnValue, {{/returnType}} newErr - {{/-last}} - {{^wildcard}} - } - {{/wildcard}} - {{/is2xx}} - {{/is1xx}} - {{/dataType}} - {{/responses}} - return {{#returnType}}localVarReturnValue, {{/returnType}} newErr - } - - {{#returnType}} - err = client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr := &oapierror.GenericOpenAPIError{ - StatusCode: localVarHTTPResponse.StatusCode, - Body: localVarBody, - ErrorMessage: err.Error(), - } - return {{#returnType}}localVarReturnValue, {{/returnType}} newErr - } - - {{/returnType}} - return {{#returnType}}localVarReturnValue, {{/returnType}} nil -} - -/* -{{operationId}}: {{{summary}}}{{^summary}}Method for {{operationId}}{{/summary}} -{{#notes}} - -{{/notes}} -Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - - @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{{#pathParams}} - @param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}} - @return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request -*/ -func (a *APIClient) {{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request { - return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request{ - apiService: a.defaultApi, - ctx: ctx, - {{#pathParams}} - {{paramName}}: {{paramName}}, - {{/pathParams}} - } -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (a *APIClient) {{{nickname}}}Execute(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}{{^isResponseFile}}*{{/isResponseFile}}{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}} error){ - r := {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request{ - apiService: a.defaultApi, - ctx: ctx, - {{#pathParams}} - {{paramName}}: {{paramName}}, - {{/pathParams}} - } - return r.Execute() -} - - -{{/operation}} -{{/operations}} diff --git a/languages/golang/compat-layer/templates/api_doc.mustache b/languages/golang/compat-layer/templates/api_doc.mustache deleted file mode 100644 index bc9de89f..00000000 --- a/languages/golang/compat-layer/templates/api_doc.mustache +++ /dev/null @@ -1,92 +0,0 @@ -# {{invokerPackage}}\{{classname}}{{#description}} - -{{.}}{{/description}} - -All URIs are relative to *{{basePath}}* - -Method | HTTP request | Description -------------- | ------------- | ------------- -{{#operations}}{{#operation}}[**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{summary}} -{{/operation}}{{/operations}} - -{{#operations}} -{{#operation}} - -## {{{operationId}}} - -> {{#returnType}}{{{.}}} {{/returnType}}{{{operationId}}}(ctx{{#pathParams}}, {{paramName}}{{/pathParams}}){{#allParams}}{{^isPathParam}}.{{vendorExtensions.x-export-param-name}}({{paramName}}){{/isPathParam}}{{/allParams}}.Execute() - -{{{summary}}}{{#notes}} - -{{{unespacedNotes}}}{{/notes}} - -### Example - -```go -package main - -import ( - "context" - "fmt" - "os" -{{#vendorExtensions.x-go-import}} -{{{vendorExtensions.x-go-import}}} -{{/vendorExtensions.x-go-import}} - {{goImportAlias}} "{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/services{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}}" -) - -func main() { - {{#allParams}} - {{paramName}} := {{{vendorExtensions.x-go-example}}} // {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} - {{/allParams}} - - configuration := {{goImportAlias}}.NewConfiguration() - apiClient := {{goImportAlias}}.NewAPIClient(configuration) - {{#returnType}}resp, {{/returnType}}r, err := apiClient.{{classname}}.{{operationId}}(context.Background(){{#pathParams}}, {{paramName}}{{/pathParams}}){{#allParams}}{{^isPathParam}}.{{vendorExtensions.x-export-param-name}}({{paramName}}){{/isPathParam}}{{/allParams}}.Execute() - if err != nil { - fmt.Fprintf(os.Stderr, "Error when calling `{{classname}}.{{operationId}}``: %v\n", err) - fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) - } - {{#returnType}} - // response from `{{operationId}}`: {{{.}}} - fmt.Fprintf(os.Stdout, "Response from `{{classname}}.{{operationId}}`: %v\n", resp) - {{/returnType}} -} -``` - -### Path Parameters - -{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#pathParams}}{{#-last}} -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- -**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc.{{/-last}}{{/pathParams}}{{#pathParams}} -**{{paramName}}** | {{^isPrimitiveType}}{{^isFile}}[{{/isFile}}{{/isPrimitiveType}}**{{dataType}}**{{^isPrimitiveType}}{{^isFile}}]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}} | {{description}} | {{#defaultValue}}[default to {{.}}]{{/defaultValue}}{{/pathParams}} - -### Other Parameters - -Other parameters are passed through a pointer to a api{{{nickname}}}Request struct via the builder pattern -{{#allParams}}{{#-last}} - -Name | Type | Description | Notes -------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}{{#allParams}} -{{^isPathParam}} **{{paramName}}** | {{#isContainer}}{{#isArray}}{{#items}}{{^isPrimitiveType}}{{^isFile}}[{{/isFile}}{{/isPrimitiveType}}**[]{{dataType}}**{{^isPrimitiveType}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isFile}}{{/isPrimitiveType}}{{/items}}{{/isArray}}{{#isMap}}{{#items}}{{^isPrimitiveType}}{{^isFile}}[{{/isFile}}{{/isPrimitiveType}}**map[string]{{dataType}}**{{^isPrimitiveType}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isFile}}{{/isPrimitiveType}}{{/items}}{{/isMap}}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}{{^isFile}}[{{/isFile}}{{/isPrimitiveType}}**{{dataType}}**{{^isPrimitiveType}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isFile}}{{/isPrimitiveType}}{{/isContainer}} | {{description}} | {{#defaultValue}}[default to {{.}}]{{/defaultValue}}{{/isPathParam}}{{/allParams}} - -### Return type - -{{#returnType}}{{#returnTypeIsPrimitive}}**{{{returnType}}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{{returnType}}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}} (empty response body){{/returnType}} - -### Authorization - -{{^authMethods}}No authorization required{{/authMethods}}{{#authMethods}}[{{{name}}}](../README.md#{{{name}}}){{^-last}}, {{/-last}}{{/authMethods}} - -### HTTP request headers - -- **Content-Type**: {{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}{{^consumes}}Not defined{{/consumes}} -- **Accept**: {{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}{{^produces}}Not defined{{/produces}} - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) -[[Back to Model list]](../README.md#documentation-for-models) -[[Back to README]](../README.md) - -{{/operation}} -{{/operations}} diff --git a/languages/golang/compat-layer/templates/client.mustache b/languages/golang/compat-layer/templates/client.mustache deleted file mode 100644 index 66040cc3..00000000 --- a/languages/golang/compat-layer/templates/client.mustache +++ /dev/null @@ -1,680 +0,0 @@ -{{>partial_header}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -package {{packageName}} - -import ( - "bytes" - "context" - "encoding/json" - "encoding/xml" - "fmt" - "io" - "log" - "mime/multipart" - "net/http" - "net/http/httputil" - "net/url" - "os" - "path/filepath" - "reflect" - "regexp" - "strconv" - "strings" - "time" - "unicode/utf8" - "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/core/auth" - - {{#hasOAuthMethods}} - "golang.org/x/oauth2" - {{/hasOAuthMethods}} -) - -var ( - jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) - xmlCheck = regexp.MustCompile(`(?i:(?:application|text)/xml)`) - queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) - queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) -) - -// APIClient manages communication with the {{appName}} API v{{version}} -// In most cases there should be only one, shared, APIClient. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type APIClient struct { - cfg *config.Configuration - common service // Reuse a single struct instead of allocating one for each service on the heap. - defaultApi *DefaultApiService -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type service struct { - client DefaultApi -} - -// NewAPIClient creates a new API client. -// Optionally receives configuration options -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewAPIClient(opts ...config.ConfigurationOption) (*APIClient, error) { - cfg := NewConfiguration() - - for _, option := range opts { - err := option(cfg) - if err != nil { - return nil, fmt.Errorf("configuring the client: %w", err) - } - } - - {{#regional_api}} - // using new regional api, so no region is set here - {{/regional_api}} - {{^regional_api}} - err := config.ConfigureRegion(cfg) - if err != nil { - return nil, fmt.Errorf("configuring region: %w", err) - } - {{/regional_api}} - - if cfg.HTTPClient == nil { - cfg.HTTPClient = &http.Client{} - } - - authRoundTripper, err := auth.SetupAuth(cfg) - if err != nil { - return nil, fmt.Errorf("setting up authentication: %w", err) - } - - roundTripper := authRoundTripper - if cfg.Middleware != nil { - roundTripper = config.ChainMiddleware(roundTripper, cfg.Middleware...) - } - - cfg.HTTPClient.Transport = roundTripper - - c := &APIClient{} - c.cfg = cfg - c.common.client = c - c.defaultApi = (*DefaultApiService)(&c.common) - - return c, nil -} - -func atoi(in string) (int, error) { - return strconv.Atoi(in) -} - -// selectHeaderContentType select a content type from the available list. -func selectHeaderContentType(contentTypes []string) string { - if len(contentTypes) == 0 { - return "" - } - if contains(contentTypes, "application/json") { - return "application/json" - } - return contentTypes[0] // use the first content type specified in 'consumes' -} - -// selectHeaderAccept join all accept types and return -func selectHeaderAccept(accepts []string) string { - if len(accepts) == 0 { - return "" - } - - if contains(accepts, "application/json") { - return "application/json" - } - - return strings.Join(accepts, ",") -} - -// contains is a case insensitive match, finding needle in a haystack -func contains(haystack []string, needle string) bool { - for _, a := range haystack { - if strings.EqualFold(a, needle) { - return true - } - } - return false -} - -// Verify optional parameters are of the correct type. -func typeCheckParameter(obj interface{}, expected string, name string) error { - // Make sure there is an object. - if obj == nil { - return nil - } - - // Check the type is as expected. - if reflect.TypeOf(obj).String() != expected { - return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) - } - return nil -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func ParameterValueToString( obj interface{}, key string ) string { - if reflect.TypeOf(obj).Kind() != reflect.Ptr { - return fmt.Sprintf("%v", obj) - } - var param,ok = obj.(MappedNullable) - if !ok { - return "" - } - dataMap,err := param.ToMap() - if err != nil { - return "" - } - return fmt.Sprintf("%v", dataMap[key]) -} - -// parameterAddToHeaderOrQuery adds the provided object to the request header or url query -// supporting deep object syntax -func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { - var v = reflect.ValueOf(obj) - var value = "" - if v == reflect.ValueOf(nil) { - value = "null" - } else { - switch v.Kind() { - case reflect.Invalid: - value = "invalid" - - case reflect.Struct: - if t,ok := obj.(MappedNullable); ok { - dataMap,err := t.ToMap() - if err != nil { - return - } - parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) - return - } - if t, ok := obj.(time.Time); ok { - parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) - return - } - value = v.Type().String() + " value" - case reflect.Slice: - var indValue = reflect.ValueOf(obj) - if indValue == reflect.ValueOf(nil) { - return - } - var lenIndValue = indValue.Len() - for i:=0;i 0 || (len(formFiles) > 0) { - if body != nil { - return nil, fmt.Errorf("cannot specify postBody and multipart form at the same time.") - } - body = &bytes.Buffer{} - w := multipart.NewWriter(body) - - for k, v := range formParams { - for _, iv := range v { - if strings.HasPrefix(k, "@") { // file - err = addFile(w, k[1:], iv) - if err != nil { - return nil, err - } - } else { // form value - w.WriteField(k, iv) - } - } - } - for _, formFile := range formFiles { - if len(formFile.fileBytes) > 0 && formFile.fileName != "" { - w.Boundary() - part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName)) - if err != nil { - return nil, err - } - _, err = part.Write(formFile.fileBytes) - if err != nil { - return nil, err - } - } - } - - // Set the Boundary in the Content-Type - headerParams["Content-Type"] = w.FormDataContentType() - - // Set Content-Length - headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) - w.Close() - } - - if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { - if body != nil { - return nil, fmt.Errorf("cannot specify postBody and x-www-form-urlencoded form at the same time.") - } - body = &bytes.Buffer{} - body.WriteString(formParams.Encode()) - // Set Content-Length - headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) - } - - // Setup path and query parameters - url, err := url.Parse(path) - if err != nil { - return nil, err - } - - // Override request host, if applicable - if c.cfg.Host != "" { - url.Host = c.cfg.Host - } - - // Override request scheme, if applicable - if c.cfg.Scheme != "" { - url.Scheme = c.cfg.Scheme - } - - // Adding Query Param - query := url.Query() - for k, v := range queryParams { - for _, iv := range v { - query.Add(k, iv) - } - } - - // Encode the parameters. - url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string { - pieces := strings.Split(s, "=") - pieces[0] = queryDescape.Replace(pieces[0]) - return strings.Join(pieces, "=") - }) - - // Generate a new request - if body != nil { - localVarRequest, err = http.NewRequest(method, url.String(), body) - } else { - localVarRequest, err = http.NewRequest(method, url.String(), nil) - } - if err != nil { - return nil, err - } - - // add header parameters, if any - if len(headerParams) > 0 { - headers := http.Header{} - for h, v := range headerParams { - headers[h] = []string{v} - } - localVarRequest.Header = headers - } - - // Add the user agent to the request. - localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) - - if ctx != nil { - // add context to the request - localVarRequest = localVarRequest.WithContext(ctx) - - // Walk through any authentication. - - {{#hasOAuthMethods}} - // OAuth2 authentication - if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { - // We were able to grab an oauth2 token from the context - var latestToken *oauth2.Token - if latestToken, err = tok.Token(); err != nil { - return nil, err - } - - latestToken.SetAuthHeader(localVarRequest) - } - - {{/hasOAuthMethods}} - {{#hasHttpBasicMethods}} - // Basic HTTP Authentication - if auth, ok := ctx.Value(ContextBasicAuth).(BasicAuth); ok { - localVarRequest.SetBasicAuth(auth.UserName, auth.Password) - } - - {{/hasHttpBasicMethods}} - {{#hasHttpBearerMethods}} - // AccessToken Authentication - if auth, ok := ctx.Value(config.ContextAccessToken).(string); ok { - localVarRequest.Header.Add("Authorization", "Bearer "+auth) - } - - {{/hasHttpBearerMethods}} - } - - for header, value := range c.cfg.DefaultHeader { - localVarRequest.Header.Add(header, value) - } -{{#withCustomMiddlewareFunction}} - - if c.cfg.Middleware != nil { - c.cfg.Middleware(localVarRequest) - } - -{{/withCustomMiddlewareFunction}} -{{#hasHttpSignatureMethods}} - if ctx != nil { - // HTTP Signature Authentication. All request headers must be set (including default headers) - // because the headers may be included in the signature. - if auth, ok := ctx.Value(ContextHttpSignatureAuth).(HttpSignatureAuth); ok { - err = SignRequest(ctx, localVarRequest, auth) - if err != nil { - return nil, err - } - } - } -{{/hasHttpSignatureMethods}} - return localVarRequest, nil -} - -func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { - if len(b) == 0 { - return nil - } - if s, ok := v.(*string); ok { - *s = string(b) - return nil - } - if f, ok := v.(*os.File); ok { - f, err = os.CreateTemp("", "HttpClientFile") - if err != nil { - return - } - _, err = f.Write(b) - if err != nil { - return - } - _, err = f.Seek(0, io.SeekStart) - return - } - if f, ok := v.(**os.File); ok { - *f, err = os.CreateTemp("", "HttpClientFile") - if err != nil { - return - } - _, err = (*f).Write(b) - if err != nil { - return - } - _, err = (*f).Seek(0, io.SeekStart) - return - } - if xmlCheck.MatchString(contentType) { - if err = xml.Unmarshal(b, v); err != nil { - return err - } - return nil - } - if jsonCheck.MatchString(contentType) { - if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas - if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined - if err = unmarshalObj.UnmarshalJSON(b); err != nil { - return err - } - } else { - return fmt.Errorf("unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") - } - } else if err = json.Unmarshal(b, v); err != nil { // simple model - return err - } - return nil - } - return fmt.Errorf("undefined response type") -} - -// Add a file to the multipart request -func addFile(w *multipart.Writer, fieldName, path string) error { - file, err := os.Open(filepath.Clean(path)) - if err != nil { - return err - } - defer file.Close() - - part, err := w.CreateFormFile(fieldName, filepath.Base(path)) - if err != nil { - return err - } - _, err = io.Copy(part, file) - - return err -} - -// A wrapper for strict JSON decoding -func newStrictDecoder(data []byte) *json.Decoder { - dec := json.NewDecoder(bytes.NewBuffer(data)) - dec.DisallowUnknownFields() - return dec -} - -// Set request body from an interface{} -func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { - if bodyBuf == nil { - bodyBuf = &bytes.Buffer{} - } - - if reader, ok := body.(io.Reader); ok { - _, err = bodyBuf.ReadFrom(reader) - } else if fp, ok := body.(*os.File); ok { - _, err = bodyBuf.ReadFrom(fp) - } else if b, ok := body.([]byte); ok { - _, err = bodyBuf.Write(b) - } else if s, ok := body.(string); ok { - _, err = bodyBuf.WriteString(s) - } else if s, ok := body.(*string); ok { - _, err = bodyBuf.WriteString(*s) - } else if jsonCheck.MatchString(contentType) { - err = json.NewEncoder(bodyBuf).Encode(body) - } else if xmlCheck.MatchString(contentType) { - err = xml.NewEncoder(bodyBuf).Encode(body) - } - - if err != nil { - return nil, err - } - - if bodyBuf.Len() == 0 { - err = fmt.Errorf("invalid body type %s", contentType) - return nil, err - } - return bodyBuf, nil -} - -// detectContentType method is used to figure out `Request.Body` content type for request header -func detectContentType(body interface{}) string { - contentType := "text/plain; charset=utf-8" - kind := reflect.TypeOf(body).Kind() - - switch kind { - case reflect.Struct, reflect.Map, reflect.Ptr: - contentType = "application/json; charset=utf-8" - case reflect.String: - contentType = "text/plain; charset=utf-8" - default: - if b, ok := body.([]byte); ok { - contentType = http.DetectContentType(b) - } else if kind == reflect.Slice { - contentType = "application/json; charset=utf-8" - } - } - - return contentType -} - -// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go -type cacheControl map[string]string - -func parseCacheControl(headers http.Header) cacheControl { - cc := cacheControl{} - ccHeader := headers.Get("Cache-Control") - for _, part := range strings.Split(ccHeader, ",") { - part = strings.Trim(part, " ") - if part == "" { - continue - } - if strings.ContainsRune(part, '=') { - keyval := strings.Split(part, "=") - cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") - } else { - cc[part] = "" - } - } - return cc -} - -// CacheExpires helper function to determine remaining time before repeating a request. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func CacheExpires(r *http.Response) time.Time { - // Figure out when the cache expires. - var expires time.Time - now, err := time.Parse(time.RFC1123, r.Header.Get("date")) - if err != nil { - return time.Now() - } - respCacheControl := parseCacheControl(r.Header) - - if maxAge, ok := respCacheControl["max-age"]; ok { - lifetime, err := time.ParseDuration(maxAge + "s") - if err != nil { - expires = now - } else { - expires = now.Add(lifetime) - } - } else { - expiresHeader := r.Header.Get("Expires") - if expiresHeader != "" { - expires, err = time.Parse(time.RFC1123, expiresHeader) - if err != nil { - expires = now - } - } - } - return expires -} - -func strlen(s string) int { - return utf8.RuneCountInString(s) -} diff --git a/languages/golang/compat-layer/templates/configuration.mustache b/languages/golang/compat-layer/templates/configuration.mustache deleted file mode 100644 index 17ff9087..00000000 --- a/languages/golang/compat-layer/templates/configuration.mustache +++ /dev/null @@ -1,94 +0,0 @@ -{{>partial_header}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -package {{packageName}} - -import ( - "github.com/stackitcloud/stackit-sdk-go/core/config" -) - -// NewConfiguration returns a new Configuration object -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewConfiguration() *config.Configuration { - cfg := &config.Configuration{ - DefaultHeader: make(map[string]string), - UserAgent: "{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/go{{/httpUserAgent}}", - Debug: false, - {{#servers}} - {{#-first}} - Servers: config.ServerConfigurations{ - {{/-first}} - { - URL: "{{{url}}}", - Description: "{{{description}}}{{^description}}No description provided{{/description}}", - {{#variables}} - {{#-first}} - Variables: map[string]config.ServerVariable{ - {{/-first}} - "{{{name}}}": { - Description: "{{{description}}}{{^description}}No description provided{{/description}}", - DefaultValue: "{{{defaultValue}}}", - {{#enumValues}} - {{#-first}} - EnumValues: []string{ - {{/-first}} - "{{{.}}}", - {{#-last}} - }, - {{/-last}} - {{/enumValues}} - }, - {{#-last}} - }, - {{/-last}} - {{/variables}} - }, - {{#-last}} - }, - {{/-last}} - {{/servers}} - {{#apiInfo}} - OperationServers: map[string]config.ServerConfigurations{ - {{#apis}} - {{#operations}} - {{#operation}} - {{#servers}} - {{#-first}} - "{{{classname}}}Service.{{{nickname}}}": { - {{/-first}} - { - URL: "{{{url}}}", - Description: "{{{description}}}{{^description}}No description provided{{/description}}", - {{#variables}} - {{#-first}} - Variables: map[string]config.ServerVariable{ - {{/-first}} - "{{{name}}}": config.ServerVariable{ - Description: "{{{description}}}{{^description}}No description provided{{/description}}", - DefaultValue: "{{{defaultValue}}}", - {{#enumValues}} - {{#-first}} - EnumValues: []string{ - {{/-first}} - "{{{.}}}", - {{#-last}} - }, - {{/-last}} - {{/enumValues}} - }, - {{#-last}} - }, - {{/-last}} - {{/variables}} - }, - {{#-last}} - }, - {{/-last}} - {{/servers}} - {{/operation}} - {{/operations}} - {{/apis}} - }, - {{/apiInfo}} - } - return cfg -} diff --git a/languages/golang/compat-layer/templates/custom/helper/array_json_example_value.mustache b/languages/golang/compat-layer/templates/custom/helper/array_json_example_value.mustache deleted file mode 100644 index 00b75f8e..00000000 --- a/languages/golang/compat-layer/templates/custom/helper/array_json_example_value.mustache +++ /dev/null @@ -1 +0,0 @@ -{{#isArray}}[{{#items}}{{#isString}}"example"{{/isString}}{{/items}}]{{/isArray}} \ No newline at end of file diff --git a/languages/golang/compat-layer/templates/custom/helper/container_json_example_value.mustache b/languages/golang/compat-layer/templates/custom/helper/container_json_example_value.mustache deleted file mode 100644 index 4643fa75..00000000 --- a/languages/golang/compat-layer/templates/custom/helper/container_json_example_value.mustache +++ /dev/null @@ -1 +0,0 @@ -{{#isContainer}}{{#isMap}}{"map":{{#items}}{{> custom/helper/array_json_example_value}}{{^isArray}}{{#isString}}"example"{{/isString}}{{/isArray}}{{/items}}}{{/isMap}}{{^isMap}}{{> custom/helper/array_json_example_value}}{{/isMap}}{{/isContainer}} \ No newline at end of file diff --git a/languages/golang/compat-layer/templates/custom/model_oneof_test.mustache b/languages/golang/compat-layer/templates/custom/model_oneof_test.mustache deleted file mode 100644 index cb2b7126..00000000 --- a/languages/golang/compat-layer/templates/custom/model_oneof_test.mustache +++ /dev/null @@ -1,69 +0,0 @@ -{{! NOTE: This is a custom STACKIT template which is not present in upsteam to support testing of oneOf models}} - - -{{! tests only the adjusted cases in the Generator of UnmarshalJSON}} -{{#useOneOfDiscriminatorLookup}} -{{^discriminator}} -// isOneOf - -{{#composedSchemas.oneOf}} -{{#-first}} -func Test{{{classname}}}_UnmarshalJSON(t *testing.T) { - type args struct { - src []byte - } - tests := []struct { - name string - args args - wantErr bool - }{ -{{/-first}} - {{#allowableValues.values}} - { - name: "success - {{dataType}} {{.}}", - args: args{ - src: []byte(`"{{.}}"`), - }, - wantErr: false, - }, - {{/allowableValues.values}} - {{^allowableValues.values}}{{^isModel}}{{^isContainer}} - { - name: "success - {{dataType}} {{{example}}}", - args: args{ - src: []byte(`"{{{example}}}"`), - }, - wantErr: false, - }, - {{/isContainer}}{{#isContainer}} - { - name: "success - {{dataType}}", - args: args{ - src: []byte(`{{>custom/helper/container_json_example_value}}`), - }, - wantErr: false, - }, - {{/isContainer}}{{/isModel}}{{/allowableValues.values}} -{{#-last}} - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - v := &{{{classname}}}{} - if err := v.UnmarshalJSON(tt.args.src); (err != nil) != tt.wantErr { - t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) - } - marshalJson, err := v.MarshalJSON() - if err != nil { - t.Fatalf("failed marshalling {{classname}}: %v", err) - } - if string(marshalJson) != string(tt.args.src) { - t.Fatalf("wanted %s, get %s", tt.args.src, marshalJson) - } - }) - } -} -{{/-last}} -{{/composedSchemas.oneOf}} - -{{/discriminator}} -{{/useOneOfDiscriminatorLookup}} \ No newline at end of file diff --git a/languages/golang/compat-layer/templates/custom/model_simple_test.mustache b/languages/golang/compat-layer/templates/custom/model_simple_test.mustache deleted file mode 100644 index f6bde368..00000000 --- a/languages/golang/compat-layer/templates/custom/model_simple_test.mustache +++ /dev/null @@ -1,49 +0,0 @@ -{{! NOTE: This is a custom STACKIT template which is not present in upsteam to support testing of enum models}} - -{{#vars}} -{{! special handling for enums}} -{{#isEnumRef}} -{{#isEnum}} -// isEnum - -func Test{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}_UnmarshalJSON(t *testing.T) { - type args struct { - src []byte - } - tests := []struct { - name string - args args - wantErr bool - }{ - {{#allowableValues}} - {{#enumVars}} - { - name: `success - possible enum value no. {{-index}}`, - args: args{ - src: []byte(`{{{value}}}`), - }, - wantErr: false, - }, - {{/enumVars}} - {{/allowableValues}} - { - name: "fail", - args: args{ - src: []byte("\"FOOBAR\""), - }, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - v := {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}({{#isNumeric}}-1{{/isNumeric}}{{^isNumeric}}""{{/isNumeric}}) - if err := v.UnmarshalJSON(tt.args.src); (err != nil) != tt.wantErr { - t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -{{/isEnum}} -{{/isEnumRef}} -{{/vars}} \ No newline at end of file diff --git a/languages/golang/compat-layer/templates/custom/model_test.mustache b/languages/golang/compat-layer/templates/custom/model_test.mustache deleted file mode 100644 index 7a4ee372..00000000 --- a/languages/golang/compat-layer/templates/custom/model_test.mustache +++ /dev/null @@ -1,23 +0,0 @@ -{{#models}} - -{{>partial_header}} -package {{packageName}} - -import ( - "testing" -{{#imports}} - "{{import}}" -{{/imports}} -) - -{{#model}} -{{^isEnum}} -{{#oneOf}} -{{#-first}}{{>custom/model_oneof_test}}{{/-first}} -{{/oneOf}} -{{^oneOf}}{{^anyOf}} -{{>custom/model_simple_test}} -{{/anyOf}}{{/oneOf}} -{{/isEnum}} -{{/model}} -{{/models}} diff --git a/languages/golang/compat-layer/templates/git_push.sh.mustache b/languages/golang/compat-layer/templates/git_push.sh.mustache deleted file mode 100644 index 0e3776ae..00000000 --- a/languages/golang/compat-layer/templates/git_push.sh.mustache +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/sh -# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ -# -# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" - -git_user_id=$1 -git_repo_id=$2 -release_note=$3 -git_host=$4 - -if [ "$git_host" = "" ]; then - git_host="{{{gitHost}}}" - echo "[INFO] No command line input provided. Set \$git_host to $git_host" -fi - -if [ "$git_user_id" = "" ]; then - git_user_id="{{{gitUserId}}}" - echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" -fi - -if [ "$git_repo_id" = "" ]; then - git_repo_id="{{{gitRepoId}}}" - echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" -fi - -if [ "$release_note" = "" ]; then - release_note="{{{releaseNote}}}" - echo "[INFO] No command line input provided. Set \$release_note to $release_note" -fi - -# Initialize the local directory as a Git repository -git init - -# Adds the files in the local repository and stages them for commit. -git add . - -# Commits the tracked changes and prepares them to be pushed to a remote repository. -git commit -m "$release_note" - -# Sets the new remote -git_remote=$(git remote) -if [ "$git_remote" = "" ]; then # git remote not defined - - if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." - git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git - else - git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git - fi - -fi - -git pull origin master - -# Pushes (Forces) the changes in the local repository up to the remote repository -echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" -git push origin master 2>&1 | grep -v 'To https' diff --git a/languages/golang/compat-layer/templates/gitignore.mustache b/languages/golang/compat-layer/templates/gitignore.mustache deleted file mode 100644 index daf913b1..00000000 --- a/languages/golang/compat-layer/templates/gitignore.mustache +++ /dev/null @@ -1,24 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof diff --git a/languages/golang/compat-layer/templates/go.mod.mustache b/languages/golang/compat-layer/templates/go.mod.mustache deleted file mode 100644 index 1cfab611..00000000 --- a/languages/golang/compat-layer/templates/go.mod.mustache +++ /dev/null @@ -1,7 +0,0 @@ -module {{gitHost}}/{{gitUserId}}/{{gitRepoId}}/services{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}} - -go 1.21 - -require ( - github.com/stackitcloud/stackit-sdk-go/core v0.27.1 -) diff --git a/languages/golang/compat-layer/templates/go.sum.mustache b/languages/golang/compat-layer/templates/go.sum.mustache deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/golang/compat-layer/templates/model.mustache b/languages/golang/compat-layer/templates/model.mustache deleted file mode 100644 index 4e02b75d..00000000 --- a/languages/golang/compat-layer/templates/model.mustache +++ /dev/null @@ -1,21 +0,0 @@ -{{>partial_header}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -package {{packageName}} - -{{#models}} -import ( - "encoding/json" -{{#imports}} - "{{import}}" -{{/imports}} -) - -{{#model}} -{{#isEnum}} -{{>model_enum}} -{{/isEnum}} -{{^isEnum}} -{{#oneOf}}{{#-first}}{{>model_oneof}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#-first}}{{>model_anyof}}{{/-first}}{{/anyOf}}{{^anyOf}}{{>model_simple}}{{/anyOf}}{{/oneOf}} -{{/isEnum}} -{{/model}} -{{/models}} diff --git a/languages/golang/compat-layer/templates/model_anyof.mustache b/languages/golang/compat-layer/templates/model_anyof.mustache deleted file mode 100644 index 238a9f84..00000000 --- a/languages/golang/compat-layer/templates/model_anyof.mustache +++ /dev/null @@ -1,79 +0,0 @@ -// {{classname}} {{{description}}}{{^description}}struct for {{{classname}}}{{/description}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}} struct { - {{#anyOf}} - {{{.}}} *{{{.}}} - {{/anyOf}} -} - -// Unmarshal JSON data into any of the pointers in the struct -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (dst *{{classname}}) UnmarshalJSON(data []byte) error { - var err error - {{#isNullable}} - // this object is nullable so check if the payload is null or empty string - if string(data) == "" || string(data) == "{}" { - return nil - } - - {{/isNullable}} - {{#discriminator}} - {{#mappedModels}} - {{#-first}} - // use discriminator value to speed up the lookup - var jsonDict map[string]interface{} - err = json.Unmarshal(data, &jsonDict) - if err != nil { - return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup") - } - - {{/-first}} - // check if the discriminator value is '{{{mappingName}}}' - if jsonDict["{{{propertyBaseName}}}"] == "{{{mappingName}}}" { - // try to unmarshal JSON data into {{{modelName}}} - err = json.Unmarshal(data, &dst.{{{modelName}}}); - if err == nil { - json{{{modelName}}}, _ := json.Marshal(dst.{{{modelName}}}) - if string(json{{{modelName}}}) == "{}" { // empty struct - dst.{{{modelName}}} = nil - } else { - return nil // data stored in dst.{{{modelName}}}, return on the first match - } - } else { - dst.{{{modelName}}} = nil - } - } - - {{/mappedModels}} - {{/discriminator}} - {{#anyOf}} - // try to unmarshal JSON data into {{{.}}} - err = json.Unmarshal(data, &dst.{{{.}}}); - if err == nil { - json{{{.}}}, _ := json.Marshal(dst.{{{.}}}) - if string(json{{{.}}}) == "{}" { // empty struct - dst.{{{.}}} = nil - } else { - return nil // data stored in dst.{{{.}}}, return on the first match - } - } else { - dst.{{{.}}} = nil - } - - {{/anyOf}} - return fmt.Errorf("data failed to match schemas in anyOf({{classname}})") -} - -// Marshal data from the first non-nil pointers in the struct to JSON -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (src *{{classname}}) MarshalJSON() ([]byte, error) { -{{#anyOf}} - if src.{{{.}}} != nil { - return json.Marshal(&src.{{{.}}}) - } - -{{/anyOf}} - return nil, nil // no data in anyOf schemas -} - -{{>nullable_model}} diff --git a/languages/golang/compat-layer/templates/model_doc.mustache b/languages/golang/compat-layer/templates/model_doc.mustache deleted file mode 100644 index 439e695b..00000000 --- a/languages/golang/compat-layer/templates/model_doc.mustache +++ /dev/null @@ -1,97 +0,0 @@ -{{#models}}{{#model}}# {{classname}} - -{{^isEnum}} -## Properties - -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -{{#vendorExtensions.x-is-one-of-interface}} -**{{classname}}Interface** | **interface { {{#discriminator}}{{propertyGetter}}() {{propertyType}}{{/discriminator}} }** | An interface that can hold any of the proper implementing types | -{{/vendorExtensions.x-is-one-of-interface}} -{{^vendorExtensions.x-is-one-of-interface}} -{{#vars}}**{{name}}** | {{^required}}Pointer to {{/required}}{{#isContainer}}{{#isArray}}{{#items}}{{^isPrimitiveType}}{{^isFile}}[{{/isFile}}{{/isPrimitiveType}}**[]{{dataType}}**{{^isPrimitiveType}}{{^isFile}}]({{dataType}}.md){{/isFile}}{{/isPrimitiveType}}{{/items}}{{/isArray}}{{#isMap}}{{#items}}{{^isPrimitiveType}}{{^isFile}}[{{/isFile}}{{/isPrimitiveType}}**map[string]{{dataType}}**{{^isPrimitiveType}}{{^isFile}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isFile}}{{/isPrimitiveType}}{{/items}}{{/isMap}}{{/isContainer}}{{^isContainer}}{{^isPrimitiveType}}{{^isFile}}{{^isDateTime}}[{{/isDateTime}}{{/isFile}}{{/isPrimitiveType}}**{{dataType}}**{{^isPrimitiveType}}{{^isFile}}{{^isDateTime}}]({{^baseType}}{{dataType}}{{/baseType}}{{baseType}}.md){{/isDateTime}}{{/isFile}}{{/isPrimitiveType}}{{/isContainer}} | {{description}} | {{^required}}[optional] {{/required}}{{#isReadOnly}}[readonly] {{/isReadOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}} -{{/vars}} -{{/vendorExtensions.x-is-one-of-interface}} - -## Methods - -{{^vendorExtensions.x-is-one-of-interface}} -### New{{classname}} - -`func New{{classname}}({{#vars}}{{#required}}{{nameInCamelCase}} {{dataType}}, {{/required}}{{/vars}}) *{{classname}}` - -New{{classname}} instantiates a new {{classname}} object -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 - -### New{{classname}}WithDefaults - -`func New{{classname}}WithDefaults() *{{classname}}` - -New{{classname}}WithDefaults instantiates a new {{classname}} object -This constructor will only assign default values to properties that have it defined, -but it doesn't guarantee that properties required by API are set - -{{#vars}} -### Get{{name}} - -`func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}}` - -Get{{name}} returns the {{name}} field if non-nil, zero value otherwise. - -### Get{{name}}Ok - -`func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, bool)` - -Get{{name}}Ok returns a tuple with the {{name}} field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### Set{{name}} - -`func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}})` - -Set{{name}} sets {{name}} field to given value. - -{{^required}} -### Has{{name}} - -`func (o *{{classname}}) Has{{name}}() bool` - -Has{{name}} returns a boolean if a field has been set. -{{/required}} - -{{#isNullable}} -### Set{{name}}Nil - -`func (o *{{classname}}) Set{{name}}Nil(b bool)` - - Set{{name}}Nil sets the value for {{name}} to be an explicit nil - -### Unset{{name}} -`func (o *{{classname}}) Unset{{name}}()` - -Unset{{name}} ensures that no value is present for {{name}}, not even an explicit nil -{{/isNullable}} -{{/vars}} -{{#vendorExtensions.x-implements}} - -### As{{{.}}} - -`func (s *{{classname}}) As{{{.}}}() {{{.}}}` - -Convenience method to wrap this instance of {{classname}} in {{{.}}} -{{/vendorExtensions.x-implements}} -{{/vendorExtensions.x-is-one-of-interface}} -{{/isEnum}} -{{#isEnum}} -## Enum - -{{#allowableValues}}{{#enumVars}} -* `{{name}}` (value: `{{{value}}}`) -{{/enumVars}}{{/allowableValues}} -{{/isEnum}} - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - -{{/model}}{{/models}} diff --git a/languages/golang/compat-layer/templates/model_enum.mustache b/languages/golang/compat-layer/templates/model_enum.mustache deleted file mode 100644 index 8bdc277c..00000000 --- a/languages/golang/compat-layer/templates/model_enum.mustache +++ /dev/null @@ -1,121 +0,0 @@ -// {{{classname}}} {{{description}}}{{^description}}the model '{{{classname}}}'{{/description}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{{classname}}} {{dataType}} - -// List of {{{name}}} -const ( - {{#allowableValues}} - {{#enumVars}} - {{^-first}} - {{/-first}} - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - {{{classname.toUpperCase}}}_{{name}} {{{classname}}} = {{{value}}} - {{/enumVars}} - {{/allowableValues}} -) - -// All allowed values of {{{classname}}} enum -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -var Allowed{{{classname}}}EnumValues = []{{{classname}}}{ - {{#allowableValues}} - {{#enumVars}} - {{{value}}}, - {{/enumVars}} - {{/allowableValues}} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *{{{classname}}}) UnmarshalJSON(src []byte) error { - var value {{dataType}} - err := json.Unmarshal(src, &value) - if err != nil { - return err - } - // Allow unmarshalling zero value for testing purposes - var zeroValue {{dataType}} - if value == zeroValue { - return nil - } - enumTypeValue := {{{classname}}}(value) - for _, existing := range Allowed{{{classname}}}EnumValues { - if existing == enumTypeValue { - *v = enumTypeValue - return nil - } - } - - return fmt.Errorf("%+v is not a valid {{classname}}", value) -} - -// New{{{classname}}}FromValue returns a pointer to a valid {{{classname}}} -// for the value passed as argument, or an error if the value passed is not allowed by the enum -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func New{{{classname}}}FromValue(v {{dataType}}) (*{{{classname}}}, error) { - ev := {{{classname}}}(v) - if ev.IsValid() { - return &ev, nil - } else { - return nil, fmt.Errorf("invalid value '%v' for {{{classname}}}: valid values are %v", v, Allowed{{{classname}}}EnumValues) - } -} - -// IsValid return true if the value is valid for the enum, false otherwise -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v {{{classname}}}) IsValid() bool { - for _, existing := range Allowed{{{classname}}}EnumValues { - if existing == v { - return true - } - } - return false -} - -// Ptr returns reference to {{{name}}} value -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v {{{classname}}}) Ptr() *{{{classname}}} { - return &v -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type Nullable{{{classname}}} struct { - value *{{{classname}}} - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v Nullable{{classname}}) Get() *{{classname}} { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *Nullable{{classname}}) Set(val *{{classname}}) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v Nullable{{classname}}) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *Nullable{{classname}}) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullable{{classname}}(val *{{classname}}) *Nullable{{classname}} { - return &Nullable{{classname}}{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} diff --git a/languages/golang/compat-layer/templates/model_oneof.mustache b/languages/golang/compat-layer/templates/model_oneof.mustache deleted file mode 100644 index 7dadc07f..00000000 --- a/languages/golang/compat-layer/templates/model_oneof.mustache +++ /dev/null @@ -1,162 +0,0 @@ -// {{classname}} - {{{description}}}{{^description}}struct for {{{classname}}}{{/description}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}} struct { - {{#oneOf}} - {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} *{{{.}}} - {{/oneOf}} -} - -{{#oneOf}} -// {{{.}}}As{{classname}} is a convenience function that returns {{{.}}} wrapped in {{classname}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}As{{classname}}(v *{{{.}}}) {{classname}} { - return {{classname}}{ - {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}: v, - } -} - -{{/oneOf}} - -// Unmarshal JSON data into one of the pointers in the struct -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (dst *{{classname}}) UnmarshalJSON(data []byte) error { - var err error - {{#isNullable}} - // this object is nullable so check if the payload is null or empty string - if string(data) == "" || string(data) == "{}" { - return nil - } - - {{/isNullable}} - {{#useOneOfDiscriminatorLookup}} - {{#discriminator}} - {{#mappedModels}} - {{#-first}} - // use discriminator value to speed up the lookup - var jsonDict map[string]interface{} - err = newStrictDecoder(data).Decode(&jsonDict) - if err != nil { - return fmt.Errorf("failed to unmarshal JSON into map for the discriminator lookup") - } - - {{/-first}} - // check if the discriminator value is '{{{mappingName}}}' - if jsonDict["{{{propertyBaseName}}}"] == "{{{mappingName}}}" { - // try to unmarshal JSON data into {{{modelName}}} - err = json.Unmarshal(data, &dst.{{{modelName}}}) - if err == nil { - return nil // data stored in dst.{{{modelName}}}, return on the first match - } else { - dst.{{{modelName}}} = nil - return fmt.Errorf("failed to unmarshal {{classname}} as {{{modelName}}}: %s", err.Error()) - } - } - - {{/mappedModels}} - return nil - {{/discriminator}} - {{^discriminator}} - match := 0 - {{! BEGIN - Workaround in case oneOf contains enums and strings. The enum value would match with both. }} - {{! This workaround adds a regex check for the string (in case the api spec provides a regex) }} - // Workaround until upstream issue is fixed: - // https://github.com/OpenAPITools/openapi-generator/issues/21751 - // Tracking issue on our side: https://jira.schwarz/browse/STACKITSDK-226 - {{#composedSchemas.oneOf}} - {{#dataType}} - // try to unmarshal data into {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} - dst{{classname}}{{-index}} := &{{classname}}{} - err = json.Unmarshal(data, &dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) - if err == nil { - json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}, _ := json.Marshal(&dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) - {{#pattern}} - regex := `{{.}}` - regex = regexp.MustCompile("^\\/|\\/$").ReplaceAllString(regex, "$1") // Remove beginning slash and ending slash - regex = regexp.MustCompile("\\\\(.)").ReplaceAllString(regex, "$1") // Remove duplicate escaping char for dots - rawString := regexp.MustCompile(`^"|"$`).ReplaceAllString(*dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{dataType}}{{/lambda.type-to-name}}, "$1") // Remove quotes - isMatched, _ := regexp.MatchString(regex, rawString) - {{/pattern}} - if string(json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) != "{}" {{#pattern}}&& isMatched {{/pattern}} { // empty struct - dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = dst{{classname}}{{-index}}.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} - match++ - } - } - - {{/dataType}} - {{/composedSchemas.oneOf}} - {{! END - Workaround in case oneOf contains enums and strings. The enum value would match with both. }} - if match > 1 { // more than 1 match - // reset to nil - {{#oneOf}} - dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil - {{/oneOf}} - - return fmt.Errorf("data matches more than one schema in oneOf({{classname}})") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf({{classname}})") - } - {{/discriminator}} - {{/useOneOfDiscriminatorLookup}} - {{^useOneOfDiscriminatorLookup}} - match := 0 - {{#oneOf}} - // try to unmarshal data into {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} - err = newStrictDecoder(data).Decode(&dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) - if err == nil { - json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}, _ := json.Marshal(dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) - if string(json{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) == "{}" { // empty struct - dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil - } else { - match++ - } - } else { - dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil - } - - {{/oneOf}} - if match > 1 { // more than 1 match - // reset to nil - {{#oneOf}} - dst.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} = nil - {{/oneOf}} - - return fmt.Errorf("data matches more than one schema in oneOf({{classname}})") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf({{classname}})") - } - {{/useOneOfDiscriminatorLookup}} -} - -// Marshal data from the first non-nil pointers in the struct to JSON -func (src {{classname}}) MarshalJSON() ([]byte, error) { -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -{{#oneOf}} - if src.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} != nil { - return json.Marshal(&src.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}) - } - -{{/oneOf}} - return []byte("{}"), nil // no data in oneOf schemas => empty JSON object -} - -// Get the actual instance -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (obj *{{classname}}) GetActualInstance() (interface{}) { - if obj == nil { - return nil - } -{{#oneOf}} - if obj.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} != nil { - return obj.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} - } - -{{/oneOf}} - // all schemas are nil - return nil -} - -{{>nullable_model}} diff --git a/languages/golang/compat-layer/templates/model_simple.mustache b/languages/golang/compat-layer/templates/model_simple.mustache deleted file mode 100644 index b4b570f5..00000000 --- a/languages/golang/compat-layer/templates/model_simple.mustache +++ /dev/null @@ -1,1129 +0,0 @@ -// checks if the {{classname}} type satisfies the MappedNullable interface at compile time -var _ MappedNullable = &{{classname}}{} - -{{#vars}} - -/* - 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 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *float64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}float64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}float64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isNumber}} -{{#isFloat}} -// isFloat -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *float64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}float64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}float64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isFloat}} -{{#isDouble}} -// isDouble -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *float64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}float64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}float64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -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 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *int64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}int64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}int64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isInteger}} -{{/isShort}} -{{#isInteger}} -// isInteger -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *int64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}int64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}int64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isInteger}} -{{#isLong}} -// isLong -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *int64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}int64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}int64 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -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 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *NullableString -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return arg.Get(),true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - if IsNil(*arg) { - *arg = NewNullableString(val) - } else { - (*arg).Set(val) - } -} -{{/isNullable}} -{{^isNullable}} -{{! non nullable strings are plain string pointers}} -// isNotNullableString -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *string -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isNullable}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}string -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}string -{{/isArray}} -{{/isString}} -{{#isAnyType}} -// isAny -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = any -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = any -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = any -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -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 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *time.Time -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}time.Time -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}time.Time -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isDateTime}} -{{#isDate}} -{{! special handling for date}} -// isDate -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *string -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}string -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}string -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isDate}} -{{#isEnumRef}} -{{! special handling for enums}} -{{#isEnum}} -// isEnum - -// {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} {{{description}}}{{^description}}the model '{{{classname}}}'{{/description}} -// value type for enums -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} {{#isNumeric}}int{{/isNumeric}}{{^isNumeric}}string{{/isNumeric}} - -// List of {{name}} -const ( - {{#allowableValues}} - {{#enumVars}} - {{^-first}} - {{/-first}} - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - {{{classname.toUpperCase}}}{{{enumName}}}_{{name}} {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} = {{{value}}} - {{/enumVars}} - {{/allowableValues}} -) - -// All allowed values of {{{classname}}} enum -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -var Allowed{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}EnumValues = []{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}{ - {{#allowableValues}} - {{#enumVars}} - {{{value}}}, - {{/enumVars}} - {{/allowableValues}} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) UnmarshalJSON(src []byte) error { - // use a type alias to prevent infinite recursion during unmarshal, - // see https://biscuit.ninja/posts/go-avoid-an-infitine-loop-with-custom-json-unmarshallers - type TmpJson {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} - var value TmpJson - err := json.Unmarshal(src, &value) - if err != nil { - return err - } - // Allow unmarshalling zero value for testing purposes - var zeroValue TmpJson - if value == zeroValue { - return nil - } - enumTypeValue := {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}(value) - for _, existing := range Allowed{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}EnumValues { - if existing == enumTypeValue { - *v = enumTypeValue - return nil - } - } - - return fmt.Errorf("%+v is not a valid {{classname}}", value) -} - -// New{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}FromValue returns a pointer to a valid {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} -// for the value passed as argument, or an error if the value passed is not allowed by the enum -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func New{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}FromValue(v {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) (*{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}, error) { - ev := {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}(v) - if ev.IsValid() { - return &ev, nil - } else { - return nil, fmt.Errorf("invalid value '%v' for {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}: valid values are %v", v, Allowed{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}EnumValues) - } -} - -// IsValid return true if the value is valid for the enum, false otherwise -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) IsValid() bool { - for _, existing := range Allowed{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}EnumValues { - if existing == v { - return true - } - } - return false -} - -// Ptr returns reference to {{{name}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} value -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) Ptr() *{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} { - return &v -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type Nullable{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} struct { - value *{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v Nullable{{classname}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) Get() *{{classname}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *Nullable{{classname}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) Set(val *{{classname}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v Nullable{{classname}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *Nullable{{classname}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullable{{classname}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}(val *{{classname}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) *Nullable{{classname}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} { - return &Nullable{{classname}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v Nullable{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *Nullable{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}}) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isEnum}} -{{^isEnum}} -// isEnumRef -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{^isNumeric}}{{dataType}}{{/isNumeric}}{{#isNumeric}}int64{{/isNumeric}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isEnum}} -{{/isEnumRef}} -{{#isModel}} -{{! special handling for recursive datatypes}} -// isModel -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isModel}} -{{^isPrimitiveType}} -{{^isModel}} -{{^isMap}} -{{^isArray}} -{{^isDateTime}} -{{^isEnumRef}} -// fallback -{{! everything else will end up here}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isEnumRef}} -{{/isDateTime}} -{{/isArray}} -{{/isMap}} -{{/isModel}} -{{/isPrimitiveType}} -{{#isArray}} -// isArray -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isArray}} - - -{{#isFreeFormObject}} -// isFreeform -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isFreeFormObject}} -{{#isContainer}} -{{^isFreeFormObject}} -{{^isArray}} -// isContainer -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}{{dataType}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isArray}} -{{/isFreeFormObject}} -{{/isContainer}} -{{#isByteArray}} -// isByteArray -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *[]byte -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}[]byte -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}[]byte -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isByteArray}} -{{#isBoolean}} -// isBoolean -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}AttributeType = *bool -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}ArgType = {{#isNullable}}*{{/isNullable}}bool -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}}{{getter}}RetType = {{#isNullable}}*{{/isNullable}}bool -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func get{{classname}}{{getter}}AttributeTypeOk(arg {{classname}}{{getter}}AttributeType) (ret {{classname}}{{getter}}RetType, ok bool) { - if arg == nil { - {{#isNullable}} - return nil,false - {{/isNullable}} - {{^isNullable}} - return ret,false - {{/isNullable}} - } - return {{^isNullable}}*{{/isNullable}}arg,true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func set{{classname}}{{getter}}AttributeType(arg *{{classname}}{{getter}}AttributeType, val {{classname}}{{getter}}RetType) { - *arg={{^isNullable}}&{{/isNullable}}val -} -{{/isBoolean}} - -{{/vars}} - -// {{classname}} {{{description}}}{{^description}}struct for {{{classname}}}{{/description}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type {{classname}} struct { -{{#parent}} -{{^isMap}} -{{^isArray}} - {{{parent}}} -{{/isArray}} -{{/isMap}} -{{#isArray}} - Items {{{parent}}} -{{/isArray}} -{{/parent}} -{{#vars}} -{{^-first}} -{{/-first}} -{{#description}} - // {{#deprecated}} Deprecated: {{/deprecated}}{{{.}}} -{{/description}} -{{^description}} -{{#deprecated}} - // Deprecated: Check the GitHub changelog for alternatives -{{/deprecated}} -{{/description}} -{{#isShort}} - // Can be cast to int32 without loss of precision. -{{/isShort}} -{{#isFloat}} - // Can be cast to float32 without loss of precision. -{{/isFloat}} -{{#required}} -{{^isReadOnly}} -{{^isWriteOnly}} - // REQUIRED -{{/isWriteOnly}} -{{/isReadOnly}} -{{/required}} - {{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}}{{#required}} required:"true"{{/required}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` -{{/vars}} -{{#isAdditionalPropertiesTrue}} - AdditionalProperties map[string]interface{} -{{/isAdditionalPropertiesTrue}} -} - - -{{#isAdditionalPropertiesTrue}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type _{{{classname}}} {{{classname}}} - -{{/isAdditionalPropertiesTrue}} -{{^isAdditionalPropertiesTrue}} -{{#hasRequired}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type _{{{classname}}} {{{classname}}} - -{{/hasRequired}} -{{/isAdditionalPropertiesTrue}} -// New{{classname}} instantiates a new {{classname}} object -// 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 -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func New{{classname}}({{#requiredVars}}{{nameInCamelCase}} {{classname}}{{getter}}ArgType{{^-last}}, {{/-last}}{{/requiredVars}}) *{{classname}} { - this := {{classname}}{} -{{#allVars}} -{{#required}} - set{{classname}}{{getter}}AttributeType(&this.{{name}}, {{nameInCamelCase}}) -{{/required}} -{{/allVars}} - return &this -} - -// New{{classname}}WithDefaults instantiates a new {{classname}} object -// This constructor will only assign default values to properties that have it defined, -// but it doesn't guarantee that properties required by API are set -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func New{{classname}}WithDefaults() *{{classname}} { - this := {{classname}}{} -{{#vars}} -{{#defaultValue}} -{{^vendorExtensions.x-golang-is-container}} -{{^isReadOnly}} -{{#isEnum}} - var {{nameInCamelCase}} {{{classname}}}{{#lambda.titlecase}}{{nameInCamelCase}}{{/lambda.titlecase}} = {{{.}}} -{{/isEnum}} -{{^isEnum}} -{{!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}}{{#isNumber}}float64{{/isNumber}}{{^isNumber}}{{^isInteger}}{{dataType}}{{/isInteger}}{{/isNumber}} = {{{.}}} -{{/isEnum}} -{{#isNullable}} - this.{{name}} = *New{{dataType}}(&{{nameInCamelCase}}) -{{/isNullable}} -{{^isNullable}} - this.{{name}} = &{{nameInCamelCase}} -{{/isNullable}} -{{/isReadOnly}} -{{/vendorExtensions.x-golang-is-container}} -{{/defaultValue}} -{{/vars}} - return &this -} - -{{#vars}} -{{#required}} -// Get{{name}} returns the {{name}} field value -{{#isNullable}} -// If the value is explicit nil, the zero value for {{vendorExtensions.x-go-base-type}} will be returned -{{/isNullable}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o *{{classname}}) Get{{name}}() (ret {{classname}}{{getter}}RetType) { - ret,_ = o.Get{{name}}Ok() - return ret -} - -// Get{{name}}Ok returns a tuple with the {{name}} field value -// and a boolean to check if the value has been set. -{{#isNullable}} -// NOTE: If the value is an explicit nil, `nil, true` will be returned -{{/isNullable}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -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: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o *{{classname}}) Set{{name}}(v {{classname}}{{getter}}RetType) { - set{{classname}}{{getter}}AttributeType(&o.{{name}},v) -} - -{{/required}} -{{^required}} -// Get{{name}} returns the {{name}} field value if set, zero value otherwise{{#isNullable}} (both if not set or set to explicit null){{/isNullable}}. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o *{{classname}}) Get{{name}}() (res {{classname}}{{getter}}RetType) { - res,_ = o.Get{{name}}Ok() - return -} - -// Get{{name}}Ok returns a tuple with the {{name}} field value if set, nil otherwise -// and a boolean to check if the value has been set. -{{#isNullable}} -// NOTE: If the value is an explicit nil, `nil, true` will be returned -{{/isNullable}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -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. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o *{{classname}}) Has{{name}}() bool { - _,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: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o *{{classname}}) Set{{name}}(v {{classname}}{{getter}}RetType) { - set{{classname}}{{getter}}AttributeType(&o.{{name}},v) -} - - -{{#isNullable}} -{{^vendorExtensions.x-golang-is-container}} -// Set{{name}}Nil sets the value for {{name}} to be an explicit nil -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o *{{classname}}) Set{{name}}Nil() { - o.{{name}} = nil -} - -// Unset{{name}} ensures that no value is present for {{name}}, not even an explicit nil -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o *{{classname}}) Unset{{name}}() { - o.{{name}} = nil -} -{{/vendorExtensions.x-golang-is-container}} -{{/isNullable}} - -{{/required}} -{{/vars}} -{{#vendorExtensions.x-go-generate-marshal-json}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o {{classname}}) MarshalJSON() ([]byte, error) { - toSerialize,err := o.ToMap() - if err != nil { - return []byte{}, err - } - return json.Marshal(toSerialize) -} - -{{/vendorExtensions.x-go-generate-marshal-json}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o {{classname}}) ToMap() (map[string]interface{}, error) { - toSerialize := {{#isArray}}make([]interface{}, len(o.Items)){{/isArray}}{{^isArray}}map[string]interface{}{}{{/isArray}} - {{#parent}} - {{^isMap}} - {{^isArray}} - serialized{{parent}}, err{{parent}} := json.Marshal(o.{{parent}}) - if err{{parent}} != nil { - return map[string]interface{}{}, err{{parent}} - } - err{{parent}} = json.Unmarshal([]byte(serialized{{parent}}), &toSerialize) - if err{{parent}} != nil { - return map[string]interface{}{}, err{{parent}} - } - {{/isArray}} - {{/isMap}} - {{#isArray}} - for i, item := range o.Items { - toSerialize[i] = item - } - {{/isArray}} - {{/parent}} - {{#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}}{{getter}}AttributeTypeOk(o.{{name}});ok { - toSerialize["{{{name}}}"] = val - } - {{/vars}} - {{#isAdditionalPropertiesTrue}} - - for key, value := range o.AdditionalProperties { - toSerialize[key] = value - } - - {{/isAdditionalPropertiesTrue}} - return toSerialize, nil -} - -{{#vendorExtensions.x-go-generate-unmarshal-json}} -{{#isAdditionalPropertiesTrue}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o *{{{classname}}}) UnmarshalJSON(data []byte) (err error) { -{{/isAdditionalPropertiesTrue}} -{{^isAdditionalPropertiesTrue}} -{{#hasRequired}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o *{{{classname}}}) UnmarshalJSON(data []byte) (err error) { -{{/hasRequired}} -{{/isAdditionalPropertiesTrue}} -{{#hasRequired}} - // This validates that all required properties are included in the JSON object - // by unmarshalling the object into a generic map with string keys and checking - // that every required field exists as a key in the generic map. - requiredProperties := []string{ -{{#requiredVars}} - "{{nameInCamelCase}}", -{{/requiredVars}} - } - - allProperties := make(map[string]interface{}) - - err = json.Unmarshal(data, &allProperties) - - if err != nil { - return err; - } - - for _, requiredProperty := range(requiredProperties) { - if _, exists := allProperties[requiredProperty]; !exists { - return fmt.Errorf("no value given for required property %v", requiredProperty) - } - } - -{{/hasRequired}} -{{#isAdditionalPropertiesTrue}} -{{#parent}} -{{^isMap}} - type {{classname}}WithoutEmbeddedStruct struct { - {{#vars}} - {{^-first}} - {{/-first}} - {{#description}} - // {{{.}}} - {{/description}} - {{#deprecated}} - // Deprecated - {{/deprecated}} - {{name}} {{^required}}{{^isNullable}}*{{/isNullable}}{{/required}}{{#isNumber}}float64{{/isNumber}}{{#isFloat}}float64{{/isFloat}}{{#isDouble}}float64{{/isDouble}}{{#isInteger}}int64{{/isInteger}}{{#isLong}}int64{{/isLong}}{{^isNumeric}}{{{dataType}}}{{/isNumeric}} `json:"{{{baseName}}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{{baseName}}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}` - {{/vars}} - } - - var{{{classname}}}WithoutEmbeddedStruct := {{{classname}}}WithoutEmbeddedStruct{} - - err = json.Unmarshal(data, &var{{{classname}}}WithoutEmbeddedStruct) - if err == nil { - var{{{classname}}} := _{{{classname}}}{} - {{#vars}} - var{{{classname}}}.{{{name}}} = var{{{classname}}}WithoutEmbeddedStruct.{{{name}}} - {{/vars}} - *o = {{{classname}}}(var{{{classname}}}) - } else { - return err - } - - var{{{classname}}} := _{{{classname}}}{} - - err = json.Unmarshal(data, &var{{{classname}}}) - if err == nil { - o.{{{parent}}} = var{{{classname}}}.{{{parent}}} - } else { - return err - } - - additionalProperties := make(map[string]interface{}) - - if err = json.Unmarshal(data, &additionalProperties); err == nil { - {{#vars}} - delete(additionalProperties, "{{{baseName}}}") - {{/vars}} - - // remove fields from embedded structs - reflect{{{parent}}} := reflect.ValueOf(o.{{{parent}}}) - for i := 0; i < reflect{{{parent}}}.Type().NumField(); i++ { - t := reflect{{{parent}}}.Type().Field(i) - - if jsonTag := t.Tag.Get("json"); jsonTag != "" { - fieldName := "" - if commaIdx := strings.Index(jsonTag, ","); commaIdx > 0 { - fieldName = jsonTag[:commaIdx] - } else { - fieldName = jsonTag - } - if fieldName != "AdditionalProperties" { - delete(additionalProperties, fieldName) - } - } - } - - o.AdditionalProperties = additionalProperties - } - - return err -{{/isMap}} -{{#isMap}} - var{{{classname}}} := _{{{classname}}}{} - - err = json.Unmarshal(data, &var{{{classname}}}) - - if err != nil { - return err - } - - *o = {{{classname}}}(var{{{classname}}}) - - additionalProperties := make(map[string]interface{}) - - if err = json.Unmarshal(data, &additionalProperties); err == nil { - {{#vars}} - delete(additionalProperties, "{{{baseName}}}") - {{/vars}} - o.AdditionalProperties = additionalProperties - } - - return err -{{/isMap}} -{{/parent}} -{{^parent}} - var{{{classname}}} := _{{{classname}}}{} - - err = json.Unmarshal(data, &var{{{classname}}}) - - if err != nil { - return err - } - - *o = {{{classname}}}(var{{{classname}}}) - - additionalProperties := make(map[string]interface{}) - - if err = json.Unmarshal(data, &additionalProperties); err == nil { - {{#vars}} - delete(additionalProperties, "{{{baseName}}}") - {{/vars}} - o.AdditionalProperties = additionalProperties - } - - return err -{{/parent}} -{{/isAdditionalPropertiesTrue}} -{{#isAdditionalPropertiesTrue}} -} - -{{/isAdditionalPropertiesTrue}} -{{^isAdditionalPropertiesTrue}} -{{#hasRequired}} - var{{{classname}}} := _{{{classname}}}{} - - decoder := json.NewDecoder(bytes.NewReader(data)) - decoder.DisallowUnknownFields() - err = decoder.Decode(&var{{{classname}}}) - - if err != nil { - return err - } - - *o = {{{classname}}}(var{{{classname}}}) - - return err -} - -{{/hasRequired}} -{{/isAdditionalPropertiesTrue}} -{{#isArray}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (o *{{{classname}}}) UnmarshalJSON(data []byte) (err error) { - return json.Unmarshal(data, &o.Items) -} - -{{/isArray}} -{{/vendorExtensions.x-go-generate-unmarshal-json}} -{{>nullable_model}} diff --git a/languages/golang/compat-layer/templates/nullable_model.mustache b/languages/golang/compat-layer/templates/nullable_model.mustache deleted file mode 100644 index 06ada567..00000000 --- a/languages/golang/compat-layer/templates/nullable_model.mustache +++ /dev/null @@ -1,43 +0,0 @@ -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type Nullable{{{classname}}} struct { - value {{^isArray}}{{^isFreeFormObject}}*{{/isFreeFormObject}}{{/isArray}}{{{classname}}} - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v Nullable{{classname}}) Get() {{^isArray}}{{^isFreeFormObject}}*{{/isFreeFormObject}}{{/isArray}}{{classname}} { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *Nullable{{classname}}) Set(val {{^isArray}}{{^isFreeFormObject}}*{{/isFreeFormObject}}{{/isArray}}{{classname}}) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v Nullable{{classname}}) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *Nullable{{classname}}) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullable{{classname}}(val {{^isArray}}{{^isFreeFormObject}}*{{/isFreeFormObject}}{{/isArray}}{{classname}}) *Nullable{{classname}} { - return &Nullable{{classname}}{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} diff --git a/languages/golang/compat-layer/templates/openapi.mustache b/languages/golang/compat-layer/templates/openapi.mustache deleted file mode 100644 index 51ebafb0..00000000 --- a/languages/golang/compat-layer/templates/openapi.mustache +++ /dev/null @@ -1 +0,0 @@ -{{{openapi-yaml}}} \ No newline at end of file diff --git a/languages/golang/compat-layer/templates/partial_header.mustache b/languages/golang/compat-layer/templates/partial_header.mustache deleted file mode 100644 index 1f7f7238..00000000 --- a/languages/golang/compat-layer/templates/partial_header.mustache +++ /dev/null @@ -1,15 +0,0 @@ -/* -{{#appName}} -{{{.}}} - -{{/appName}} -{{#appDescription}} -{{{.}}} - -{{/appDescription}} -{{#version}} -API version: {{{.}}} -{{/version}} -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. diff --git a/languages/golang/compat-layer/templates/response.mustache b/languages/golang/compat-layer/templates/response.mustache deleted file mode 100644 index 1ad3dbf9..00000000 --- a/languages/golang/compat-layer/templates/response.mustache +++ /dev/null @@ -1,48 +0,0 @@ -{{>partial_header}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -package {{packageName}} - -import ( - "net/http" -) - -// APIResponse stores the API response returned by the server. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type APIResponse struct { - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - *http.Response `json:"-"` - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - Message string `json:"message,omitempty"` - // Operation is the name of the OpenAPI operation. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - Operation string `json:"operation,omitempty"` - // RequestURL is the request URL. This value is always available, even if the - // embedded *http.Response is nil. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - RequestURL string `json:"url,omitempty"` - // Method is the HTTP method used for the request. This value is always - // available, even if the embedded *http.Response is nil. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - Method string `json:"method,omitempty"` - // Payload holds the contents of the response body (which may be nil or empty). - // This is provided here as the raw response.Body() reader will have already - // been drained. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - Payload []byte `json:"-"` -} - -// NewAPIResponse returns a new APIResponse object. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewAPIResponse(r *http.Response) *APIResponse { - - response := &APIResponse{Response: r} - return response -} - -// NewAPIResponseWithError returns a new APIResponse object with the provided error message. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewAPIResponseWithError(errorMessage string) *APIResponse { - - response := &APIResponse{Message: errorMessage} - return response -} diff --git a/languages/golang/compat-layer/templates/signing.mustache b/languages/golang/compat-layer/templates/signing.mustache deleted file mode 100644 index 553daf30..00000000 --- a/languages/golang/compat-layer/templates/signing.mustache +++ /dev/null @@ -1,468 +0,0 @@ -{{>partial_header}} -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -package {{packageName}} - -import ( - "bytes" - "context" - "crypto" - "crypto/ecdsa" - "crypto/ed25519" - "crypto/rand" - "crypto/rsa" - "crypto/x509" - "encoding/base64" - "encoding/pem" - "fmt" - "io" - "net/http" - "net/textproto" - "os" - "strings" - "time" -) - -const ( - // Constants for HTTP signature parameters. - // The '(request-target)' parameter concatenates the lowercased :method, an - // ASCII space, and the :path pseudo-headers. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpSignatureParameterRequestTarget string = "(request-target)" - // The '(created)' parameter expresses when the signature was - // created. The value MUST be a Unix timestamp integer value. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpSignatureParameterCreated string = "(created)" - // The '(expires)' parameter expresses when the signature ceases to - // be valid. The value MUST be a Unix timestamp integer value. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpSignatureParameterExpires string = "(expires)" -) - -const ( - // Constants for HTTP headers. - // The 'Host' header, as defined in RFC 2616, section 14.23. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpHeaderHost string = "Host" - // The 'Date' header. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpHeaderDate string = "Date" - // The digest header, as defined in RFC 3230, section 4.3.2. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpHeaderDigest string = "Digest" - // The HTTP Authorization header, as defined in RFC 7235, section 4.2. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpHeaderAuthorization string = "Authorization" -) - -const ( - // Specifies the Digital Signature Algorithm is derived from metadata - // associated with 'keyId'. Supported DSA algorithms are RSASSA-PKCS1-v1_5, - // RSASSA-PSS, and ECDSA. - // The hash is SHA-512. - // This is the default value. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpSigningSchemeHs2019 string = "hs2019" - // Use RSASSA-PKCS1-v1_5 with SHA-512 hash. Deprecated. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpSigningSchemeRsaSha512 string = "rsa-sha512" - // Use RSASSA-PKCS1-v1_5 with SHA-256 hash. Deprecated. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpSigningSchemeRsaSha256 string = "rsa-sha256" - - // RFC 8017 section 7.2 - // Calculate the message signature using RSASSA-PKCS1-V1_5-SIGN from RSA PKCS#1 v1.5. - // PKCSV1_5 is deterministic. The same message and key will produce an identical - // signature value each time. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpSigningAlgorithmRsaPKCS1v15 string = "RSASSA-PKCS1-v1_5" - // Calculate the message signature using probabilistic signature scheme RSASSA-PSS. - // PSS is randomized and will produce a different signature value each time. - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpSigningAlgorithmRsaPSS string = "RSASSA-PSS" - - // HashAlgorithm Sha256 for generating hash - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpHashAlgorithmSha256 string = "sha256" - - // HashAlgorithm Sha512 for generating hash - // Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead - HttpHashAlgorithmSha512 string = "sha512" -) - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -var supportedSigningSchemes = map[string]bool{ - HttpSigningSchemeHs2019: true, - HttpSigningSchemeRsaSha512: true, - HttpSigningSchemeRsaSha256: true, -} - - -// HttpSignatureAuth provides HTTP signature authentication to a request passed -// via context using ContextHttpSignatureAuth. -// An 'Authorization' header is calculated by creating a hash of select headers, -// and optionally the body of the HTTP request, then signing the hash value using -// a private key which is available to the client. -// -// SignedHeaders specifies the list of HTTP headers that are included when generating -// the message signature. -// The two special signature headers '(request-target)' and '(created)' SHOULD be -// included in SignedHeaders. -// The '(created)' header expresses when the signature was created. -// The '(request-target)' header is a concatenation of the lowercased :method, an -// ASCII space, and the :path pseudo-headers. -// -// For example, SignedHeaders can be set to: -// (request-target) (created) date host digest -// -// When SignedHeaders is not specified, the client defaults to a single value, '(created)', -// in the list of HTTP headers. -// When SignedHeaders contains the 'Digest' value, the client performs the following operations: -// 1. Calculate a digest of request body, as specified in RFC3230, section 4.3.2. -// 2. Set the 'Digest' header in the request body. -// 3. Include the 'Digest' header and value in the HTTP signature. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type HttpSignatureAuth struct { - KeyId string // A key identifier. - PrivateKeyPath string // The path to the private key. - Passphrase string // The passphrase to decrypt the private key, if the key is encrypted. - SigningScheme string // The signature scheme, when signing HTTP requests. Supported value is 'hs2019'. - // The signature algorithm, when signing HTTP requests. - // Supported values are RSASSA-PKCS1-v1_5, RSASSA-PSS. - SigningAlgorithm string - HashAlgorithm string // supported values are sha256 and sha512. This also allows using sha256 with hs2019, which defaults to sha512. - SignedHeaders []string // A list of HTTP headers included when generating the signature for the message. - // SignatureMaxValidity specifies the maximum duration of the signature validity. - // The value is used to set the '(expires)' signature parameter in the HTTP request. - // '(expires)' is set to '(created)' plus the value of the SignatureMaxValidity field. - // To specify the '(expires)' signature parameter, set 'SignatureMaxValidity' and add '(expires)' to 'SignedHeaders'. - SignatureMaxValidity time.Duration - privateKey crypto.PrivateKey // The private key used to sign HTTP requests. -} - -// SetPrivateKey accepts a private key string and sets it. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (h *HttpSignatureAuth) SetPrivateKey(privateKey string) error { - return h.parsePrivateKey([]byte(privateKey)) -} - -// ContextWithValue validates the HttpSignatureAuth configuration parameters and returns a context -// suitable for HTTP signature. An error is returned if the HttpSignatureAuth configuration parameters -// are invalid. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (h *HttpSignatureAuth) ContextWithValue(ctx context.Context) (context.Context, error) { - if h.KeyId == "" { - return nil, fmt.Errorf("key ID must be specified") - } - if h.PrivateKeyPath == "" && h.privateKey == nil { - return nil, fmt.Errorf("private key path must be specified") - } - if _, ok := supportedSigningSchemes[h.SigningScheme]; !ok { - return nil, fmt.Errorf("invalid signing scheme: '%v'", h.SigningScheme) - } - m := make(map[string]bool) - for _, h := range h.SignedHeaders { - if strings.EqualFold(h, HttpHeaderAuthorization) { - return nil, fmt.Errorf("signed headers cannot include the 'Authorization' header") - } - m[h] = true - } - if len(m) != len(h.SignedHeaders) { - return nil, fmt.Errorf("list of signed headers cannot have duplicate names") - } - if h.SignatureMaxValidity < 0 { - return nil, fmt.Errorf("signature max validity must be a positive value") - } - if err := h.loadPrivateKey(); err != nil { - return nil, err - } - return context.WithValue(ctx, ContextHttpSignatureAuth, *h), nil -} - -// GetPublicKey returns the public key associated with this HTTP signature configuration. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (h *HttpSignatureAuth) GetPublicKey() (crypto.PublicKey, error) { - if h.privateKey == nil { - if err := h.loadPrivateKey(); err != nil { - return nil, err - } - } - switch key := h.privateKey.(type) { - case *rsa.PrivateKey: - return key.Public(), nil - case *ecdsa.PrivateKey: - return key.Public(), nil - default: - // Do not change '%T' to anything else such as '%v'! - // The value of the private key must not be returned. - return nil, fmt.Errorf("unsupported key: %T", h.privateKey) - } -} - -// loadPrivateKey reads the private key from the file specified in the HttpSignatureAuth. -// The key is loaded only when privateKey is not already set. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (h *HttpSignatureAuth) loadPrivateKey() (err error) { - if h.privateKey != nil { - return nil - } - var file *os.File - file, err = os.Open(h.PrivateKeyPath) - if err != nil { - return fmt.Errorf("cannot load private key '%s'. Error: %v", h.PrivateKeyPath, err) - } - defer func() { - err = file.Close() - }() - var priv []byte - priv, err = io.ReadAll(file) - if err != nil { - return err - } - return h.parsePrivateKey(priv) -} - -// parsePrivateKey decodes privateKey byte array to crypto.PrivateKey type. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (h *HttpSignatureAuth) parsePrivateKey(priv []byte) error { - pemBlock, _ := pem.Decode(priv) - if pemBlock == nil { - // No PEM data has been found. - return fmt.Errorf("file '%s' does not contain PEM data", h.PrivateKeyPath) - } - var privKey []byte - var err error - if x509.IsEncryptedPEMBlock(pemBlock) { - // The PEM data is encrypted. - privKey, err = x509.DecryptPEMBlock(pemBlock, []byte(h.Passphrase)) - if err != nil { - // Failed to decrypt PEM block. Because of deficiencies in the encrypted-PEM format, - // it's not always possible to detect an incorrect password. - return err - } - } else { - privKey = pemBlock.Bytes - } - switch pemBlock.Type { - case "RSA PRIVATE KEY": - if h.privateKey, err = x509.ParsePKCS1PrivateKey(privKey); err != nil { - return err - } - case "EC PRIVATE KEY", "PRIVATE KEY": - // https://tools.ietf.org/html/rfc5915 section 4. - if h.privateKey, err = x509.ParsePKCS8PrivateKey(privKey); err != nil { - return err - } - default: - return fmt.Errorf("key '%s' is not supported", pemBlock.Type) - } - return nil -} - -// SignRequest signs the request using HTTP signature. -// See https://datatracker.ietf.org/doc/draft-cavage-http-signatures/ -// -// Do not add, remove or change headers that are included in the SignedHeaders -// after SignRequest has been invoked; this is because the header values are -// included in the signature. Any subsequent alteration will cause a signature -// verification failure. -// If there are multiple instances of the same header field, all -// header field values associated with the header field MUST be -// concatenated, separated by a ASCII comma and an ASCII space -// ', ', and used in the order in which they will appear in the -// transmitted HTTP message. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func SignRequest( - ctx context.Context, - r *http.Request, - auth HttpSignatureAuth) error { - - if auth.privateKey == nil { - return fmt.Errorf("private key is not set") - } - now := time.Now() - date := now.UTC().Format(http.TimeFormat) - // The 'created' field expresses when the signature was created. - // The value MUST be a Unix timestamp integer value. See 'HTTP signature' section 2.1.4. - created := now.Unix() - - var h crypto.Hash - var err error - var prefix string - var expiresUnix float64 - - if auth.SignatureMaxValidity < 0 { - return fmt.Errorf("signature validity must be a positive value") - } - if auth.SignatureMaxValidity > 0 { - e := now.Add(auth.SignatureMaxValidity) - expiresUnix = float64(e.Unix()) + float64(e.Nanosecond()) / float64(time.Second) - } - // Determine the cryptographic hash to be used for the signature and the body digest. - switch auth.SigningScheme { - case HttpSigningSchemeRsaSha512: - h = crypto.SHA512 - prefix = "SHA-512=" - case HttpSigningSchemeRsaSha256: - // This is deprecated and should no longer be used. - h = crypto.SHA256 - prefix = "SHA-256=" - case HttpSigningSchemeHs2019: - if auth.HashAlgorithm == HttpHashAlgorithmSha256 { - h = crypto.SHA256 - prefix = "SHA-256=" - } else { - h = crypto.SHA512 - prefix = "SHA-512=" - } - - default: - return fmt.Errorf("unsupported signature scheme: %v", auth.SigningScheme) - } - if !h.Available() { - return fmt.Errorf("hash '%v' is not available", h) - } - - // Build the "(request-target)" signature header. - var sb bytes.Buffer - fmt.Fprintf(&sb, "%s %s", strings.ToLower(r.Method), r.URL.EscapedPath()) - if r.URL.RawQuery != "" { - // The ":path" pseudo-header field includes the path and query parts - // of the target URI (the "path-absolute" production and optionally a - // '?' character followed by the "query" production (see Sections 3.3 - // and 3.4 of [RFC3986] - fmt.Fprintf(&sb, "?%s", r.URL.RawQuery) - } - requestTarget := sb.String() - sb.Reset() - - // Build the string to be signed. - signedHeaders := auth.SignedHeaders - if len(signedHeaders) == 0 { - signedHeaders = []string{HttpSignatureParameterCreated} - } - // Validate the list of signed headers has no duplicates. - m := make(map[string]bool) - for _, h := range signedHeaders { - m[h] = true - } - if len(m) != len(signedHeaders) { - return fmt.Errorf("list of signed headers must not have any duplicates") - } - hasCreatedParameter := false - hasExpiresParameter := false - for i, header := range signedHeaders { - header = strings.ToLower(header) - var value string - switch header { - case strings.ToLower(HttpHeaderAuthorization): - return fmt.Errorf("cannot include the 'Authorization' header as a signed header") - case HttpSignatureParameterRequestTarget: - value = requestTarget - case HttpSignatureParameterCreated: - value = fmt.Sprintf("%d", created) - hasCreatedParameter = true - case HttpSignatureParameterExpires: - if auth.SignatureMaxValidity.Nanoseconds() == 0 { - return fmt.Errorf("cannot set '(expires)' signature parameter. SignatureMaxValidity is not configured") - } - value = fmt.Sprintf("%.3f", expiresUnix) - hasExpiresParameter = true - case "date": - value = date - r.Header.Set(HttpHeaderDate, date) - case "digest": - // Calculate the digest of the HTTP request body. - // Calculate body digest per RFC 3230 section 4.3.2 - bodyHash := h.New() - if r.Body != nil { - // Make a copy of the body io.Reader so that we can read the body to calculate the hash, - // then one more time when marshaling the request. - var body io.Reader - body, err = r.GetBody() - if err != nil { - return err - } - if _, err = io.Copy(bodyHash, body); err != nil { - return err - } - } - d := bodyHash.Sum(nil) - value = prefix + base64.StdEncoding.EncodeToString(d) - r.Header.Set(HttpHeaderDigest, value) - case "host": - value = r.Host - r.Header.Set(HttpHeaderHost, r.Host) - default: - var ok bool - var v []string - canonicalHeader := textproto.CanonicalMIMEHeaderKey(header) - if v, ok = r.Header[canonicalHeader]; !ok { - // If a header specified in the headers parameter cannot be matched with - // a provided header in the message, the implementation MUST produce an error. - return fmt.Errorf("header '%s' does not exist in the request", canonicalHeader) - } - // If there are multiple instances of the same header field, all - // header field values associated with the header field MUST be - // concatenated, separated by a ASCII comma and an ASCII space - // `, `, and used in the order in which they will appear in the - // transmitted HTTP message. - value = strings.Join(v, ", ") - } - if i > 0 { - fmt.Fprintf(&sb, "\n") - } - fmt.Fprintf(&sb, "%s: %s", header, value) - } - if expiresUnix != 0 && !hasExpiresParameter { - return fmt.Errorf("signatureMaxValidity is specified, but '(expired)' parameter is not present") - } - msg := []byte(sb.String()) - msgHash := h.New() - if _, err = msgHash.Write(msg); err != nil { - return err - } - d := msgHash.Sum(nil) - - var signature []byte - switch key := auth.privateKey.(type) { - case *rsa.PrivateKey: - switch auth.SigningAlgorithm { - case HttpSigningAlgorithmRsaPKCS1v15: - signature, err = rsa.SignPKCS1v15(rand.Reader, key, h, d) - case "", HttpSigningAlgorithmRsaPSS: - signature, err = rsa.SignPSS(rand.Reader, key, h, d, nil) - default: - return fmt.Errorf("unsupported signing algorithm: '%s'", auth.SigningAlgorithm) - } - case *ecdsa.PrivateKey: - signature, err = key.Sign(rand.Reader, d, h) - case ed25519.PrivateKey: // requires go 1.13 - signature, err = key.Sign(rand.Reader, msg, crypto.Hash(0)) - default: - return fmt.Errorf("unsupported private key") - } - if err != nil { - return err - } - - sb.Reset() - for i, header := range signedHeaders { - if i > 0 { - sb.WriteRune(' ') - } - sb.WriteString(strings.ToLower(header)) - } - headers_list := sb.String() - sb.Reset() - fmt.Fprintf(&sb, `Signature keyId="%s",algorithm="%s",`, auth.KeyId, auth.SigningScheme) - if hasCreatedParameter { - fmt.Fprintf(&sb, "created=%d,", created) - } - if hasExpiresParameter { - fmt.Fprintf(&sb, "expires=%.3f,", expiresUnix) - } - fmt.Fprintf(&sb, `headers="%s",signature="%s"`, headers_list, base64.StdEncoding.EncodeToString(signature)) - authStr := sb.String() - r.Header.Set(HttpHeaderAuthorization, authStr) - return nil -} diff --git a/languages/golang/compat-layer/templates/utils.mustache b/languages/golang/compat-layer/templates/utils.mustache deleted file mode 100644 index 254911ed..00000000 --- a/languages/golang/compat-layer/templates/utils.mustache +++ /dev/null @@ -1,456 +0,0 @@ -{{>partial_header}} -package {{packageName}} - -import ( - "encoding/json" - "reflect" - "time" -) - -// PtrBool is a helper routine that returns a pointer to given boolean value. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func PtrBool(v bool) *bool { return &v } - -// PtrInt is a helper routine that returns a pointer to given integer value. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func PtrInt(v int) *int { return &v } - -// PtrInt32 is a helper routine that returns a pointer to given integer value. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func PtrInt32(v int32) *int32 { return &v } - -// PtrInt64 is a helper routine that returns a pointer to given integer value. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func PtrInt64(v int64) *int64 { return &v } - -// PtrFloat32 is a helper routine that returns a pointer to given float value. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func PtrFloat32(v float32) *float32 { return &v } - -// PtrFloat64 is a helper routine that returns a pointer to given float value. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func PtrFloat64(v float64) *float64 { return &v } - -// PtrString is a helper routine that returns a pointer to given string value. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func PtrString(v string) *string { return &v } - -// PtrTime is helper routine that returns a pointer to given Time value. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func PtrTime(v time.Time) *time.Time { return &v } - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type NullableValue[T any] struct { - value *T - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableValue[T]) Get() *T { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableValue[T]) Set(val *T) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableValue[T]) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableValue[T]) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type NullableBool struct { - value *bool - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableBool) Get() *bool { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableBool) Set(val *bool) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableBool) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableBool) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullableBool(val *bool) *NullableBool { - return &NullableBool{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableBool) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableBool) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type NullableInt struct { - value *int - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableInt) Get() *int { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableInt) Set(val *int) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableInt) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableInt) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullableInt(val *int) *NullableInt { - return &NullableInt{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableInt) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableInt) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type NullableInt32 struct { - value *int32 - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableInt32) Get() *int32 { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableInt32) Set(val *int32) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableInt32) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableInt32) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullableInt32(val *int32) *NullableInt32 { - return &NullableInt32{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableInt32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableInt32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type NullableInt64 struct { - value *int64 - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableInt64) Get() *int64 { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableInt64) Set(val *int64) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableInt64) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableInt64) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullableInt64(val *int64) *NullableInt64 { - return &NullableInt64{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableInt64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableInt64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type NullableFloat32 struct { - value *float32 - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableFloat32) Get() *float32 { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableFloat32) Set(val *float32) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableFloat32) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableFloat32) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullableFloat32(val *float32) *NullableFloat32 { - return &NullableFloat32{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableFloat32) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableFloat32) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type NullableFloat64 struct { - value *float64 - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableFloat64) Get() *float64 { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableFloat64) Set(val *float64) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableFloat64) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableFloat64) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullableFloat64(val *float64) *NullableFloat64 { - return &NullableFloat64{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableFloat64) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableFloat64) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type NullableString struct { - value *string - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableString) Get() *string { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableString) Set(val *string) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableString) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableString) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullableString(val *string) *NullableString { - return &NullableString{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableString) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableString) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type NullableTime struct { - value *time.Time - isSet bool -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableTime) Get() *time.Time { - return v.value -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableTime) Set(val *time.Time) { - v.value = val - v.isSet = true -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableTime) IsSet() bool { - return v.isSet -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableTime) Unset() { - v.value = nil - v.isSet = false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func NewNullableTime(val *time.Time) *NullableTime { - return &NullableTime{value: val, isSet: true} -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v NullableTime) MarshalJSON() ([]byte, error) { - return v.value.MarshalJSON() -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func (v *NullableTime) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// IsNil checks if an input is nil -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -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() - case reflect.Array: - return reflect.ValueOf(i).IsZero() - } - return false -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -type MappedNullable interface { - ToMap() (map[string]interface{}, error) -} - -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -const letterRunes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - -// randString returns a random string with a specified length. It panics if n <= 0. -// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead -func randString(n int) string { - b := make([]byte, n) - for i := range b { - b[i] = letterRunes[rand.Intn(len(letterRunes))] - } - return string(b) -} diff --git a/scripts/download-oas.sh b/scripts/download-oas.sh index 43a829d4..0c411bba 100755 --- a/scripts/download-oas.sh +++ b/scripts/download-oas.sh @@ -30,8 +30,8 @@ fi git clone "${OAS_REPO}" "${ROOT_DIR}/oas" --quiet -# NOTE: Everything below is needed for the "compatibility layer" logic. -# It can be completely removed once the compatibility layer isn't needed anymore in the SDK. +# NOTE: Everything below is needed for the python SDK which doesn't have multi API version support yet. +# It can be completely removed once the python SDK got migrated to the new multi API version concept. # Create temp directory to clone OAS repo work_dir=$(mktemp -d) diff --git a/scripts/generate-sdk/languages/go.sh b/scripts/generate-sdk/languages/go.sh index 75216164..c65bfc6a 100644 --- a/scripts/generate-sdk/languages/go.sh +++ b/scripts/generate-sdk/languages/go.sh @@ -154,7 +154,6 @@ generate_go_sdk() { generate_go_service() { local service_dir=$1 local service=$2 - local compat_layer_service_oas_name=$3 echo -e "\n>> Generating SDK for \"${service}\" service..." for version_dir in "${service_dir}"/*; do @@ -209,122 +208,21 @@ generate_go_service() { fi done - if ! grep -E "^$service$" "${ROOT_DIR}/languages/golang/compat-layer/allow-list.txt"; then - echo "Skipping service ${service}, compatibility layer is not activated for it" - warning+="Skipping compatibility layer generation for service ${service}\n" - - if [ ! -f "${SERVICES_FOLDER}/${service}/go.mod" ]; then - printf "module ${GIT_HOST}/${GIT_USER_ID}/${GIT_REPO_ID}/services/${service}\n\n" > "${SERVICES_FOLDER}/${service}/go.mod" - printf "go ${SDK_GO_VERSION}\n\n" >> "${SERVICES_FOLDER}/${service}/go.mod" - printf "require (\n\tgithub.com/stackitcloud/stackit-sdk-go/core v0.21.1\n)\n" >> "${SERVICES_FOLDER}/${service}/go.mod" - fi - - # generate package.go - printf "package ${service}\n" > "${SERVICES_FOLDER}/${service}/package.go" - - # If the service has a LICENSE file, move it inside the service folder - if [ -f "${sdk_services_backup_dir}/${service}/LICENSE.md" ]; then - echo "Found ${service} \"LICENSE\" file" - cp -r "${sdk_services_backup_dir}/${service}/LICENSE.md" "${SERVICES_FOLDER}/${service}/LICENSE.md" - else - cp "${ROOT_DIR}/LICENSE.md" "${SERVICES_FOLDER}/${service}/LICENSE.md" - fi - - # If the service has a CHANGELOG file, move it inside the service folder - if [ -f "${sdk_services_backup_dir}/${service}/CHANGELOG.md" ]; then - echo "Found ${service} \"CHANGELOG\" file" - cp -r "${sdk_services_backup_dir}/${service}/CHANGELOG.md" "${SERVICES_FOLDER}/${service}/CHANGELOG.md" - fi - - # If the service has a NOTICE file, move it inside the service folder - if [ -f "${sdk_services_backup_dir}/${service}/NOTICE.txt" ]; then - echo "Found ${service} \"NOTICE\" file" - cp -r "${sdk_services_backup_dir}/${service}/NOTICE.txt" "${SERVICES_FOLDER}/${service}/NOTICE.txt" - fi - - # If the service has a VERSION file, move it inside the service folder - if [ -f "${sdk_services_backup_dir}/${service}/VERSION" ]; then - echo "Found ${service} \"VERSION\" file" - cp -r "${sdk_services_backup_dir}/${service}/VERSION" "${SERVICES_FOLDER}/${service}/VERSION" - fi - - # If the service has oas_commit file, move it inside the service folder - if [ -f "${sdk_services_backup_dir}/${service}/oas_commit" ]; then - echo "Found ${service} \"oas_commit\" file" - cp -r "${sdk_services_backup_dir}/${service}/oas_commit" "${SERVICES_FOLDER}/${service}/oas_commit" - fi - - cd "${SERVICES_FOLDER}/${service}" - go work use . - # Make sure that dependencies are uptodate - go get -u ./... - go mod tidy - - return + if [ ! -f "${SERVICES_FOLDER}/${service}/go.mod" ]; then + printf "module ${GIT_HOST}/${GIT_USER_ID}/${GIT_REPO_ID}/services/${service}\n\n" > "${SERVICES_FOLDER}/${service}/go.mod" + printf "go ${SDK_GO_VERSION}\n\n" >> "${SERVICES_FOLDER}/${service}/go.mod" + printf "require (\n\tgithub.com/stackitcloud/stackit-sdk-go/core v0.21.1\n)\n" >> "${SERVICES_FOLDER}/${service}/go.mod" fi - # COMPAT LAYER - LEGACY !! - START + # generate package.go + printf "package ${service}\n" > "${SERVICES_FOLDER}/${service}/package.go" - # Download OpenAPI generator if not already downloaded - compat_layer_jar_path="${ROOT_DIR}/scripts/bin/openapi-generator-cli-go-compat-layer.jar" - if [ -e ${compat_layer_jar_path} ] && [ $(java -jar ${compat_layer_jar_path} version) == "6.6.0" ]; then - : + # If the service has a LICENSE file, move it inside the service folder + if [ -f "${sdk_services_backup_dir}/${service}/LICENSE.md" ]; then + echo "Found ${service} \"LICENSE\" file" + cp -r "${sdk_services_backup_dir}/${service}/LICENSE.md" "${SERVICES_FOLDER}/${service}/LICENSE.md" else - echo "Downloading OpenAPI generator (version 6.6.0) for generating the compatibility layer..." - mkdir -p "${ROOT_DIR}/scripts/bin" - wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/6.6.0/openapi-generator-cli-6.6.0.jar -O ${compat_layer_jar_path} --quiet - echo "Download done." - fi - - echo -e "\n>> Generating compatibility layer for \"${service}\" service..." - cd "${ROOT_DIR}" - - mkdir -p "${SERVICES_FOLDER}/${service}" - cp "${ROOT_DIR}/languages/golang/compat-layer/.openapi-generator-ignore" "${SERVICES_FOLDER}/${service}/.openapi-generator-ignore" - regional_api= - if grep -E "^$service$" ${ROOT_DIR}/languages/golang/compat-layer/regional-allowlist.txt; then - echo "Generating new regional api" - regional_api="regional_api" - fi - - # Run the compatibility-layer generator for Go - java -Dlog.level=${GENERATOR_LOG_LEVEL} -jar ${compat_layer_jar_path} generate \ - --generator-name go \ - --input-spec "${ROOT_DIR}/oas/legacy/${compat_layer_service_oas_name}.json" \ - --output "${SERVICES_FOLDER}/${service}" \ - --package-name "${service}" \ - --enable-post-process-file \ - --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,apiTests=false \ - --additional-properties=isGoSubmodule=true,enumClassPrefix=true,generateInterfaces=true,$regional_api \ - --http-user-agent "stackit-sdk-go/${service}" \ - --reserved-words-mappings type=types \ - --config "${ROOT_DIR}/languages/golang/compat-layer/openapi-generator-config.yml" - - # Remove unnecessary files - rm "${SERVICES_FOLDER}/${service}/.openapi-generator-ignore" - rm "${SERVICES_FOLDER}/${service}/.openapi-generator/FILES" - - # If there's a comment at the start of go.mod, copy it - go_mod_backup_path="${sdk_services_backup_dir}/${service}/go.mod" - if [ -f ${go_mod_backup_path} ]; then - go_mod_backup_first_line="$(head -n 1 ${go_mod_backup_path})" - is_comment_pattern="^\/\/" - if [[ ${go_mod_backup_first_line} =~ ${is_comment_pattern} ]]; then - echo "Found comment at the top of ${service}/go.mod" - go_mod_path="${SERVICES_FOLDER}/${service}/go.mod" - echo -e "${go_mod_backup_first_line}\n$(cat ${go_mod_path})" >${go_mod_path} - fi - fi - - # If the service has a wait package files, move them inside the service folder - if [ -d "${sdk_services_backup_dir}/${service}/wait" ]; then - echo "Found ${service} \"wait\" package" - cp -r "${sdk_services_backup_dir}/${service}/wait" "${SERVICES_FOLDER}/${service}/wait" - # deprecate legacy wait package - printf "// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead\npackage wait\n\n" > "${SERVICES_FOLDER}/${service}/wait/deprecation.go" + cp "${ROOT_DIR}/LICENSE.md" "${SERVICES_FOLDER}/${service}/LICENSE.md" fi # If the service has a CHANGELOG file, move it inside the service folder @@ -333,12 +231,6 @@ generate_go_service() { cp -r "${sdk_services_backup_dir}/${service}/CHANGELOG.md" "${SERVICES_FOLDER}/${service}/CHANGELOG.md" fi - # If the service has a LICENSE file, move it inside the service folder - if [ -f "${sdk_services_backup_dir}/${service}/LICENSE.md" ]; then - echo "Found ${service} \"LICENSE\" file" - cp -r "${sdk_services_backup_dir}/${service}/LICENSE.md" "${SERVICES_FOLDER}/${service}/LICENSE.md" - fi - # If the service has a NOTICE file, move it inside the service folder if [ -f "${sdk_services_backup_dir}/${service}/NOTICE.txt" ]; then echo "Found ${service} \"NOTICE\" file" @@ -362,6 +254,4 @@ generate_go_service() { # Make sure that dependencies are uptodate go get -u ./... go mod tidy - - # COMPAT LAYER - LEGACY !! - END }