Skip to content

Commit 9dc770b

Browse files
authored
feat(golang): implement multi-version support (#237)
relates to STACKITSDK-294 and STACKITSDK-297
1 parent 68890e6 commit 9dc770b

25 files changed

+1875
-61
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
README.md
2+
git_push.sh
3+
.travis.yml
4+
.gitignore
5+
api/openapi.yaml

languages/golang/compat-layer/.openapi-generator-ignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
git_push.sh
22
.travis.yml
33
.gitignore
4-
#utils.go
54
README.md
65
response.go
76
api/openapi.yaml
@@ -12,4 +11,4 @@ setup.py
1211
test-requirements.txt
1312
requirements.txt
1413
tox.ini
15-
*/.github/*
14+
*/.github/*
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Transitional file to enable compatibility layer generation for selected services.
2+
# Note: It shouldn't be needed to add any services here!
3+
alb
4+
auditlog
5+
authorization
6+
cdn
7+
certificates
8+
dns
9+
edge
10+
git
11+
iaas
12+
intake
13+
kms
14+
loadbalancer
15+
logme
16+
logs
17+
mariadb
18+
modelserving
19+
mongodbflex
20+
objectstorage
21+
observability
22+
opensearch
23+
postgresflex
24+
rabbitmq
25+
redis
26+
resourcemanager
27+
runcommand
28+
scf
29+
secretsmanager
30+
serverbackup
31+
serverupdate
32+
serviceaccount
33+
serviceenablement
34+
sfs
35+
ske
36+
sqlserverflex

languages/golang/compat-layer/templates/api.mustache

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{>partial_header}}
2+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
23
package {{packageName}}
34

45
{{#operations}}
@@ -16,6 +17,7 @@ import (
1617

1718
{{#generateInterfaces}}
1819

20+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
1921
type {{classname}} interface {
2022
{{#operation}}
2123
/*
@@ -36,24 +38,21 @@ type {{classname}} interface {
3638
@param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}}
3739
@return {{{.}}}{{/returnType}}
3840

39-
{{#isDeprecated}}
40-
Deprecated: {{{unescapedNotes}}}
41-
{{/isDeprecated}}
41+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
4242
*/
4343
{{nickname}}Execute(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}{{^isResponseFile}}*{{/isResponseFile}}{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}} error)
4444
{{/operation}}
4545
}
4646

4747
{{#operation}}
48+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
4849
type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request interface {
4950
{{#allParams}}
5051
{{^isPathParam}}
5152
{{#description}}
5253
// {{.}}
5354
{{/description}}
54-
{{#isDeprecated}}
55-
// Deprecated
56-
{{/isDeprecated}}
55+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
5756
{{vendorExtensions.x-export-param-name}}({{paramName}} {{{dataType}}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request
5857
{{/isPathParam}}
5958
{{/allParams}}
@@ -64,9 +63,11 @@ type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/stru
6463
{{/generateInterfaces}}
6564

6665
// {{classname}}Service {{classname}} service
66+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
6767
type {{classname}}Service service
6868
{{#operation}}
6969

70+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
7071
type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request struct {
7172
ctx context.Context
7273
apiService *{{classname}}Service
@@ -80,10 +81,7 @@ type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request stru
8081
{{#description}}
8182
// {{.}}
8283
{{/description}}
83-
{{#isDeprecated}}
84-
// Deprecated
85-
{{/isDeprecated}}
86-
84+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
8785
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request) {{vendorExtensions.x-export-param-name}}({{paramName}} {{{dataType}}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request {
8886
r.{{paramName}} = {{^isFile}}&{{/isFile}}{{paramName}}
8987
return r
@@ -92,6 +90,7 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request)
9290
{{/isPathParam}}
9391
{{/allParams}}
9492

93+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
9594
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request) Execute() ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}{{^isResponseFile}}*{{/isResponseFile}}{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}} error) {
9695
var (
9796
localVarHTTPMethod = http.Method{{httpMethod}}
@@ -412,8 +411,8 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request)
412411
{{operationId}}: {{{summary}}}{{^summary}}Method for {{operationId}}{{/summary}}
413412
{{#notes}}
414413

415-
{{#isDeprecated}}Deprecated: {{/isDeprecated}}{{{unescapedNotes}}}
416414
{{/notes}}
415+
Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
417416

418417
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{{#pathParams}}
419418
@param {{paramName}}{{#description}} {{{.}}}{{/description}}{{/pathParams}}
@@ -429,11 +428,7 @@ func (a *APIClient) {{{nickname}}}(ctx context.Context{{#pathParams}}, {{paramNa
429428
}
430429
}
431430

432-
{{#isDeprecated}}
433-
/*
434-
Deprecated: {{{unescapedNotes}}}
435-
*/
436-
{{/isDeprecated}}
431+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
437432
func (a *APIClient) {{{nickname}}}Execute(ctx context.Context{{#pathParams}}, {{paramName}} {{{dataType}}}{{/pathParams}}) ({{#returnType}}{{^isArray}}{{^returnTypeIsPrimitive}}{{^isResponseFile}}*{{/isResponseFile}}{{/returnTypeIsPrimitive}}{{/isArray}}{{{.}}}, {{/returnType}} error){
438433
r := {{#structPrefix}}{{&classname}}{{/structPrefix}}{{operationId}}Request{
439434
apiService: a.defaultApi,

languages/golang/compat-layer/templates/client.mustache

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{>partial_header}}
2+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
23
package {{packageName}}
34

45
import (
@@ -38,18 +39,21 @@ var (
3839

3940
// APIClient manages communication with the {{appName}} API v{{version}}
4041
// In most cases there should be only one, shared, APIClient.
42+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
4143
type APIClient struct {
4244
cfg *config.Configuration
4345
common service // Reuse a single struct instead of allocating one for each service on the heap.
4446
defaultApi *DefaultApiService
4547
}
4648

49+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
4750
type service struct {
4851
client DefaultApi
4952
}
5053

5154
// NewAPIClient creates a new API client.
5255
// Optionally receives configuration options
56+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
5357
func NewAPIClient(opts ...config.ConfigurationOption) (*APIClient, error) {
5458
cfg := NewConfiguration()
5559
@@ -146,6 +150,7 @@ func typeCheckParameter(obj interface{}, expected string, name string) error {
146150
return nil
147151
}
148152

153+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
149154
func ParameterValueToString( obj interface{}, key string ) string {
150155
if reflect.TypeOf(obj).Kind() != reflect.Ptr {
151156
return fmt.Sprintf("%v", obj)
@@ -284,6 +289,7 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
284289

285290
// Allow modification of underlying config for alternate implementations and testing
286291
// Caution: modifying the configuration while live can cause data races and potentially unwanted behavior
292+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
287293
func (c *APIClient) GetConfig() *config.Configuration {
288294
return c.cfg
289295
}
@@ -640,6 +646,7 @@ func parseCacheControl(headers http.Header) cacheControl {
640646
}
641647

642648
// CacheExpires helper function to determine remaining time before repeating a request.
649+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
643650
func CacheExpires(r *http.Response) time.Time {
644651
// Figure out when the cache expires.
645652
var expires time.Time
@@ -670,4 +677,4 @@ func CacheExpires(r *http.Response) time.Time {
670677

671678
func strlen(s string) int {
672679
return utf8.RuneCountInString(s)
673-
}
680+
}

languages/golang/compat-layer/templates/configuration.mustache

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{{>partial_header}}
2+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
23
package {{packageName}}
34

45
import (
56
"github.com/stackitcloud/stackit-sdk-go/core/config"
67
)
78

89
// NewConfiguration returns a new Configuration object
10+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
911
func NewConfiguration() *config.Configuration {
1012
cfg := &config.Configuration{
1113
DefaultHeader: make(map[string]string),
@@ -89,4 +91,4 @@ func NewConfiguration() *config.Configuration {
8991
{{/apiInfo}}
9092
}
9193
return cfg
92-
}
94+
}

languages/golang/compat-layer/templates/model.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{>partial_header}}
2+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
23
package {{packageName}}
34

45
{{#models}}

languages/golang/compat-layer/templates/model_anyof.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// {{classname}} {{{description}}}{{^description}}struct for {{{classname}}}{{/description}}
2+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
23
type {{classname}} struct {
34
{{#anyOf}}
45
{{{.}}} *{{{.}}}
56
{{/anyOf}}
67
}
78

89
// Unmarshal JSON data into any of the pointers in the struct
10+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
911
func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
1012
var err error
1113
{{#isNullable}}
@@ -63,6 +65,7 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
6365
}
6466

6567
// Marshal data from the first non-nil pointers in the struct to JSON
68+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
6669
func (src *{{classname}}) MarshalJSON() ([]byte, error) {
6770
{{#anyOf}}
6871
if src.{{{.}}} != nil {

languages/golang/compat-layer/templates/model_enum.mustache

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// {{{classname}}} {{{description}}}{{^description}}the model '{{{classname}}}'{{/description}}
2+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
23
type {{{classname}}} {{dataType}}
34

45
// List of {{{name}}}
@@ -7,12 +8,14 @@ const (
78
{{#enumVars}}
89
{{^-first}}
910
{{/-first}}
11+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
1012
{{{classname.toUpperCase}}}_{{name}} {{{classname}}} = {{{value}}}
1113
{{/enumVars}}
1214
{{/allowableValues}}
1315
)
1416

1517
// All allowed values of {{{classname}}} enum
18+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
1619
var Allowed{{{classname}}}EnumValues = []{{{classname}}}{
1720
{{#allowableValues}}
1821
{{#enumVars}}
@@ -21,6 +24,7 @@ var Allowed{{{classname}}}EnumValues = []{{{classname}}}{
2124
{{/allowableValues}}
2225
}
2326

27+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
2428
func (v *{{{classname}}}) UnmarshalJSON(src []byte) error {
2529
var value {{dataType}}
2630
err := json.Unmarshal(src, &value)
@@ -45,6 +49,7 @@ func (v *{{{classname}}}) UnmarshalJSON(src []byte) error {
4549

4650
// New{{{classname}}}FromValue returns a pointer to a valid {{{classname}}}
4751
// for the value passed as argument, or an error if the value passed is not allowed by the enum
52+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
4853
func New{{{classname}}}FromValue(v {{dataType}}) (*{{{classname}}}, error) {
4954
ev := {{{classname}}}(v)
5055
if ev.IsValid() {
@@ -55,6 +60,7 @@ func New{{{classname}}}FromValue(v {{dataType}}) (*{{{classname}}}, error) {
5560
}
5661

5762
// IsValid return true if the value is valid for the enum, false otherwise
63+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
5864
func (v {{{classname}}}) IsValid() bool {
5965
for _, existing := range Allowed{{{classname}}}EnumValues {
6066
if existing == v {
@@ -65,41 +71,50 @@ func (v {{{classname}}}) IsValid() bool {
6571
}
6672

6773
// Ptr returns reference to {{{name}}} value
74+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
6875
func (v {{{classname}}}) Ptr() *{{{classname}}} {
6976
return &v
7077
}
7178

79+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
7280
type Nullable{{{classname}}} struct {
7381
value *{{{classname}}}
7482
isSet bool
7583
}
7684

85+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
7786
func (v Nullable{{classname}}) Get() *{{classname}} {
7887
return v.value
7988
}
8089

90+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
8191
func (v *Nullable{{classname}}) Set(val *{{classname}}) {
8292
v.value = val
8393
v.isSet = true
8494
}
8595

96+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
8697
func (v Nullable{{classname}}) IsSet() bool {
8798
return v.isSet
8899
}
89100

101+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
90102
func (v *Nullable{{classname}}) Unset() {
91103
v.value = nil
92104
v.isSet = false
93105
}
94106

107+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
95108
func NewNullable{{classname}}(val *{{classname}}) *Nullable{{classname}} {
96109
return &Nullable{{classname}}{value: val, isSet: true}
97110
}
98111

112+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
99113
func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) {
100114
return json.Marshal(v.value)
101115
}
102116

117+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
103118
func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error {
104119
v.isSet = true
105120
return json.Unmarshal(src, &v.value)

languages/golang/compat-layer/templates/model_oneof.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// {{classname}} - {{{description}}}{{^description}}struct for {{{classname}}}{{/description}}
2+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
23
type {{classname}} struct {
34
{{#oneOf}}
45
{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} *{{{.}}}
@@ -7,6 +8,7 @@ type {{classname}} struct {
78

89
{{#oneOf}}
910
// {{{.}}}As{{classname}} is a convenience function that returns {{{.}}} wrapped in {{classname}}
11+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
1012
func {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}As{{classname}}(v *{{{.}}}) {{classname}} {
1113
return {{classname}}{
1214
{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}: v,
@@ -16,6 +18,7 @@ func {{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}}As{{classname}}(v *{
1618
{{/oneOf}}
1719

1820
// Unmarshal JSON data into one of the pointers in the struct
21+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
1922
func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
2023
var err error
2124
{{#isNullable}}
@@ -130,6 +133,7 @@ func (dst *{{classname}}) UnmarshalJSON(data []byte) error {
130133

131134
// Marshal data from the first non-nil pointers in the struct to JSON
132135
func (src {{classname}}) MarshalJSON() ([]byte, error) {
136+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
133137
{{#oneOf}}
134138
if src.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}} != nil {
135139
return json.Marshal(&src.{{#lambda.type-to-name}}{{{.}}}{{/lambda.type-to-name}})
@@ -140,6 +144,7 @@ func (src {{classname}}) MarshalJSON() ([]byte, error) {
140144
}
141145

142146
// Get the actual instance
147+
// Deprecated: Will be removed after 2026-09-30. Move to the packages generated for each available API version instead
143148
func (obj *{{classname}}) GetActualInstance() (interface{}) {
144149
if obj == nil {
145150
return nil

0 commit comments

Comments
 (0)