From a27ffa48f9d939579a13c27b987c7068ae4f0ad2 Mon Sep 17 00:00:00 2001 From: Carlo Goetz Date: Fri, 12 Jun 2026 10:35:40 +0200 Subject: [PATCH 1/6] feat(go): patch iaas/AreaID after generation to fix oneOf regex issue STACKITSDK-226 --- CustomRegionGenerator.java | 198 +++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) diff --git a/CustomRegionGenerator.java b/CustomRegionGenerator.java index 160fda5..8b03089 100644 --- a/CustomRegionGenerator.java +++ b/CustomRegionGenerator.java @@ -5,6 +5,11 @@ import org.openapitools.codegen.CodegenParameter; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; +import java.security.MessageDigest; +import java.util.Arrays; import java.util.Set; import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.parameters.Parameter; @@ -68,4 +73,197 @@ private boolean isRegionField(String name) { } return name.equalsIgnoreCase("region") || name.equalsIgnoreCase("regionId"); } + private final byte[] IAAS_AREA_ID_HASH = {-73, 66, 84, 86, -60, 99, 59, 46, -116, 10, 97, -23, -85, 59, 87, -98}; + private final String IAAS_AREA_ID_PATCHED = """ +/* +STACKIT IaaS API + +This API allows you to create and modify IaaS resources. + +API version: 2 +Contact: stackit-iaas@mail.schwarz +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v2api + +import ( + "encoding/json" + "fmt" + "regexp" +) + +// AreaId - The identifier (ID) of an area. +type AreaId struct { + StaticAreaID *StaticAreaID + String *string +} + +// StaticAreaIDAsAreaId is a convenience function that returns StaticAreaID wrapped in AreaId +func StaticAreaIDAsAreaId(v *StaticAreaID) AreaId { + return AreaId{ + StaticAreaID: v, + } +} + +// stringAsAreaId is a convenience function that returns string wrapped in AreaId +func StringAsAreaId(v *string) AreaId { + return AreaId{ + String: v, + } +} + +// Unmarshal JSON data into one of the pointers in the struct +func (dst *AreaId) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into StaticAreaID + err = json.Unmarshal(data, &dst.StaticAreaID) + if err == nil { + jsonStaticAreaID, _ := json.Marshal(dst.StaticAreaID) + if string(jsonStaticAreaID) == "{}" { // empty struct + dst.StaticAreaID = nil + } else { + match++ + } + } else { + dst.StaticAreaID = nil + } + + // try to unmarshal data into String + err = json.Unmarshal(data, &dst.String) + if err == nil { + jsonString, _ := json.Marshal(dst.String) + regex := `/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/` + 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(*dstAreaId1.String, "$1") // Remove quotes + isMatched, _ := regexp.MatchString(regex, rawString) + if string(jsonString) != "{}" && isMatched { // empty struct + dst.String = nil + } else { + match++ + } + } else { + dst.String = nil + } + + if match > 1 { // more than 1 match + // reset to nil + dst.StaticAreaID = nil + dst.String = nil + + return fmt.Errorf("data matches more than one schema in oneOf(AreaId)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(AreaId)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src AreaId) MarshalJSON() ([]byte, error) { + if src.StaticAreaID != nil { + return json.Marshal(&src.StaticAreaID) + } + + if src.String != nil { + return json.Marshal(&src.String) + } + + return nil, nil // no data in oneOf schemas +} + +// Get the actual instance +func (obj *AreaId) GetActualInstance() interface{} { + if obj == nil { + return nil + } + if obj.StaticAreaID != nil { + return obj.StaticAreaID + } + + if obj.String != nil { + return obj.String + } + + // all schemas are nil + return nil +} + +// Get the actual instance value +func (obj AreaId) GetActualInstanceValue() interface{} { + if obj.StaticAreaID != nil { + return *obj.StaticAreaID + } + + if obj.String != nil { + return *obj.String + } + + // all schemas are nil + return nil +} + +type NullableAreaId struct { + value *AreaId + isSet bool +} + +func (v NullableAreaId) Get() *AreaId { + return v.value +} + +func (v *NullableAreaId) Set(val *AreaId) { + v.value = val + v.isSet = true +} + +func (v NullableAreaId) IsSet() bool { + return v.isSet +} + +func (v *NullableAreaId) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAreaId(val *AreaId) *NullableAreaId { + return &NullableAreaId{value: val, isSet: true} +} + +func (v NullableAreaId) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAreaId) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} +"""; + + @Override + public void postProcessFile(File file, String fileType) { + if (file.getAbsolutePath().endsWith("iaas/v2api/model_area_id.go")) { + try { + var content = Files.readAllBytes(file.toPath()); + var digest = MessageDigest.getInstance("MD5"); + var hash = digest.digest(content); + if (Arrays.equals(hash, IAAS_AREA_ID_HASH)) { + Files.writeString(file.toPath(), IAAS_AREA_ID_PATCHED, StandardOpenOption.TRUNCATE_EXISTING); + } else { + throw new IllegalStateException( + "expected iaas/v2api/model_area_id.go to hash to " + + Arrays.toString(IAAS_AREA_ID_HASH) + " but got " + Arrays.toString(hash) + + "\nedit CustomRegionGenerator.java in the sdk-generator and update IAAS_AREA_ID_HASH" + + "to accept this change" + ); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + super.postProcessFile(file, fileType); + } } From 7956e39ad412a8ada8ea25fb5c31a51e85250095 Mon Sep 17 00:00:00 2001 From: Carlo Goetz Date: Thu, 25 Jun 2026 09:51:36 +0200 Subject: [PATCH 2/6] feat(go): make file overrides configurable, add iaas overrides --- CustomRegionGenerator.java | 237 +++++------------- .../golang/overrides/overrides.properties | 11 + .../golang/overrides/v1api_model_area_id.go | 164 ++++++++++++ .../golang/overrides/v2api_model_area_id.go | 163 ++++++++++++ .../golang/overrides/v2beta_model_area_id.go | 163 ++++++++++++ scripts/generate-sdk/languages/go.sh | 3 +- 6 files changed, 565 insertions(+), 176 deletions(-) create mode 100644 languages/golang/overrides/overrides.properties create mode 100644 languages/golang/overrides/v1api_model_area_id.go create mode 100644 languages/golang/overrides/v2api_model_area_id.go create mode 100644 languages/golang/overrides/v2beta_model_area_id.go diff --git a/CustomRegionGenerator.java b/CustomRegionGenerator.java index 8b03089..932de41 100644 --- a/CustomRegionGenerator.java +++ b/CustomRegionGenerator.java @@ -6,15 +6,27 @@ import org.openapitools.codegen.CodegenParameter; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.security.MessageDigest; -import java.util.Arrays; +import java.util.HashMap; +import java.util.HexFormat; +import java.util.List; +import java.util.Map; +import java.util.Properties; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.parameters.Parameter; public class CustomRegionGenerator extends GoClientCodegen { + private final static String NAMESPACE = "cloud/stackit/codegen/"; + private final Map overrides; @Override public String getName() { @@ -25,6 +37,14 @@ public String getName() { public CustomRegionGenerator() { super(); System.out.println("=== CUSTOM GO CLIENT GENERATOR INITIALIZED ==="); + try { + overrides = OverrideConfig.load().stream().collect(Collectors.toMap( + o -> o.path, + Function.identity() + )); + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override @@ -73,189 +93,27 @@ private boolean isRegionField(String name) { } return name.equalsIgnoreCase("region") || name.equalsIgnoreCase("regionId"); } - private final byte[] IAAS_AREA_ID_HASH = {-73, 66, 84, 86, -60, 99, 59, 46, -116, 10, 97, -23, -85, 59, 87, -98}; - private final String IAAS_AREA_ID_PATCHED = """ -/* -STACKIT IaaS API - -This API allows you to create and modify IaaS resources. - -API version: 2 -Contact: stackit-iaas@mail.schwarz -*/ - -// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. - -package v2api - -import ( - "encoding/json" - "fmt" - "regexp" -) - -// AreaId - The identifier (ID) of an area. -type AreaId struct { - StaticAreaID *StaticAreaID - String *string -} - -// StaticAreaIDAsAreaId is a convenience function that returns StaticAreaID wrapped in AreaId -func StaticAreaIDAsAreaId(v *StaticAreaID) AreaId { - return AreaId{ - StaticAreaID: v, - } -} - -// stringAsAreaId is a convenience function that returns string wrapped in AreaId -func StringAsAreaId(v *string) AreaId { - return AreaId{ - String: v, - } -} - -// Unmarshal JSON data into one of the pointers in the struct -func (dst *AreaId) UnmarshalJSON(data []byte) error { - var err error - match := 0 - // try to unmarshal data into StaticAreaID - err = json.Unmarshal(data, &dst.StaticAreaID) - if err == nil { - jsonStaticAreaID, _ := json.Marshal(dst.StaticAreaID) - if string(jsonStaticAreaID) == "{}" { // empty struct - dst.StaticAreaID = nil - } else { - match++ - } - } else { - dst.StaticAreaID = nil - } - - // try to unmarshal data into String - err = json.Unmarshal(data, &dst.String) - if err == nil { - jsonString, _ := json.Marshal(dst.String) - regex := `/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/` - 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(*dstAreaId1.String, "$1") // Remove quotes - isMatched, _ := regexp.MatchString(regex, rawString) - if string(jsonString) != "{}" && isMatched { // empty struct - dst.String = nil - } else { - match++ - } - } else { - dst.String = nil - } - - if match > 1 { // more than 1 match - // reset to nil - dst.StaticAreaID = nil - dst.String = nil - - return fmt.Errorf("data matches more than one schema in oneOf(AreaId)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(AreaId)") - } -} - -// Marshal data from the first non-nil pointers in the struct to JSON -func (src AreaId) MarshalJSON() ([]byte, error) { - if src.StaticAreaID != nil { - return json.Marshal(&src.StaticAreaID) - } - - if src.String != nil { - return json.Marshal(&src.String) - } - - return nil, nil // no data in oneOf schemas -} - -// Get the actual instance -func (obj *AreaId) GetActualInstance() interface{} { - if obj == nil { - return nil - } - if obj.StaticAreaID != nil { - return obj.StaticAreaID - } - - if obj.String != nil { - return obj.String - } - - // all schemas are nil - return nil -} - -// Get the actual instance value -func (obj AreaId) GetActualInstanceValue() interface{} { - if obj.StaticAreaID != nil { - return *obj.StaticAreaID - } - - if obj.String != nil { - return *obj.String - } - - // all schemas are nil - return nil -} - -type NullableAreaId struct { - value *AreaId - isSet bool -} - -func (v NullableAreaId) Get() *AreaId { - return v.value -} - -func (v *NullableAreaId) Set(val *AreaId) { - v.value = val - v.isSet = true -} - -func (v NullableAreaId) IsSet() bool { - return v.isSet -} - -func (v *NullableAreaId) Unset() { - v.value = nil - v.isSet = false -} - -func NewNullableAreaId(val *AreaId) *NullableAreaId { - return &NullableAreaId{value: val, isSet: true} -} - -func (v NullableAreaId) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *NullableAreaId) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} -"""; @Override public void postProcessFile(File file, String fileType) { - if (file.getAbsolutePath().endsWith("iaas/v2api/model_area_id.go")) { + var path = file.getAbsolutePath(); + var servicesIdx = path.indexOf("/services/"); + var subPath = path.substring(servicesIdx + "/services/".length()); + if (overrides.containsKey(subPath)) { + var override = overrides.get(subPath); try { var content = Files.readAllBytes(file.toPath()); var digest = MessageDigest.getInstance("MD5"); - var hash = digest.digest(content); - if (Arrays.equals(hash, IAAS_AREA_ID_HASH)) { - Files.writeString(file.toPath(), IAAS_AREA_ID_PATCHED, StandardOpenOption.TRUNCATE_EXISTING); + var hex = HexFormat.of(); + var hash = hex.formatHex(digest.digest(content)); + if (hash.equals(override.hash)) { + var replacementPath = Path.of(Thread.currentThread().getContextClassLoader().getResource(NAMESPACE + override.replacementPath).getPath()); + var replacementContent = Files.readAllBytes(replacementPath); + Files.write(file.toPath(), replacementContent, StandardOpenOption.TRUNCATE_EXISTING); } else { throw new IllegalStateException( "expected iaas/v2api/model_area_id.go to hash to " + - Arrays.toString(IAAS_AREA_ID_HASH) + " but got " + Arrays.toString(hash) + + override.hash + " but got " + hash + "\nedit CustomRegionGenerator.java in the sdk-generator and update IAAS_AREA_ID_HASH" + "to accept this change" ); @@ -266,4 +124,33 @@ public void postProcessFile(File file, String fileType) { } super.postProcessFile(file, fileType); } + + private static class OverrideConfig { + public String name; + public String path; + public String replacementPath; + public String hash; + + public static List load() throws IOException { + var path = Thread.currentThread().getContextClassLoader().getResource(NAMESPACE + "overrides.properties").getPath(); + var overrideProps = new Properties(); + overrideProps.load(new FileInputStream(path)); + var byName = new HashMap(); + overrideProps.stringPropertyNames().forEach(key -> { + var prefixLen = key.indexOf('.'); + var prefix = key.substring(0, prefixLen); + var config = byName.computeIfAbsent(prefix, (_) -> new OverrideConfig()); + config.name = prefix; + var suffix = key.substring(prefixLen + 1); + switch (suffix) { + case "path" -> config.path = overrideProps.getProperty(key); + case "replacementPath" -> config.replacementPath = overrideProps.getProperty(key); + case "hash" -> config.hash = overrideProps.getProperty(key); + default -> throw new IllegalStateException("unexpected suffix: " + suffix); + } + }); + return byName.values().stream().toList(); + } + } + } diff --git a/languages/golang/overrides/overrides.properties b/languages/golang/overrides/overrides.properties new file mode 100644 index 0000000..58a7a15 --- /dev/null +++ b/languages/golang/overrides/overrides.properties @@ -0,0 +1,11 @@ +iaasV2ApiAreaId.path=iaas/v2api/model_area_id.go +iaasV2ApiAreaId.replacementPath=v2api_model_area_id.go +iaasV2ApiAreaId.hash=b7425456c4633b2e8c0a61e9ab3b579e + +iaasV1ApiAreaId.path=iaas/v1api/model_area_id.go +iaasV1ApiAreaId.replacementPath=v1api_model_area_id.go +iaasV1ApiAreaId.hash=a9d72364fec0794cab3b51f3680de584 + +iaasV2BetaApiAreaId.path="iaas/v2beta1api/model_area_id.go +iaasV2BetaApiAreaId.replacementPath=v2beta_model_area_id.go +iaasV2BetaApiAreaId.hash=bb5583419348ee95ebbde0b4133a36f0 diff --git a/languages/golang/overrides/v1api_model_area_id.go b/languages/golang/overrides/v1api_model_area_id.go new file mode 100644 index 0000000..7dab3f9 --- /dev/null +++ b/languages/golang/overrides/v1api_model_area_id.go @@ -0,0 +1,164 @@ +/* +STACKIT IaaS API + +This API is deprecated. It will be retired on 01.03.2027. Please use the STACKIT IaaS API V2 instead. + +API version: 1 +Contact: stackit-iaas@mail.schwarz +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1api + +import ( + "encoding/json" + "fmt" + "regexp" +) + +// AreaId - The identifier (ID) of an area. +type AreaId struct { + StaticAreaID *StaticAreaID + String *string +} + +// StaticAreaIDAsAreaId is a convenience function that returns StaticAreaID wrapped in AreaId +func StaticAreaIDAsAreaId(v *StaticAreaID) AreaId { + return AreaId{ + StaticAreaID: v, + } +} + +// stringAsAreaId is a convenience function that returns string wrapped in AreaId +func StringAsAreaId(v *string) AreaId { + return AreaId{ + String: v, + } +} + +// Unmarshal JSON data into one of the pointers in the struct +func (dst *AreaId) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into StaticAreaID + err = json.Unmarshal(data, &dst.StaticAreaID) + if err == nil { + jsonStaticAreaID, _ := json.Marshal(dst.StaticAreaID) + if string(jsonStaticAreaID) == "{}" { // empty struct + dst.StaticAreaID = nil + } else { + match++ + } + } else { + dst.StaticAreaID = nil + } + + // try to unmarshal data into String + err = json.Unmarshal(data, &dst.String) + if err == nil { + jsonString, _ := json.Marshal(dst.String) + regex := `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` + isMatched, _ := regexp.MatchString(regex, *dst.String) + if string(jsonString) != "{}" && isMatched { // empty struct + match++ + } else { + dst.String = nil + } + } else { + dst.String = nil + } + + if match > 1 { // more than 1 match + // reset to nil + dst.StaticAreaID = nil + dst.String = nil + + return fmt.Errorf("data matches more than one schema in oneOf(AreaId)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(AreaId)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src AreaId) MarshalJSON() ([]byte, error) { + if src.StaticAreaID != nil { + return json.Marshal(&src.StaticAreaID) + } + + if src.String != nil { + return json.Marshal(&src.String) + } + + return nil, nil // no data in oneOf schemas +} + +// Get the actual instance +func (obj *AreaId) GetActualInstance() interface{} { + if obj == nil { + return nil + } + if obj.StaticAreaID != nil { + return obj.StaticAreaID + } + + if obj.String != nil { + return obj.String + } + + // all schemas are nil + return nil +} + +// Get the actual instance value +func (obj AreaId) GetActualInstanceValue() interface{} { + if obj.StaticAreaID != nil { + return *obj.StaticAreaID + } + + if obj.String != nil { + return *obj.String + } + + // all schemas are nil + return nil +} + +type NullableAreaId struct { + value *AreaId + isSet bool +} + +func (v NullableAreaId) Get() *AreaId { + return v.value +} + +func (v *NullableAreaId) Set(val *AreaId) { + v.value = val + v.isSet = true +} + +func (v NullableAreaId) IsSet() bool { + return v.isSet +} + +func (v *NullableAreaId) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAreaId(val *AreaId) *NullableAreaId { + return &NullableAreaId{value: val, isSet: true} +} + +func (v NullableAreaId) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAreaId) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + diff --git a/languages/golang/overrides/v2api_model_area_id.go b/languages/golang/overrides/v2api_model_area_id.go new file mode 100644 index 0000000..5159f8b --- /dev/null +++ b/languages/golang/overrides/v2api_model_area_id.go @@ -0,0 +1,163 @@ +/* +STACKIT IaaS API + +This API allows you to create and modify IaaS resources. + +API version: 2 +Contact: stackit-iaas@mail.schwarz +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v2api + +import ( + "encoding/json" + "fmt" + "regexp" +) + +// AreaId - The identifier (ID) of an area. +type AreaId struct { + StaticAreaID *StaticAreaID + String *string +} + +// StaticAreaIDAsAreaId is a convenience function that returns StaticAreaID wrapped in AreaId +func StaticAreaIDAsAreaId(v *StaticAreaID) AreaId { + return AreaId{ + StaticAreaID: v, + } +} + +// stringAsAreaId is a convenience function that returns string wrapped in AreaId +func StringAsAreaId(v *string) AreaId { + return AreaId{ + String: v, + } +} + +// Unmarshal JSON data into one of the pointers in the struct +func (dst *AreaId) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into StaticAreaID + err = json.Unmarshal(data, &dst.StaticAreaID) + if err == nil { + jsonStaticAreaID, _ := json.Marshal(dst.StaticAreaID) + if string(jsonStaticAreaID) == "{}" { // empty struct + dst.StaticAreaID = nil + } else { + match++ + } + } else { + dst.StaticAreaID = nil + } + + // try to unmarshal data into String + err = json.Unmarshal(data, &dst.String) + if err == nil { + jsonString, _ := json.Marshal(dst.String) + regex := `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` + isMatched, _ := regexp.MatchString(regex, *dst.String) + if string(jsonString) != "{}" && isMatched { // empty struct + match++ + } else { + dst.String = nil + } + } else { + dst.String = nil + } + + if match > 1 { // more than 1 match + // reset to nil + dst.StaticAreaID = nil + dst.String = nil + + return fmt.Errorf("data matches more than one schema in oneOf(AreaId)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(AreaId)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src AreaId) MarshalJSON() ([]byte, error) { + if src.StaticAreaID != nil { + return json.Marshal(&src.StaticAreaID) + } + + if src.String != nil { + return json.Marshal(&src.String) + } + + return nil, nil // no data in oneOf schemas +} + +// Get the actual instance +func (obj *AreaId) GetActualInstance() interface{} { + if obj == nil { + return nil + } + if obj.StaticAreaID != nil { + return obj.StaticAreaID + } + + if obj.String != nil { + return obj.String + } + + // all schemas are nil + return nil +} + +// Get the actual instance value +func (obj AreaId) GetActualInstanceValue() interface{} { + if obj.StaticAreaID != nil { + return *obj.StaticAreaID + } + + if obj.String != nil { + return *obj.String + } + + // all schemas are nil + return nil +} + +type NullableAreaId struct { + value *AreaId + isSet bool +} + +func (v NullableAreaId) Get() *AreaId { + return v.value +} + +func (v *NullableAreaId) Set(val *AreaId) { + v.value = val + v.isSet = true +} + +func (v NullableAreaId) IsSet() bool { + return v.isSet +} + +func (v *NullableAreaId) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAreaId(val *AreaId) *NullableAreaId { + return &NullableAreaId{value: val, isSet: true} +} + +func (v NullableAreaId) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAreaId) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/languages/golang/overrides/v2beta_model_area_id.go b/languages/golang/overrides/v2beta_model_area_id.go new file mode 100644 index 0000000..f7bcd61 --- /dev/null +++ b/languages/golang/overrides/v2beta_model_area_id.go @@ -0,0 +1,163 @@ +/* +STACKIT IaaS API + +This API allows you to create and modify IaaS resources. + +API version: 2beta1 +Contact: stackit-iaas@mail.schwarz +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v2beta1api + +import ( + "encoding/json" + "fmt" + "regexp" +) + +// AreaId - The identifier (ID) of an area. +type AreaId struct { + StaticAreaID *StaticAreaID + String *string +} + +// StaticAreaIDAsAreaId is a convenience function that returns StaticAreaID wrapped in AreaId +func StaticAreaIDAsAreaId(v *StaticAreaID) AreaId { + return AreaId{ + StaticAreaID: v, + } +} + +// stringAsAreaId is a convenience function that returns string wrapped in AreaId +func StringAsAreaId(v *string) AreaId { + return AreaId{ + String: v, + } +} + +// Unmarshal JSON data into one of the pointers in the struct +func (dst *AreaId) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into StaticAreaID + err = json.Unmarshal(data, &dst.StaticAreaID) + if err == nil { + jsonStaticAreaID, _ := json.Marshal(dst.StaticAreaID) + regex := `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` + isMatched, _ := regexp.MatchString(regex, string(*dst.StaticAreaID)) + if string(jsonStaticAreaID) != "{}" && isMatched { // empty struct + match++ + } else { + dst.StaticAreaID = nil + } + } else { + dst.StaticAreaID = nil + } + + // try to unmarshal data into String + err = json.Unmarshal(data, &dst.String) + if err == nil { + jsonString, _ := json.Marshal(dst.String) + if string(jsonString) == "{}" { // empty struct + dst.String = nil + } else { + match++ + } + } else { + dst.String = nil + } + + if match > 1 { // more than 1 match + // reset to nil + dst.StaticAreaID = nil + dst.String = nil + + return fmt.Errorf("data matches more than one schema in oneOf(AreaId)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(AreaId)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src AreaId) MarshalJSON() ([]byte, error) { + if src.StaticAreaID != nil { + return json.Marshal(&src.StaticAreaID) + } + + if src.String != nil { + return json.Marshal(&src.String) + } + + return nil, nil // no data in oneOf schemas +} + +// Get the actual instance +func (obj *AreaId) GetActualInstance() interface{} { + if obj == nil { + return nil + } + if obj.StaticAreaID != nil { + return obj.StaticAreaID + } + + if obj.String != nil { + return obj.String + } + + // all schemas are nil + return nil +} + +// Get the actual instance value +func (obj AreaId) GetActualInstanceValue() interface{} { + if obj.StaticAreaID != nil { + return *obj.StaticAreaID + } + + if obj.String != nil { + return *obj.String + } + + // all schemas are nil + return nil +} + +type NullableAreaId struct { + value *AreaId + isSet bool +} + +func (v NullableAreaId) Get() *AreaId { + return v.value +} + +func (v *NullableAreaId) Set(val *AreaId) { + v.value = val + v.isSet = true +} + +func (v NullableAreaId) IsSet() bool { + return v.isSet +} + +func (v *NullableAreaId) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAreaId(val *AreaId) *NullableAreaId { + return &NullableAreaId{value: val, isSet: true} +} + +func (v NullableAreaId) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAreaId) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/scripts/generate-sdk/languages/go.sh b/scripts/generate-sdk/languages/go.sh index 87036fd..638c42b 100644 --- a/scripts/generate-sdk/languages/go.sh +++ b/scripts/generate-sdk/languages/go.sh @@ -111,7 +111,8 @@ generate_go_sdk() { cd ${ROOT_DIR} mkdir -p custom/cloud/stackit/codegen javac -cp "${GENERATOR_JAR_PATH}" CustomRegionGenerator.java - mv CustomRegionGenerator.class custom/cloud/stackit/codegen/CustomRegionGenerator.class + mv ./*.class custom/cloud/stackit/codegen + cp languages/golang/overrides/* custom/cloud/stackit/codegen warning="" From a9a6f6b322fd7a2de44fb5f39bd8aba5fba498c4 Mon Sep 17 00:00:00 2001 From: Carlo Goetz Date: Thu, 25 Jun 2026 10:14:44 +0200 Subject: [PATCH 3/6] fix(ci): bump java version --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d16065e..198afeb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,7 +4,7 @@ on: [pull_request, workflow_dispatch] env: GO_VERSION_BUILD: "1.25" - JAVA_VERSION: "11" + JAVA_VERSION: "25" jobs: main-go: From 6ea4534f66f6ea429e40f4945e00d58105912f4c Mon Sep 17 00:00:00 2001 From: Carlo Goetz Date: Fri, 17 Jul 2026 16:01:44 +0200 Subject: [PATCH 4/6] feat(generator): rework custom generators, support java overrides --- CustomRegionGenerator.java | 156 --------- scripts/generate-sdk/languages/go.sh | 10 +- scripts/generate-sdk/languages/java.sh | 11 +- scripts/generators/GoGenerator.java | 80 +++++ scripts/generators/JavaGenerator.java | 24 ++ scripts/generators/README.md | 74 ++++ .../overrides/go}/overrides.properties | 0 .../overrides/go}/v1api_model_area_id.go | 0 .../overrides/go}/v2api_model_area_id.go | 0 .../overrides/go}/v2beta_model_area_id.go | 0 .../iaas_v2alpha_model_destinationCIDRv4.java | 331 ++++++++++++++++++ .../iaas_v2alpha_model_destinationCIDRv6.java | 331 ++++++++++++++++++ .../iaas_v2alpha_model_nexthopBlackhole.java | 302 ++++++++++++++++ .../java/iaas_v2alpha_model_nexthopIPv4.java | 331 ++++++++++++++++++ .../java/iaas_v2alpha_model_nexthopIPv6.java | 331 ++++++++++++++++++ .../iaas_v2alpha_model_nexthopInternet.java | 302 ++++++++++++++++ .../overrides/java/overrides.properties | 23 ++ .../shared/PostProcessFileReplace.java | 101 ++++++ 18 files changed, 2243 insertions(+), 164 deletions(-) delete mode 100644 CustomRegionGenerator.java create mode 100644 scripts/generators/GoGenerator.java create mode 100644 scripts/generators/JavaGenerator.java create mode 100644 scripts/generators/README.md rename {languages/golang/overrides => scripts/generators/overrides/go}/overrides.properties (100%) rename {languages/golang/overrides => scripts/generators/overrides/go}/v1api_model_area_id.go (100%) rename {languages/golang/overrides => scripts/generators/overrides/go}/v2api_model_area_id.go (100%) rename {languages/golang/overrides => scripts/generators/overrides/go}/v2beta_model_area_id.go (100%) create mode 100644 scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv4.java create mode 100644 scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv6.java create mode 100644 scripts/generators/overrides/java/iaas_v2alpha_model_nexthopBlackhole.java create mode 100644 scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv4.java create mode 100644 scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv6.java create mode 100644 scripts/generators/overrides/java/iaas_v2alpha_model_nexthopInternet.java create mode 100644 scripts/generators/overrides/java/overrides.properties create mode 100644 scripts/generators/shared/PostProcessFileReplace.java diff --git a/CustomRegionGenerator.java b/CustomRegionGenerator.java deleted file mode 100644 index 932de41..0000000 --- a/CustomRegionGenerator.java +++ /dev/null @@ -1,156 +0,0 @@ -package cloud.stackit.codegen; - -import org.openapitools.codegen.CodegenProperty; -import org.openapitools.codegen.languages.GoClientCodegen; - -import org.openapitools.codegen.CodegenParameter; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardOpenOption; -import java.security.MessageDigest; -import java.util.HashMap; -import java.util.HexFormat; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; - -import io.swagger.v3.oas.models.media.Schema; -import io.swagger.v3.oas.models.parameters.Parameter; - -public class CustomRegionGenerator extends GoClientCodegen { - private final static String NAMESPACE = "cloud/stackit/codegen/"; - private final Map overrides; - - @Override - public String getName() { - // This is the name you will pass to the -g flag - return "cloud.stackit.codegen.CustomRegionGenerator"; - } - - public CustomRegionGenerator() { - super(); - System.out.println("=== CUSTOM GO CLIENT GENERATOR INITIALIZED ==="); - try { - overrides = OverrideConfig.load().stream().collect(Collectors.toMap( - o -> o.path, - Function.identity() - )); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public CodegenProperty fromProperty(String name, Schema p, boolean required) { - CodegenProperty property = super.fromProperty(name, p, required); - - if (isRegionField(property.name)) { - property.dataType = "string"; - property.datatypeWithEnum = "string"; - property.baseType = "string"; - - // Force template engine to treat this as a string - property.isString = true; - property.isInteger = false; - property.isLong = false; - property.isNumber = false; - property.isNumeric = false; - } - return property; - } - - /** - * Intercepts operation parameters (query, path, header, body). - */ - @Override - public CodegenParameter fromParameter(Parameter param, Set imports) { - CodegenParameter parameter = super.fromParameter(param, imports); - - if (isRegionField(parameter.paramName)) { - parameter.dataType = "string"; - - // Force template engine to treat this as a string - parameter.isString = true; - parameter.isInteger = false; - parameter.isLong = false; - parameter.isNumber = false; - // If it was previously an enum or another complex type, clear it - parameter.isEnum = false; - } - return parameter; - } - - private boolean isRegionField(String name) { - if (name == null) { - return false; - } - return name.equalsIgnoreCase("region") || name.equalsIgnoreCase("regionId"); - } - - @Override - public void postProcessFile(File file, String fileType) { - var path = file.getAbsolutePath(); - var servicesIdx = path.indexOf("/services/"); - var subPath = path.substring(servicesIdx + "/services/".length()); - if (overrides.containsKey(subPath)) { - var override = overrides.get(subPath); - try { - var content = Files.readAllBytes(file.toPath()); - var digest = MessageDigest.getInstance("MD5"); - var hex = HexFormat.of(); - var hash = hex.formatHex(digest.digest(content)); - if (hash.equals(override.hash)) { - var replacementPath = Path.of(Thread.currentThread().getContextClassLoader().getResource(NAMESPACE + override.replacementPath).getPath()); - var replacementContent = Files.readAllBytes(replacementPath); - Files.write(file.toPath(), replacementContent, StandardOpenOption.TRUNCATE_EXISTING); - } else { - throw new IllegalStateException( - "expected iaas/v2api/model_area_id.go to hash to " + - override.hash + " but got " + hash + - "\nedit CustomRegionGenerator.java in the sdk-generator and update IAAS_AREA_ID_HASH" + - "to accept this change" - ); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - super.postProcessFile(file, fileType); - } - - private static class OverrideConfig { - public String name; - public String path; - public String replacementPath; - public String hash; - - public static List load() throws IOException { - var path = Thread.currentThread().getContextClassLoader().getResource(NAMESPACE + "overrides.properties").getPath(); - var overrideProps = new Properties(); - overrideProps.load(new FileInputStream(path)); - var byName = new HashMap(); - overrideProps.stringPropertyNames().forEach(key -> { - var prefixLen = key.indexOf('.'); - var prefix = key.substring(0, prefixLen); - var config = byName.computeIfAbsent(prefix, (_) -> new OverrideConfig()); - config.name = prefix; - var suffix = key.substring(prefixLen + 1); - switch (suffix) { - case "path" -> config.path = overrideProps.getProperty(key); - case "replacementPath" -> config.replacementPath = overrideProps.getProperty(key); - case "hash" -> config.hash = overrideProps.getProperty(key); - default -> throw new IllegalStateException("unexpected suffix: " + suffix); - } - }); - return byName.values().stream().toList(); - } - } - -} diff --git a/scripts/generate-sdk/languages/go.sh b/scripts/generate-sdk/languages/go.sh index 638c42b..1182413 100644 --- a/scripts/generate-sdk/languages/go.sh +++ b/scripts/generate-sdk/languages/go.sh @@ -109,10 +109,8 @@ generate_go_sdk() { # compile custom generator cd ${ROOT_DIR} - mkdir -p custom/cloud/stackit/codegen - javac -cp "${GENERATOR_JAR_PATH}" CustomRegionGenerator.java - mv ./*.class custom/cloud/stackit/codegen - cp languages/golang/overrides/* custom/cloud/stackit/codegen + mkdir -p custom + javac -cp "${GENERATOR_JAR_PATH}" -d custom $(find ./scripts/generators -type f -name '*.java' | grep -v overrides) warning="" @@ -168,9 +166,9 @@ generate_go_sdk() { cp "${ROOT_DIR}/languages/golang/.openapi-generator-ignore" "${SERVICES_FOLDER}/${service}/${version}api/.openapi-generator-ignore" # Run the generator for Go - java -Dlog.level=${GENERATOR_LOG_LEVEL} -cp "custom:scripts/bin/openapi-generator-cli.jar" \ + java -Dlog.level=${GENERATOR_LOG_LEVEL} -cp "custom:scripts/bin/openapi-generator-cli.jar:scripts/generators" \ org.openapitools.codegen.OpenAPIGenerator generate \ - -g cloud.stackit.codegen.CustomRegionGenerator \ + -g GoGenerator \ --input-spec "${service_version_json}" \ --output "${SERVICES_FOLDER}/${service}/${version}api" \ --package-name "${version}api" \ diff --git a/scripts/generate-sdk/languages/java.sh b/scripts/generate-sdk/languages/java.sh index 056ec84..e46e035 100644 --- a/scripts/generate-sdk/languages/java.sh +++ b/scripts/generate-sdk/languages/java.sh @@ -75,6 +75,11 @@ generate_java_sdk() { rm -rf "${SERVICES_FOLDER}" mkdir -p "${SERVICES_FOLDER}" + # compile custom generator + cd ${ROOT_DIR} + mkdir -p custom + javac -cp "${GENERATOR_JAR_PATH}" -d custom $(find ./scripts/generators -type f -name '*.java' | grep -v overrides) + warning="" # Generate SDK for each service @@ -129,13 +134,15 @@ generate_java_sdk() { SERVICE_DESCRIPTION=$(cat "${service_version_json}" | jq .info.title --raw-output) # Run the generator - java -Dlog.level="${GENERATOR_LOG_LEVEL}" -jar "${GENERATOR_JAR_PATH}" generate \ - --generator-name java \ + java -Dlog.level="${GENERATOR_LOG_LEVEL}" -cp "custom:${GENERATOR_JAR_PATH}:scripts/generators" \ + org.openapitools.codegen.OpenAPIGenerator generate \ + --generator-name JavaGenerator \ --input-spec "${service_version_json}" \ --output "${SERVICES_FOLDER}/${service}" \ --git-host "${GIT_HOST}" \ --git-user-id "${GIT_USER_ID}" \ --git-repo-id "${GIT_REPO_ID}" \ + --enable-post-process-file \ --global-property apis,models,modelTests=false,modelDocs=false,apiDocs=false,apiTests=true,supportingFiles \ --additional-properties="artifactId=${service},artifactDescription=${SERVICE_DESCRIPTION},invokerPackage=cloud.stackit.sdk.${service}.${version}api,modelPackage=cloud.stackit.sdk.${service}.${version}api.model,apiPackage=cloud.stackit.sdk.${service}.${version}api.api,serviceName=${service_pascal_case}" \ --inline-schema-options "SKIP_SCHEMA_REUSE=true" \ diff --git a/scripts/generators/GoGenerator.java b/scripts/generators/GoGenerator.java new file mode 100644 index 0000000..d41cd5b --- /dev/null +++ b/scripts/generators/GoGenerator.java @@ -0,0 +1,80 @@ +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.parameters.Parameter; +import org.openapitools.codegen.CodegenParameter; +import org.openapitools.codegen.CodegenProperty; +import org.openapitools.codegen.languages.GoClientCodegen; +import shared.PostProcessFileReplace; + +import java.io.File; +import java.util.Set; + +public class GoGenerator extends GoClientCodegen { + private static RegionFix regionFix = new RegionFix(); + private static PostProcessFileReplace postProcessFileReplace = new PostProcessFileReplace("overrides/go"); + + @Override + public String getName() { + return "GoClientCodegen"; + } + + public GoGenerator(){ + super(); + System.out.println("=== Custom Go Generator initialized ==="); + } + + @Override + public CodegenProperty fromProperty(String name, Schema p, boolean required) { + return regionFix.fromProperty(super.fromProperty(name, p, required)); + } + + @Override + public CodegenParameter fromParameter(Parameter parameter, Set imports) { + return regionFix.fromParameter(super.fromParameter(parameter, imports)); + } + + @Override + public void postProcessFile(File file, String fileType) { + postProcessFileReplace.process(file); + super.postProcessFile(file, fileType); + } +} + +class RegionFix { + CodegenProperty fromProperty(CodegenProperty property) { + if (isRegionField(property.name)) { + property.dataType = "string"; + property.datatypeWithEnum = "string"; + property.baseType = "string"; + + // Force template engine to treat this as a string + property.isString = true; + property.isInteger = false; + property.isLong = false; + property.isNumber = false; + property.isNumeric = false; + } + return property; + } + + CodegenParameter fromParameter(CodegenParameter parameter) { + if (isRegionField(parameter.paramName)) { + parameter.dataType = "string"; + + // Force template engine to treat this as a string + parameter.isString = true; + parameter.isInteger = false; + parameter.isLong = false; + parameter.isNumber = false; + // If it was previously an enum or another complex type, clear it + parameter.isEnum = false; + } + return parameter; + } + + private static boolean isRegionField(String name) { + if (name == null) { + return false; + } + return name.equalsIgnoreCase("region") || name.equalsIgnoreCase("regionId"); + } +} diff --git a/scripts/generators/JavaGenerator.java b/scripts/generators/JavaGenerator.java new file mode 100644 index 0000000..6618db5 --- /dev/null +++ b/scripts/generators/JavaGenerator.java @@ -0,0 +1,24 @@ +import org.openapitools.codegen.languages.JavaClientCodegen; +import shared.PostProcessFileReplace; + +import java.io.File; + +public class JavaGenerator extends JavaClientCodegen { + private static PostProcessFileReplace postProcessFileReplace = new PostProcessFileReplace("overrides/java"); + + @Override + public String getName() { + return "JavaClientCodegen"; + } + + public JavaGenerator(){ + super(); + System.out.println("=== Custom Java Generator initialized ==="); + } + + @Override + public void postProcessFile(File file, String fileType) { + postProcessFileReplace.process(file); + super.postProcessFile(file, fileType); + } +} diff --git a/scripts/generators/README.md b/scripts/generators/README.md new file mode 100644 index 0000000..34c6582 --- /dev/null +++ b/scripts/generators/README.md @@ -0,0 +1,74 @@ +# Custom Generators + +Customized templates are painful when updating the generator. Each template has to be compared with upstream and adapted +accordingly. + +We use custom generators for introducing workarounds and fixes to not further customize our templates. + +## Structure + +Custom generators live in this directory. For each language with a custom generator there should be a `Generator.java` +file. Each fix/workaround should live in its own class and be called from the `Generator.java` file. This allows +easy removal of such fixes, when they are no longer needed. + +Fixes, applicable to multiple languages, should be implemented in the `shared` package. + +We try to only use the JDK and no external libraries besides the `openapi-generator` itself to keep a simple build step. + +## How Custom Generators are executed + +Each language with a custom generator, needs an adapted `.sh` script. Before building each service the custom +generator has to be built: + +```bash +# compile custom generator +cd ${ROOT_DIR} +mkdir -p custom +javac -cp "${GENERATOR_JAR_PATH}" -d custom $(find ./scripts/generators -type f -name '*.java' | grep -v overrides) +``` + +This compiles all java files into the `custom` directory. Here we also exclude java files in the `overrides` directory. +These are resources and should not be compiled in this step. + +The generator call itself has to be adapted: + +```bash +java -Dlog.level="${GENERATOR_LOG_LEVEL}" -cp "custom:${GENERATOR_JAR_PATH}:scripts/generators" \ + org.openapitools.codegen.OpenAPIGenerator generate \ + --generator-name JavaGenerator \ + --enable-post-process-file \ + # more params +``` + +We have to: +- extend the classpath: `custom` makes the compiled custom generator available, `scripts/genrators` the `overrides` + resources +- the `generator-name` needs to be changed to the fully-qualified class name of the custom generator +- `enable-post-process-file` has to be activated to support `overrides` + +## Implemented Fixes + +### Go: Region Param Adjustment + +- we use `RESOLVE_INLINE_ENUMS` +- this creates model classes for inline enums +- this leads to a lot of different types for region enums with the same options +- which makes the API hard to use +- we force a string parameter instead + +### Go/Java: Overrides + +- there are some usages of `oneOf` schemas in our API specs, that are correct schema wise, but the generated code fails +- example: `{ "type": "cidrv4", "value": string }`, `{ "type": "cidrv6", "value": string }` both, have the same shape +- but they use different patterns for `value` +- some language generators do not apply the pattern when validating the `oneOf` and report a false positive violation +- fixing this upstream would be very involved +- we fix it by replacing after generating sources, by replacing files + +How to configure an override: +- edit the `overrides.properties` file for the language in question +- to override a single file you need 3 properties: `.path`, `.replacementPath` and `.hash` +- `` has to be equal for all 3 properties +- `path` is used to match the generated file, which should be replaced +- `hash` is used to check that the generated file still has the same content as when the override was configured +- `replacementPaht` specifies the file in resources, that should be used as replacemen \ No newline at end of file diff --git a/languages/golang/overrides/overrides.properties b/scripts/generators/overrides/go/overrides.properties similarity index 100% rename from languages/golang/overrides/overrides.properties rename to scripts/generators/overrides/go/overrides.properties diff --git a/languages/golang/overrides/v1api_model_area_id.go b/scripts/generators/overrides/go/v1api_model_area_id.go similarity index 100% rename from languages/golang/overrides/v1api_model_area_id.go rename to scripts/generators/overrides/go/v1api_model_area_id.go diff --git a/languages/golang/overrides/v2api_model_area_id.go b/scripts/generators/overrides/go/v2api_model_area_id.go similarity index 100% rename from languages/golang/overrides/v2api_model_area_id.go rename to scripts/generators/overrides/go/v2api_model_area_id.go diff --git a/languages/golang/overrides/v2beta_model_area_id.go b/scripts/generators/overrides/go/v2beta_model_area_id.go similarity index 100% rename from languages/golang/overrides/v2beta_model_area_id.go rename to scripts/generators/overrides/go/v2beta_model_area_id.go diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv4.java b/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv4.java new file mode 100644 index 0000000..26d41bc --- /dev/null +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv4.java @@ -0,0 +1,331 @@ +/* + * STACKIT IaaS API + * This API allows you to create and modify IaaS resources. + * + * The version of the OpenAPI document: 2alpha1 + * Contact: stackit-iaas@mail.schwarz + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package cloud.stackit.sdk.iaas.v2alpha1api.model; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import cloud.stackit.sdk.iaas.v2alpha1api.JSON; + +/** + * IPv4 Classless Inter-Domain Routing (CIDR) Object. + */ +@javax.annotation.Generated(value = "JavaGenerator", comments = "Generator version: 7.19.0") +public class DestinationCIDRv4 { + public static final String SERIALIZED_NAME_TYPE = "type"; + @SerializedName(SERIALIZED_NAME_TYPE) + @javax.annotation.Nonnull + private String type; + + public static final String SERIALIZED_NAME_VALUE = "value"; + @SerializedName(SERIALIZED_NAME_VALUE) + @javax.annotation.Nonnull + private String value; + + public DestinationCIDRv4() { + } + + public DestinationCIDRv4 type(@javax.annotation.Nonnull String type) { + this.type = type; + return this; + } + + /** + * Get type + * @return type + */ + @javax.annotation.Nonnull + public String getType() { + return type; + } + + public void setType(@javax.annotation.Nonnull String type) { + this.type = type; + } + + + public DestinationCIDRv4 value(@javax.annotation.Nonnull String value) { + this.value = value; + return this; + } + + /** + * An CIDRv4 string. + * @return value + */ + @javax.annotation.Nonnull + public String getValue() { + return value; + } + + public void setValue(@javax.annotation.Nonnull String value) { + this.value = value; + } + + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. + * If the property does not already exist, create it otherwise replace it. + * + * @param key name of the property + * @param value value of the property + * @return the DestinationCIDRv4 instance itself + */ + public DestinationCIDRv4 putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DestinationCIDRv4 destinationCIDRv4 = (DestinationCIDRv4) o; + return Objects.equals(this.type, destinationCIDRv4.type) && + Objects.equals(this.value, destinationCIDRv4.value)&& + Objects.equals(this.additionalProperties, destinationCIDRv4.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(type, value, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class DestinationCIDRv4 {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" value: ").append(toIndentedString(value)).append("\n"); + sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(Arrays.asList("type", "value")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(Arrays.asList("type", "value")); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to DestinationCIDRv4 + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!DestinationCIDRv4.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field(s) %s in DestinationCIDRv4 is not found in the empty JSON string", DestinationCIDRv4.openapiRequiredFields.toString())); + } + } + + // check to make sure all required properties/fields are present in the JSON string + for (String requiredField : DestinationCIDRv4.openapiRequiredFields) { + if (jsonElement.getAsJsonObject().get(requiredField) == null) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + if (!jsonObj.get("type").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); + } + if (!"cidrv4".equals(jsonObj.get("type").getAsString())) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expectd the field `type` to have value `cidrv4` but got `%s`", + jsonObj.get("type") + ) + ); + } + if (!jsonObj.get("value").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `value` to be a primitive type in the JSON string but got `%s`", jsonObj.get("value").toString())); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!DestinationCIDRv4.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'DestinationCIDRv4' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter + = gson.getDelegateAdapter(this, TypeToken.get(DestinationCIDRv4.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, DestinationCIDRv4 value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty(entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public DestinationCIDRv4 read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + DestinationCIDRv4 instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + + }.nullSafe(); + } + } + + /** + * Create an instance of DestinationCIDRv4 given an JSON string + * + * @param jsonString JSON string + * @return An instance of DestinationCIDRv4 + * @throws IOException if the JSON string is invalid with respect to DestinationCIDRv4 + */ + public static DestinationCIDRv4 fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, DestinationCIDRv4.class); + } + + /** + * Convert an instance of DestinationCIDRv4 to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv6.java b/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv6.java new file mode 100644 index 0000000..81f3119 --- /dev/null +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv6.java @@ -0,0 +1,331 @@ +/* + * STACKIT IaaS API + * This API allows you to create and modify IaaS resources. + * + * The version of the OpenAPI document: 2alpha1 + * Contact: stackit-iaas@mail.schwarz + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package cloud.stackit.sdk.iaas.v2alpha1api.model; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import cloud.stackit.sdk.iaas.v2alpha1api.JSON; + +/** + * IPv6 Classless Inter-Domain Routing (CIDR) Object. + */ +@javax.annotation.Generated(value = "JavaGenerator", comments = "Generator version: 7.19.0") +public class DestinationCIDRv6 { + public static final String SERIALIZED_NAME_TYPE = "type"; + @SerializedName(SERIALIZED_NAME_TYPE) + @javax.annotation.Nonnull + private String type; + + public static final String SERIALIZED_NAME_VALUE = "value"; + @SerializedName(SERIALIZED_NAME_VALUE) + @javax.annotation.Nonnull + private String value; + + public DestinationCIDRv6() { + } + + public DestinationCIDRv6 type(@javax.annotation.Nonnull String type) { + this.type = type; + return this; + } + + /** + * Get type + * @return type + */ + @javax.annotation.Nonnull + public String getType() { + return type; + } + + public void setType(@javax.annotation.Nonnull String type) { + this.type = type; + } + + + public DestinationCIDRv6 value(@javax.annotation.Nonnull String value) { + this.value = value; + return this; + } + + /** + * An CIDRv6 string. + * @return value + */ + @javax.annotation.Nonnull + public String getValue() { + return value; + } + + public void setValue(@javax.annotation.Nonnull String value) { + this.value = value; + } + + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. + * If the property does not already exist, create it otherwise replace it. + * + * @param key name of the property + * @param value value of the property + * @return the DestinationCIDRv6 instance itself + */ + public DestinationCIDRv6 putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DestinationCIDRv6 destinationCIDRv6 = (DestinationCIDRv6) o; + return Objects.equals(this.type, destinationCIDRv6.type) && + Objects.equals(this.value, destinationCIDRv6.value)&& + Objects.equals(this.additionalProperties, destinationCIDRv6.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(type, value, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class DestinationCIDRv6 {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" value: ").append(toIndentedString(value)).append("\n"); + sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(Arrays.asList("type", "value")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(Arrays.asList("type", "value")); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to DestinationCIDRv6 + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!DestinationCIDRv6.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field(s) %s in DestinationCIDRv6 is not found in the empty JSON string", DestinationCIDRv6.openapiRequiredFields.toString())); + } + } + + // check to make sure all required properties/fields are present in the JSON string + for (String requiredField : DestinationCIDRv6.openapiRequiredFields) { + if (jsonElement.getAsJsonObject().get(requiredField) == null) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + if (!jsonObj.get("type").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); + } + if (!"cidrv6".equals(jsonObj.get("type").getAsString())) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expectd the field `type` to have value `cidrv6` but got `%s`", + jsonObj.get("type") + ) + ); + } + if (!jsonObj.get("value").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `value` to be a primitive type in the JSON string but got `%s`", jsonObj.get("value").toString())); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!DestinationCIDRv6.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'DestinationCIDRv6' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter + = gson.getDelegateAdapter(this, TypeToken.get(DestinationCIDRv6.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, DestinationCIDRv6 value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty(entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public DestinationCIDRv6 read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + DestinationCIDRv6 instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + + }.nullSafe(); + } + } + + /** + * Create an instance of DestinationCIDRv6 given an JSON string + * + * @param jsonString JSON string + * @return An instance of DestinationCIDRv6 + * @throws IOException if the JSON string is invalid with respect to DestinationCIDRv6 + */ + public static DestinationCIDRv6 fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, DestinationCIDRv6.class); + } + + /** + * Convert an instance of DestinationCIDRv6 to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopBlackhole.java b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopBlackhole.java new file mode 100644 index 0000000..f991620 --- /dev/null +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopBlackhole.java @@ -0,0 +1,302 @@ +/* + * STACKIT IaaS API + * This API allows you to create and modify IaaS resources. + * + * The version of the OpenAPI document: 2alpha1 + * Contact: stackit-iaas@mail.schwarz + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package cloud.stackit.sdk.iaas.v2alpha1api.model; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import cloud.stackit.sdk.iaas.v2alpha1api.JSON; + +/** + * Object that represents a blackhole route. + */ +@javax.annotation.Generated(value = "JavaGenerator", comments = "Generator version: 7.19.0") +public class NexthopBlackhole { + public static final String SERIALIZED_NAME_TYPE = "type"; + @SerializedName(SERIALIZED_NAME_TYPE) + @javax.annotation.Nonnull + private String type; + + public NexthopBlackhole() { + } + + public NexthopBlackhole type(@javax.annotation.Nonnull String type) { + this.type = type; + return this; + } + + /** + * Get type + * @return type + */ + @javax.annotation.Nonnull + public String getType() { + return type; + } + + public void setType(@javax.annotation.Nonnull String type) { + this.type = type; + } + + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. + * If the property does not already exist, create it otherwise replace it. + * + * @param key name of the property + * @param value value of the property + * @return the NexthopBlackhole instance itself + */ + public NexthopBlackhole putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NexthopBlackhole nexthopBlackhole = (NexthopBlackhole) o; + return Objects.equals(this.type, nexthopBlackhole.type)&& + Objects.equals(this.additionalProperties, nexthopBlackhole.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(type, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class NexthopBlackhole {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(Arrays.asList("type")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(Arrays.asList("type")); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to NexthopBlackhole + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!NexthopBlackhole.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field(s) %s in NexthopBlackhole is not found in the empty JSON string", NexthopBlackhole.openapiRequiredFields.toString())); + } + } + + // check to make sure all required properties/fields are present in the JSON string + for (String requiredField : NexthopBlackhole.openapiRequiredFields) { + if (jsonElement.getAsJsonObject().get(requiredField) == null) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + if (!jsonObj.get("type").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); + } + if (!"blackhole".equals(jsonObj.get("type").getAsString())) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expectd the field `type` to have value `blackhole` but got `%s`", + jsonObj.get("type") + ) + ); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!NexthopBlackhole.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'NexthopBlackhole' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter + = gson.getDelegateAdapter(this, TypeToken.get(NexthopBlackhole.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, NexthopBlackhole value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty(entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public NexthopBlackhole read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + NexthopBlackhole instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + + }.nullSafe(); + } + } + + /** + * Create an instance of NexthopBlackhole given an JSON string + * + * @param jsonString JSON string + * @return An instance of NexthopBlackhole + * @throws IOException if the JSON string is invalid with respect to NexthopBlackhole + */ + public static NexthopBlackhole fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, NexthopBlackhole.class); + } + + /** + * Convert an instance of NexthopBlackhole to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv4.java b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv4.java new file mode 100644 index 0000000..3591405 --- /dev/null +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv4.java @@ -0,0 +1,331 @@ +/* + * STACKIT IaaS API + * This API allows you to create and modify IaaS resources. + * + * The version of the OpenAPI document: 2alpha1 + * Contact: stackit-iaas@mail.schwarz + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package cloud.stackit.sdk.iaas.v2alpha1api.model; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import cloud.stackit.sdk.iaas.v2alpha1api.JSON; + +/** + * Object that represents an IPv4 address. + */ +@javax.annotation.Generated(value = "JavaGenerator", comments = "Generator version: 7.19.0") +public class NexthopIPv4 { + public static final String SERIALIZED_NAME_TYPE = "type"; + @SerializedName(SERIALIZED_NAME_TYPE) + @javax.annotation.Nonnull + private String type; + + public static final String SERIALIZED_NAME_VALUE = "value"; + @SerializedName(SERIALIZED_NAME_VALUE) + @javax.annotation.Nonnull + private String value; + + public NexthopIPv4() { + } + + public NexthopIPv4 type(@javax.annotation.Nonnull String type) { + this.type = type; + return this; + } + + /** + * Get type + * @return type + */ + @javax.annotation.Nonnull + public String getType() { + return type; + } + + public void setType(@javax.annotation.Nonnull String type) { + this.type = type; + } + + + public NexthopIPv4 value(@javax.annotation.Nonnull String value) { + this.value = value; + return this; + } + + /** + * An IPv4 address. + * @return value + */ + @javax.annotation.Nonnull + public String getValue() { + return value; + } + + public void setValue(@javax.annotation.Nonnull String value) { + this.value = value; + } + + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. + * If the property does not already exist, create it otherwise replace it. + * + * @param key name of the property + * @param value value of the property + * @return the NexthopIPv4 instance itself + */ + public NexthopIPv4 putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NexthopIPv4 nexthopIPv4 = (NexthopIPv4) o; + return Objects.equals(this.type, nexthopIPv4.type) && + Objects.equals(this.value, nexthopIPv4.value)&& + Objects.equals(this.additionalProperties, nexthopIPv4.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(type, value, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class NexthopIPv4 {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" value: ").append(toIndentedString(value)).append("\n"); + sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(Arrays.asList("type", "value")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(Arrays.asList("type", "value")); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to NexthopIPv4 + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!NexthopIPv4.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field(s) %s in NexthopIPv4 is not found in the empty JSON string", NexthopIPv4.openapiRequiredFields.toString())); + } + } + + // check to make sure all required properties/fields are present in the JSON string + for (String requiredField : NexthopIPv4.openapiRequiredFields) { + if (jsonElement.getAsJsonObject().get(requiredField) == null) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + if (!jsonObj.get("type").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); + } + if (!"ipv4".equals(jsonObj.get("type").getAsString())) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expectd the field `type` to have value `ipv4` but got `%s`", + jsonObj.get("type") + ) + ); + } + if (!jsonObj.get("value").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `value` to be a primitive type in the JSON string but got `%s`", jsonObj.get("value").toString())); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!NexthopIPv4.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'NexthopIPv4' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter + = gson.getDelegateAdapter(this, TypeToken.get(NexthopIPv4.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, NexthopIPv4 value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty(entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public NexthopIPv4 read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + NexthopIPv4 instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + + }.nullSafe(); + } + } + + /** + * Create an instance of NexthopIPv4 given an JSON string + * + * @param jsonString JSON string + * @return An instance of NexthopIPv4 + * @throws IOException if the JSON string is invalid with respect to NexthopIPv4 + */ + public static NexthopIPv4 fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, NexthopIPv4.class); + } + + /** + * Convert an instance of NexthopIPv4 to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv6.java b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv6.java new file mode 100644 index 0000000..73aee22 --- /dev/null +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv6.java @@ -0,0 +1,331 @@ +/* + * STACKIT IaaS API + * This API allows you to create and modify IaaS resources. + * + * The version of the OpenAPI document: 2alpha1 + * Contact: stackit-iaas@mail.schwarz + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package cloud.stackit.sdk.iaas.v2alpha1api.model; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import cloud.stackit.sdk.iaas.v2alpha1api.JSON; + +/** + * Object that represents an IPv6 address. + */ +@javax.annotation.Generated(value = "JavaGenerator", comments = "Generator version: 7.19.0") +public class NexthopIPv6 { + public static final String SERIALIZED_NAME_TYPE = "type"; + @SerializedName(SERIALIZED_NAME_TYPE) + @javax.annotation.Nonnull + private String type; + + public static final String SERIALIZED_NAME_VALUE = "value"; + @SerializedName(SERIALIZED_NAME_VALUE) + @javax.annotation.Nonnull + private String value; + + public NexthopIPv6() { + } + + public NexthopIPv6 type(@javax.annotation.Nonnull String type) { + this.type = type; + return this; + } + + /** + * Get type + * @return type + */ + @javax.annotation.Nonnull + public String getType() { + return type; + } + + public void setType(@javax.annotation.Nonnull String type) { + this.type = type; + } + + + public NexthopIPv6 value(@javax.annotation.Nonnull String value) { + this.value = value; + return this; + } + + /** + * An IPv6 address. + * @return value + */ + @javax.annotation.Nonnull + public String getValue() { + return value; + } + + public void setValue(@javax.annotation.Nonnull String value) { + this.value = value; + } + + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. + * If the property does not already exist, create it otherwise replace it. + * + * @param key name of the property + * @param value value of the property + * @return the NexthopIPv6 instance itself + */ + public NexthopIPv6 putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NexthopIPv6 nexthopIPv6 = (NexthopIPv6) o; + return Objects.equals(this.type, nexthopIPv6.type) && + Objects.equals(this.value, nexthopIPv6.value)&& + Objects.equals(this.additionalProperties, nexthopIPv6.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(type, value, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class NexthopIPv6 {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" value: ").append(toIndentedString(value)).append("\n"); + sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(Arrays.asList("type", "value")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(Arrays.asList("type", "value")); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to NexthopIPv6 + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!NexthopIPv6.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field(s) %s in NexthopIPv6 is not found in the empty JSON string", NexthopIPv6.openapiRequiredFields.toString())); + } + } + + // check to make sure all required properties/fields are present in the JSON string + for (String requiredField : NexthopIPv6.openapiRequiredFields) { + if (jsonElement.getAsJsonObject().get(requiredField) == null) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + if (!jsonObj.get("type").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); + } + if (!"ipv6".equals(jsonObj.get("type").getAsString())) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expectd the field `type` to have value `ipv6` but got `%s`", + jsonObj.get("type") + ) + ); + } + if (!jsonObj.get("value").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `value` to be a primitive type in the JSON string but got `%s`", jsonObj.get("value").toString())); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!NexthopIPv6.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'NexthopIPv6' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter + = gson.getDelegateAdapter(this, TypeToken.get(NexthopIPv6.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, NexthopIPv6 value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty(entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public NexthopIPv6 read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + NexthopIPv6 instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + + }.nullSafe(); + } + } + + /** + * Create an instance of NexthopIPv6 given an JSON string + * + * @param jsonString JSON string + * @return An instance of NexthopIPv6 + * @throws IOException if the JSON string is invalid with respect to NexthopIPv6 + */ + public static NexthopIPv6 fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, NexthopIPv6.class); + } + + /** + * Convert an instance of NexthopIPv6 to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopInternet.java b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopInternet.java new file mode 100644 index 0000000..8971bcb --- /dev/null +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopInternet.java @@ -0,0 +1,302 @@ +/* + * STACKIT IaaS API + * This API allows you to create and modify IaaS resources. + * + * The version of the OpenAPI document: 2alpha1 + * Contact: stackit-iaas@mail.schwarz + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package cloud.stackit.sdk.iaas.v2alpha1api.model; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.util.Arrays; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import cloud.stackit.sdk.iaas.v2alpha1api.JSON; + +/** + * Object that represents a route to the internet. + */ +@javax.annotation.Generated(value = "JavaGenerator", comments = "Generator version: 7.19.0") +public class NexthopInternet { + public static final String SERIALIZED_NAME_TYPE = "type"; + @SerializedName(SERIALIZED_NAME_TYPE) + @javax.annotation.Nonnull + private String type; + + public NexthopInternet() { + } + + public NexthopInternet type(@javax.annotation.Nonnull String type) { + this.type = type; + return this; + } + + /** + * Get type + * @return type + */ + @javax.annotation.Nonnull + public String getType() { + return type; + } + + public void setType(@javax.annotation.Nonnull String type) { + this.type = type; + } + + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. + * If the property does not already exist, create it otherwise replace it. + * + * @param key name of the property + * @param value value of the property + * @return the NexthopInternet instance itself + */ + public NexthopInternet putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + NexthopInternet nexthopInternet = (NexthopInternet) o; + return Objects.equals(this.type, nexthopInternet.type)&& + Objects.equals(this.additionalProperties, nexthopInternet.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(type, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class NexthopInternet {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(Arrays.asList("type")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(Arrays.asList("type")); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to NexthopInternet + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!NexthopInternet.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field(s) %s in NexthopInternet is not found in the empty JSON string", NexthopInternet.openapiRequiredFields.toString())); + } + } + + // check to make sure all required properties/fields are present in the JSON string + for (String requiredField : NexthopInternet.openapiRequiredFields) { + if (jsonElement.getAsJsonObject().get(requiredField) == null) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + if (!jsonObj.get("type").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); + } + if (!"internet".equals(jsonObj.get("type").getAsString())) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expectd the field `type` to have value `internet` but got `%s`", + jsonObj.get("type") + ) + ); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!NexthopInternet.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'NexthopInternet' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter + = gson.getDelegateAdapter(this, TypeToken.get(NexthopInternet.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, NexthopInternet value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty(entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public NexthopInternet read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + NexthopInternet instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + + }.nullSafe(); + } + } + + /** + * Create an instance of NexthopInternet given an JSON string + * + * @param jsonString JSON string + * @return An instance of NexthopInternet + * @throws IOException if the JSON string is invalid with respect to NexthopInternet + */ + public static NexthopInternet fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, NexthopInternet.class); + } + + /** + * Convert an instance of NexthopInternet to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/scripts/generators/overrides/java/overrides.properties b/scripts/generators/overrides/java/overrides.properties new file mode 100644 index 0000000..47b5133 --- /dev/null +++ b/scripts/generators/overrides/java/overrides.properties @@ -0,0 +1,23 @@ +iaasV2AlphaApiRouteDestinationCIDRv4.path=iaas/src/main/java/cloud/stackit/sdk/iaas/v2alpha1api/model/DestinationCIDRv4.java +iaasV2AlphaApiRouteDestinationCIDRv4.replacementPath=iaas_v2alpha_model_destinationCIDRv4.java +iaasV2AlphaApiRouteDestinationCIDRv4.hash=61c00060b5f19d949ef6f2c6cd82a13a + +iaasV2AlphaApiRouteDestinationCIDRv6.path=iaas/src/main/java/cloud/stackit/sdk/iaas/v2alpha1api/model/DestinationCIDRv6.java +iaasV2AlphaApiRouteDestinationCIDRv6.replacementPath=iaas_v2alpha_model_destinationCIDRv6.java +iaasV2AlphaApiRouteDestinationCIDRv6.hash=9e47a4ea974f9080093a6c9d2e615446 + +iaasV2AlphaApiNexthopIPv4.path=iaas/src/main/java/cloud/stackit/sdk/iaas/v2alpha1api/model/NexthopIPv4.java +iaasV2AlphaApiNexthopIPv4.replacementPath=iaas_v2alpha_model_nexthopIPv4.java +iaasV2AlphaApiNexthopIPv4.hash=2ea5d1b96781197503206c2f7c21e793 + +iaasV2AlphaApiNexthopIPv6.path=iaas/src/main/java/cloud/stackit/sdk/iaas/v2alpha1api/model/NexthopIPv6.java +iaasV2AlphaApiNexthopIPv6.replacementPath=iaas_v2alpha_model_nexthopIPv6.java +iaasV2AlphaApiNexthopIPv6.hash=c81d6973112f919bc2a7d119edc30ac7 + +iaasV2AlphaApiNexthopBlackhole.path=iaas/src/main/java/cloud/stackit/sdk/iaas/v2alpha1api/model/NexthopBlackhole.java +iaasV2AlphaApiNexthopBlackhole.replacementPath=iaas_v2alpha_model_nexthopBlackhole.java +iaasV2AlphaApiNexthopBlackhole.hash=ae20d347b1ac740c33ecc3d4ee42c9c9 + +iaasV2AlphaApiNexthopInternet.path=iaas/src/main/java/cloud/stackit/sdk/iaas/v2alpha1api/model/NexthopInternet.java +iaasV2AlphaApiNexthopInternet.replacementPath=iaas_v2alpha_model_nexthopInternet.java +iaasV2AlphaApiNexthopInternet.hash=c56c0bab9c1772eacec3638d52af8aaa diff --git a/scripts/generators/shared/PostProcessFileReplace.java b/scripts/generators/shared/PostProcessFileReplace.java new file mode 100644 index 0000000..7edc492 --- /dev/null +++ b/scripts/generators/shared/PostProcessFileReplace.java @@ -0,0 +1,101 @@ +package shared; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.security.MessageDigest; +import java.util.HashMap; +import java.util.HexFormat; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class PostProcessFileReplace { + private final String configPackage; + private final Map overrides; + + public PostProcessFileReplace(String configPackage) { + this.configPackage = configPackage; + try { + overrides = OverrideConfig.load(configPackage).stream().collect(Collectors.toMap( + o -> o.path, + Function.identity() + )); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public void process(File file) { + var path = file.getAbsolutePath(); + var servicesIdx = path.indexOf("/services/"); + var subPath = path.substring(servicesIdx + "/services/".length()); + if (overrides.containsKey(subPath)) { + var override = overrides.get(subPath); + try { + var content = Files.readAllBytes(file.toPath()); + var digest = MessageDigest.getInstance("MD5"); + var hex = HexFormat.of(); + var hash = hex.formatHex(digest.digest(content)); + if (hash.equals(override.hash)) { + var resource = Thread.currentThread().getContextClassLoader().getResource(configPackage + "/" + override.replacementPath); + if (resource == null) { + throw new IllegalStateException( + String.format("configure override file can't be found in resources, check configuration %s.replacementPath in overrides.properties and verify the file exists", + override.name + ) + ); + } + var replacementPath = Path.of(resource.getPath()); + var replacementContent = Files.readAllBytes(replacementPath); + Files.write(file.toPath(), replacementContent, StandardOpenOption.TRUNCATE_EXISTING); + } else { + throw new IllegalStateException( + String.format("expected %s to hash to %s but got %s\nedit overrides.properties in the sdk-generator and update %s.hash to accept this change", + override.path, + override.hash, + hash, + override.name + ) + ); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + } + + private static class OverrideConfig { + public String name; + public String path; + public String replacementPath; + public String hash; + + public static List load(String configPackage) throws IOException { + var path = Thread.currentThread().getContextClassLoader().getResource(configPackage + "/overrides.properties").getPath(); + var overrideProps = new Properties(); + overrideProps.load(new FileInputStream(path)); + var byName = new HashMap(); + overrideProps.stringPropertyNames().forEach(key -> { + var prefixLen = key.indexOf('.'); + var prefix = key.substring(0, prefixLen); + var config = byName.computeIfAbsent(prefix, (_) -> new OverrideConfig()); + config.name = prefix; + var suffix = key.substring(prefixLen + 1); + switch (suffix) { + case "path" -> config.path = overrideProps.getProperty(key); + case "replacementPath" -> config.replacementPath = overrideProps.getProperty(key); + case "hash" -> config.hash = overrideProps.getProperty(key); + default -> throw new IllegalStateException("unexpected suffix: " + suffix); + } + }); + return byName.values().stream().toList(); + } + } +} From ef502c23a5da1204bae3260109527b6e24cb643e Mon Sep 17 00:00:00 2001 From: Carlo Goetz Date: Fri, 17 Jul 2026 16:04:28 +0200 Subject: [PATCH 5/6] fix(PostProcessFileReplace): don't use _ as lambda param --- scripts/generators/shared/PostProcessFileReplace.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generators/shared/PostProcessFileReplace.java b/scripts/generators/shared/PostProcessFileReplace.java index 7edc492..b350e3b 100644 --- a/scripts/generators/shared/PostProcessFileReplace.java +++ b/scripts/generators/shared/PostProcessFileReplace.java @@ -85,7 +85,7 @@ public static List load(String configPackage) throws IOException overrideProps.stringPropertyNames().forEach(key -> { var prefixLen = key.indexOf('.'); var prefix = key.substring(0, prefixLen); - var config = byName.computeIfAbsent(prefix, (_) -> new OverrideConfig()); + var config = byName.computeIfAbsent(prefix, (name) -> new OverrideConfig()); config.name = prefix; var suffix = key.substring(prefixLen + 1); switch (suffix) { From 6c88c6650ae82265b67ebe93187ba7bc01acdb60 Mon Sep 17 00:00:00 2001 From: Carlo Goetz Date: Fri, 17 Jul 2026 16:33:08 +0200 Subject: [PATCH 6/6] fix(iaas): add overrides for VPCNetworkRanges --- scripts/generators/README.md | 3 +- .../overrides/go/v1api_model_area_id.go | 1 + .../overrides/go/v2api_model_area_id.go | 1 + .../overrides/go/v2beta_model_area_id.go | 1 + .../iaas_v2alpha_model_destinationCIDRv4.java | 1 + .../iaas_v2alpha_model_destinationCIDRv6.java | 1 + .../iaas_v2alpha_model_nexthopBlackhole.java | 1 + .../java/iaas_v2alpha_model_nexthopIPv4.java | 1 + .../java/iaas_v2alpha_model_nexthopIPv6.java | 1 + .../iaas_v2alpha_model_nexthopInternet.java | 1 + ...aas_v2alpha_model_vpcNetworkRangeIPv4.java | 664 ++++++++++++++++++ ...aas_v2alpha_model_vpcNetworkRangeIPv6.java | 664 ++++++++++++++++++ .../overrides/java/overrides.properties | 8 + 13 files changed, 1347 insertions(+), 1 deletion(-) create mode 100644 scripts/generators/overrides/java/iaas_v2alpha_model_vpcNetworkRangeIPv4.java create mode 100644 scripts/generators/overrides/java/iaas_v2alpha_model_vpcNetworkRangeIPv6.java diff --git a/scripts/generators/README.md b/scripts/generators/README.md index 34c6582..faabd85 100644 --- a/scripts/generators/README.md +++ b/scripts/generators/README.md @@ -71,4 +71,5 @@ How to configure an override: - `` has to be equal for all 3 properties - `path` is used to match the generated file, which should be replaced - `hash` is used to check that the generated file still has the same content as when the override was configured -- `replacementPaht` specifies the file in resources, that should be used as replacemen \ No newline at end of file +- `replacementPath` specifies the file in resources, that should be used as replacement +- mark adjusted sections in the replacement file in resources with an `OVERRIDE:` comment \ No newline at end of file diff --git a/scripts/generators/overrides/go/v1api_model_area_id.go b/scripts/generators/overrides/go/v1api_model_area_id.go index 7dab3f9..a76c8e7 100644 --- a/scripts/generators/overrides/go/v1api_model_area_id.go +++ b/scripts/generators/overrides/go/v1api_model_area_id.go @@ -58,6 +58,7 @@ func (dst *AreaId) UnmarshalJSON(data []byte) error { err = json.Unmarshal(data, &dst.String) if err == nil { jsonString, _ := json.Marshal(dst.String) + // OVERRIDE: this pattern match is custom regex := `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` isMatched, _ := regexp.MatchString(regex, *dst.String) if string(jsonString) != "{}" && isMatched { // empty struct diff --git a/scripts/generators/overrides/go/v2api_model_area_id.go b/scripts/generators/overrides/go/v2api_model_area_id.go index 5159f8b..bd0b814 100644 --- a/scripts/generators/overrides/go/v2api_model_area_id.go +++ b/scripts/generators/overrides/go/v2api_model_area_id.go @@ -58,6 +58,7 @@ func (dst *AreaId) UnmarshalJSON(data []byte) error { err = json.Unmarshal(data, &dst.String) if err == nil { jsonString, _ := json.Marshal(dst.String) + // OVERRIDE: this pattern match is custom regex := `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` isMatched, _ := regexp.MatchString(regex, *dst.String) if string(jsonString) != "{}" && isMatched { // empty struct diff --git a/scripts/generators/overrides/go/v2beta_model_area_id.go b/scripts/generators/overrides/go/v2beta_model_area_id.go index f7bcd61..e6adbeb 100644 --- a/scripts/generators/overrides/go/v2beta_model_area_id.go +++ b/scripts/generators/overrides/go/v2beta_model_area_id.go @@ -45,6 +45,7 @@ func (dst *AreaId) UnmarshalJSON(data []byte) error { err = json.Unmarshal(data, &dst.StaticAreaID) if err == nil { jsonStaticAreaID, _ := json.Marshal(dst.StaticAreaID) + // OVERRIDE: this pattern match is custom regex := `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` isMatched, _ := regexp.MatchString(regex, string(*dst.StaticAreaID)) if string(jsonStaticAreaID) != "{}" && isMatched { // empty struct diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv4.java b/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv4.java index 26d41bc..cb5b51f 100644 --- a/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv4.java +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv4.java @@ -222,6 +222,7 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti if (!jsonObj.get("type").isJsonPrimitive()) { throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); } + // OVERRIDE: this if block fixes oneOf issues if (!"cidrv4".equals(jsonObj.get("type").getAsString())) { throw new IllegalArgumentException( String.format( diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv6.java b/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv6.java index 81f3119..a9917a1 100644 --- a/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv6.java +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_destinationCIDRv6.java @@ -222,6 +222,7 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti if (!jsonObj.get("type").isJsonPrimitive()) { throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); } + // OVERRIDE: this if block fixes oneOf issues if (!"cidrv6".equals(jsonObj.get("type").getAsString())) { throw new IllegalArgumentException( String.format( diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopBlackhole.java b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopBlackhole.java index f991620..691d617 100644 --- a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopBlackhole.java +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopBlackhole.java @@ -196,6 +196,7 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti if (!jsonObj.get("type").isJsonPrimitive()) { throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); } + // OVERRIDE: this if block fixes oneOf issues if (!"blackhole".equals(jsonObj.get("type").getAsString())) { throw new IllegalArgumentException( String.format( diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv4.java b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv4.java index 3591405..6d6e829 100644 --- a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv4.java +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv4.java @@ -222,6 +222,7 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti if (!jsonObj.get("type").isJsonPrimitive()) { throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); } + // OVERRIDE: this if block fixes oneOf issues if (!"ipv4".equals(jsonObj.get("type").getAsString())) { throw new IllegalArgumentException( String.format( diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv6.java b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv6.java index 73aee22..c04ebc8 100644 --- a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv6.java +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopIPv6.java @@ -222,6 +222,7 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti if (!jsonObj.get("type").isJsonPrimitive()) { throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); } + // OVERRIDE: this if block fixes oneOf issues if (!"ipv6".equals(jsonObj.get("type").getAsString())) { throw new IllegalArgumentException( String.format( diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopInternet.java b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopInternet.java index 8971bcb..f961e7b 100644 --- a/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopInternet.java +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_nexthopInternet.java @@ -196,6 +196,7 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti if (!jsonObj.get("type").isJsonPrimitive()) { throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString())); } + // OVERRIDE: this if block fixes oneOf issues if (!"internet".equals(jsonObj.get("type").getAsString())) { throw new IllegalArgumentException( String.format( diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_vpcNetworkRangeIPv4.java b/scripts/generators/overrides/java/iaas_v2alpha_model_vpcNetworkRangeIPv4.java new file mode 100644 index 0000000..2959266 --- /dev/null +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_vpcNetworkRangeIPv4.java @@ -0,0 +1,664 @@ +/* + * STACKIT IaaS API + * This API allows you to create and modify IaaS resources. + * + * The version of the OpenAPI document: 2alpha1 + * Contact: stackit-iaas@mail.schwarz + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package cloud.stackit.sdk.iaas.v2alpha1api.model; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import cloud.stackit.sdk.iaas.v2alpha1api.JSON; + +/** + * Contains the IPv4 properties of a VPC network range. + */ +@javax.annotation.Generated(value = "JavaGenerator", comments = "Generator version: 7.19.0") +public class VPCNetworkRangeIPv4 { + public static final String SERIALIZED_NAME_CREATED_AT = "createdAt"; + @SerializedName(SERIALIZED_NAME_CREATED_AT) + @javax.annotation.Nullable + private OffsetDateTime createdAt; + + public static final String SERIALIZED_NAME_DESCRIPTION = "description"; + @SerializedName(SERIALIZED_NAME_DESCRIPTION) + @javax.annotation.Nullable + private String description; + + public static final String SERIALIZED_NAME_ID = "id"; + @SerializedName(SERIALIZED_NAME_ID) + @javax.annotation.Nullable + private UUID id; + + public static final String SERIALIZED_NAME_LABELS = "labels"; + @SerializedName(SERIALIZED_NAME_LABELS) + @javax.annotation.Nullable + private Object labels; + + public static final String SERIALIZED_NAME_STATUS = "status"; + @SerializedName(SERIALIZED_NAME_STATUS) + @javax.annotation.Nullable + private String status; + + public static final String SERIALIZED_NAME_UPDATED_AT = "updatedAt"; + @SerializedName(SERIALIZED_NAME_UPDATED_AT) + @javax.annotation.Nullable + private OffsetDateTime updatedAt; + + public static final String SERIALIZED_NAME_DEFAULT_PREFIX_LEN = "defaultPrefixLen"; + @SerializedName(SERIALIZED_NAME_DEFAULT_PREFIX_LEN) + @javax.annotation.Nullable + private Long defaultPrefixLen = 25l; + + /** + * Gets or Sets ipVersion + */ + @JsonAdapter(IpVersionEnum.Adapter.class) + public enum IpVersionEnum { + IPV4("ipv4"), + + UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api"); + + private String value; + + IpVersionEnum(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static IpVersionEnum fromValue(String value) { + for (IpVersionEnum b : IpVersionEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + return UNKNOWN_DEFAULT_OPEN_API; + } + + public static class Adapter extends TypeAdapter { + @Override + public void write(final JsonWriter jsonWriter, final IpVersionEnum enumeration) throws IOException { + jsonWriter.value(enumeration.getValue()); + } + + @Override + public IpVersionEnum read(final JsonReader jsonReader) throws IOException { + String value = jsonReader.nextString(); + return IpVersionEnum.fromValue(value); + } + } + + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + String value = jsonElement.getAsString(); + IpVersionEnum.fromValue(value); + } + } + + public static final String SERIALIZED_NAME_IP_VERSION = "ipVersion"; + @SerializedName(SERIALIZED_NAME_IP_VERSION) + @javax.annotation.Nonnull + private IpVersionEnum ipVersion; + + public static final String SERIALIZED_NAME_MAX_PREFIX_LEN = "maxPrefixLen"; + @SerializedName(SERIALIZED_NAME_MAX_PREFIX_LEN) + @javax.annotation.Nullable + private Long maxPrefixLen = 29l; + + public static final String SERIALIZED_NAME_MIN_PREFIX_LEN = "minPrefixLen"; + @SerializedName(SERIALIZED_NAME_MIN_PREFIX_LEN) + @javax.annotation.Nullable + private Long minPrefixLen = 24l; + + public static final String SERIALIZED_NAME_NAMESERVERS = "nameservers"; + @SerializedName(SERIALIZED_NAME_NAMESERVERS) + @javax.annotation.Nullable + private List nameservers; + + public static final String SERIALIZED_NAME_PREFIX = "prefix"; + @SerializedName(SERIALIZED_NAME_PREFIX) + @javax.annotation.Nonnull + private String prefix; + + public VPCNetworkRangeIPv4() { + } + + public VPCNetworkRangeIPv4( + OffsetDateTime createdAt, + UUID id, + OffsetDateTime updatedAt + ) { + this(); + this.createdAt = createdAt; + this.id = id; + this.updatedAt = updatedAt; + } + + /** + * Date-time when resource was created. + * @return createdAt + */ + @javax.annotation.Nullable + public OffsetDateTime getCreatedAt() { + return createdAt; + } + + + + public VPCNetworkRangeIPv4 description(@javax.annotation.Nullable String description) { + this.description = description; + return this; + } + + /** + * Description Object. Allows string up to 255 Characters. + * @return description + */ + @javax.annotation.Nullable + public String getDescription() { + return description; + } + + public void setDescription(@javax.annotation.Nullable String description) { + this.description = description; + } + + + /** + * Universally Unique Identifier (UUID). + * @return id + */ + @javax.annotation.Nullable + public UUID getId() { + return id; + } + + + + public VPCNetworkRangeIPv4 labels(@javax.annotation.Nullable Object labels) { + this.labels = labels; + return this; + } + + /** + * Object that represents the labels of an object. Regex for keys: `^(?=.{1,63}$)([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$`. Regex for values: `^(?=.{0,63}$)(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])*$`. Providing a `null` value for a key will remove that key. The `stackit-` prefix is reserved and cannot be used for Keys. + * @return labels + */ + @javax.annotation.Nullable + public Object getLabels() { + return labels; + } + + public void setLabels(@javax.annotation.Nullable Object labels) { + this.labels = labels; + } + + + public VPCNetworkRangeIPv4 status(@javax.annotation.Nullable String status) { + this.status = status; + return this; + } + + /** + * The state of a resource object. Possible values: `CREATING`, `CREATED`, `DELETING`, `DELETED`, `FAILED`, `UPDATED`, `UPDATING`. + * @return status + */ + @javax.annotation.Nullable + public String getStatus() { + return status; + } + + public void setStatus(@javax.annotation.Nullable String status) { + this.status = status; + } + + + /** + * Date-time when resource was last updated. + * @return updatedAt + */ + @javax.annotation.Nullable + public OffsetDateTime getUpdatedAt() { + return updatedAt; + } + + + + public VPCNetworkRangeIPv4 defaultPrefixLen(@javax.annotation.Nullable Long defaultPrefixLen) { + this.defaultPrefixLen = defaultPrefixLen; + return this; + } + + /** + * The default prefix length for network ranges in the VPC. + * minimum: 24 + * maximum: 29 + * @return defaultPrefixLen + */ + @javax.annotation.Nullable + public Long getDefaultPrefixLen() { + return defaultPrefixLen; + } + + public void setDefaultPrefixLen(@javax.annotation.Nullable Long defaultPrefixLen) { + this.defaultPrefixLen = defaultPrefixLen; + } + + + public VPCNetworkRangeIPv4 ipVersion(@javax.annotation.Nonnull IpVersionEnum ipVersion) { + this.ipVersion = ipVersion; + return this; + } + + /** + * Get ipVersion + * @return ipVersion + */ + @javax.annotation.Nonnull + public IpVersionEnum getIpVersion() { + return ipVersion; + } + + public void setIpVersion(@javax.annotation.Nonnull IpVersionEnum ipVersion) { + this.ipVersion = ipVersion; + } + + + public VPCNetworkRangeIPv4 maxPrefixLen(@javax.annotation.Nullable Long maxPrefixLen) { + this.maxPrefixLen = maxPrefixLen; + return this; + } + + /** + * The maximal prefix length for network ranges in the VPC. + * minimum: 24 + * maximum: 29 + * @return maxPrefixLen + */ + @javax.annotation.Nullable + public Long getMaxPrefixLen() { + return maxPrefixLen; + } + + public void setMaxPrefixLen(@javax.annotation.Nullable Long maxPrefixLen) { + this.maxPrefixLen = maxPrefixLen; + } + + + public VPCNetworkRangeIPv4 minPrefixLen(@javax.annotation.Nullable Long minPrefixLen) { + this.minPrefixLen = minPrefixLen; + return this; + } + + /** + * The minimal prefix length for network ranges in the VPC. + * minimum: 8 + * maximum: 29 + * @return minPrefixLen + */ + @javax.annotation.Nullable + public Long getMinPrefixLen() { + return minPrefixLen; + } + + public void setMinPrefixLen(@javax.annotation.Nullable Long minPrefixLen) { + this.minPrefixLen = minPrefixLen; + } + + + public VPCNetworkRangeIPv4 nameservers(@javax.annotation.Nullable List nameservers) { + this.nameservers = nameservers; + return this; + } + + public VPCNetworkRangeIPv4 addNameserversItem(String nameserversItem) { + if (this.nameservers == null) { + this.nameservers = new ArrayList<>(); + } + this.nameservers.add(nameserversItem); + return this; + } + + /** + * A list containing DNS Servers/Nameservers for IPv4. + * @return nameservers + */ + @javax.annotation.Nullable + public List getNameservers() { + return nameservers; + } + + public void setNameservers(@javax.annotation.Nullable List nameservers) { + this.nameservers = nameservers; + } + + + public VPCNetworkRangeIPv4 prefix(@javax.annotation.Nonnull String prefix) { + this.prefix = prefix; + return this; + } + + /** + * Classless Inter-Domain Routing (CIDR). + * @return prefix + */ + @javax.annotation.Nonnull + public String getPrefix() { + return prefix; + } + + public void setPrefix(@javax.annotation.Nonnull String prefix) { + this.prefix = prefix; + } + + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. + * If the property does not already exist, create it otherwise replace it. + * + * @param key name of the property + * @param value value of the property + * @return the VPCNetworkRangeIPv4 instance itself + */ + public VPCNetworkRangeIPv4 putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + VPCNetworkRangeIPv4 vpCNetworkRangeIPv4 = (VPCNetworkRangeIPv4) o; + return Objects.equals(this.createdAt, vpCNetworkRangeIPv4.createdAt) && + Objects.equals(this.description, vpCNetworkRangeIPv4.description) && + Objects.equals(this.id, vpCNetworkRangeIPv4.id) && + Objects.equals(this.labels, vpCNetworkRangeIPv4.labels) && + Objects.equals(this.status, vpCNetworkRangeIPv4.status) && + Objects.equals(this.updatedAt, vpCNetworkRangeIPv4.updatedAt) && + Objects.equals(this.defaultPrefixLen, vpCNetworkRangeIPv4.defaultPrefixLen) && + Objects.equals(this.ipVersion, vpCNetworkRangeIPv4.ipVersion) && + Objects.equals(this.maxPrefixLen, vpCNetworkRangeIPv4.maxPrefixLen) && + Objects.equals(this.minPrefixLen, vpCNetworkRangeIPv4.minPrefixLen) && + Objects.equals(this.nameservers, vpCNetworkRangeIPv4.nameservers) && + Objects.equals(this.prefix, vpCNetworkRangeIPv4.prefix)&& + Objects.equals(this.additionalProperties, vpCNetworkRangeIPv4.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(createdAt, description, id, labels, status, updatedAt, defaultPrefixLen, ipVersion, maxPrefixLen, minPrefixLen, nameservers, prefix, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class VPCNetworkRangeIPv4 {\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" labels: ").append(toIndentedString(labels)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" updatedAt: ").append(toIndentedString(updatedAt)).append("\n"); + sb.append(" defaultPrefixLen: ").append(toIndentedString(defaultPrefixLen)).append("\n"); + sb.append(" ipVersion: ").append(toIndentedString(ipVersion)).append("\n"); + sb.append(" maxPrefixLen: ").append(toIndentedString(maxPrefixLen)).append("\n"); + sb.append(" minPrefixLen: ").append(toIndentedString(minPrefixLen)).append("\n"); + sb.append(" nameservers: ").append(toIndentedString(nameservers)).append("\n"); + sb.append(" prefix: ").append(toIndentedString(prefix)).append("\n"); + sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(Arrays.asList("createdAt", "description", "id", "labels", "status", "updatedAt", "defaultPrefixLen", "ipVersion", "maxPrefixLen", "minPrefixLen", "nameservers", "prefix")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(Arrays.asList("ipVersion", "prefix")); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to VPCNetworkRangeIPv4 + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!VPCNetworkRangeIPv4.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field(s) %s in VPCNetworkRangeIPv4 is not found in the empty JSON string", VPCNetworkRangeIPv4.openapiRequiredFields.toString())); + } + } + + // check to make sure all required properties/fields are present in the JSON string + for (String requiredField : VPCNetworkRangeIPv4.openapiRequiredFields) { + if (jsonElement.getAsJsonObject().get(requiredField) == null) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + if ((jsonObj.get("description") != null && !jsonObj.get("description").isJsonNull()) && !jsonObj.get("description").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `description` to be a primitive type in the JSON string but got `%s`", jsonObj.get("description").toString())); + } + if ((jsonObj.get("id") != null && !jsonObj.get("id").isJsonNull()) && !jsonObj.get("id").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `id` to be a primitive type in the JSON string but got `%s`", jsonObj.get("id").toString())); + } + if ((jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) && !jsonObj.get("status").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `status` to be a primitive type in the JSON string but got `%s`", jsonObj.get("status").toString())); + } + if (!jsonObj.get("ipVersion").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `ipVersion` to be a primitive type in the JSON string but got `%s`", jsonObj.get("ipVersion").toString())); + } + // OVERRIDE: this if block fixes oneOf issues + if (!"ipv4".equals(jsonObj.get("ipVersion").getAsString())) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expectd the field `ipVersion` to have value `ipv4` but got `%s`", + jsonObj.get("ipVersion") + ) + ); + } + // validate the required field `ipVersion` + IpVersionEnum.validateJsonElement(jsonObj.get("ipVersion")); + // ensure the optional json data is an array if present + if (jsonObj.get("nameservers") != null && !jsonObj.get("nameservers").isJsonNull() && !jsonObj.get("nameservers").isJsonArray()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `nameservers` to be an array in the JSON string but got `%s`", jsonObj.get("nameservers").toString())); + } + if (!jsonObj.get("prefix").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `prefix` to be a primitive type in the JSON string but got `%s`", jsonObj.get("prefix").toString())); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!VPCNetworkRangeIPv4.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'VPCNetworkRangeIPv4' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter + = gson.getDelegateAdapter(this, TypeToken.get(VPCNetworkRangeIPv4.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, VPCNetworkRangeIPv4 value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty(entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public VPCNetworkRangeIPv4 read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + VPCNetworkRangeIPv4 instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + + }.nullSafe(); + } + } + + /** + * Create an instance of VPCNetworkRangeIPv4 given an JSON string + * + * @param jsonString JSON string + * @return An instance of VPCNetworkRangeIPv4 + * @throws IOException if the JSON string is invalid with respect to VPCNetworkRangeIPv4 + */ + public static VPCNetworkRangeIPv4 fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, VPCNetworkRangeIPv4.class); + } + + /** + * Convert an instance of VPCNetworkRangeIPv4 to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/scripts/generators/overrides/java/iaas_v2alpha_model_vpcNetworkRangeIPv6.java b/scripts/generators/overrides/java/iaas_v2alpha_model_vpcNetworkRangeIPv6.java new file mode 100644 index 0000000..457361f --- /dev/null +++ b/scripts/generators/overrides/java/iaas_v2alpha_model_vpcNetworkRangeIPv6.java @@ -0,0 +1,664 @@ +/* + * STACKIT IaaS API + * This API allows you to create and modify IaaS resources. + * + * The version of the OpenAPI document: 2alpha1 + * Contact: stackit-iaas@mail.schwarz + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package cloud.stackit.sdk.iaas.v2alpha1api.model; + +import java.util.Objects; +import com.google.gson.TypeAdapter; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.annotations.SerializedName; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import cloud.stackit.sdk.iaas.v2alpha1api.JSON; + +/** + * Contains the IPv6 properties of a VPC network range. + */ +@javax.annotation.Generated(value = "JavaGenerator", comments = "Generator version: 7.19.0") +public class VPCNetworkRangeIPv6 { + public static final String SERIALIZED_NAME_CREATED_AT = "createdAt"; + @SerializedName(SERIALIZED_NAME_CREATED_AT) + @javax.annotation.Nullable + private OffsetDateTime createdAt; + + public static final String SERIALIZED_NAME_DESCRIPTION = "description"; + @SerializedName(SERIALIZED_NAME_DESCRIPTION) + @javax.annotation.Nullable + private String description; + + public static final String SERIALIZED_NAME_ID = "id"; + @SerializedName(SERIALIZED_NAME_ID) + @javax.annotation.Nullable + private UUID id; + + public static final String SERIALIZED_NAME_LABELS = "labels"; + @SerializedName(SERIALIZED_NAME_LABELS) + @javax.annotation.Nullable + private Object labels; + + public static final String SERIALIZED_NAME_STATUS = "status"; + @SerializedName(SERIALIZED_NAME_STATUS) + @javax.annotation.Nullable + private String status; + + public static final String SERIALIZED_NAME_UPDATED_AT = "updatedAt"; + @SerializedName(SERIALIZED_NAME_UPDATED_AT) + @javax.annotation.Nullable + private OffsetDateTime updatedAt; + + public static final String SERIALIZED_NAME_DEFAULT_PREFIX_LEN = "defaultPrefixLen"; + @SerializedName(SERIALIZED_NAME_DEFAULT_PREFIX_LEN) + @javax.annotation.Nullable + private Long defaultPrefixLen; + + /** + * Gets or Sets ipVersion + */ + @JsonAdapter(IpVersionEnum.Adapter.class) + public enum IpVersionEnum { + IPV6("ipv6"), + + UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api"); + + private String value; + + IpVersionEnum(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + public static IpVersionEnum fromValue(String value) { + for (IpVersionEnum b : IpVersionEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + return UNKNOWN_DEFAULT_OPEN_API; + } + + public static class Adapter extends TypeAdapter { + @Override + public void write(final JsonWriter jsonWriter, final IpVersionEnum enumeration) throws IOException { + jsonWriter.value(enumeration.getValue()); + } + + @Override + public IpVersionEnum read(final JsonReader jsonReader) throws IOException { + String value = jsonReader.nextString(); + return IpVersionEnum.fromValue(value); + } + } + + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + String value = jsonElement.getAsString(); + IpVersionEnum.fromValue(value); + } + } + + public static final String SERIALIZED_NAME_IP_VERSION = "ipVersion"; + @SerializedName(SERIALIZED_NAME_IP_VERSION) + @javax.annotation.Nonnull + private IpVersionEnum ipVersion; + + public static final String SERIALIZED_NAME_MAX_PREFIX_LEN = "maxPrefixLen"; + @SerializedName(SERIALIZED_NAME_MAX_PREFIX_LEN) + @javax.annotation.Nullable + private Long maxPrefixLen; + + public static final String SERIALIZED_NAME_MIN_PREFIX_LEN = "minPrefixLen"; + @SerializedName(SERIALIZED_NAME_MIN_PREFIX_LEN) + @javax.annotation.Nullable + private Long minPrefixLen; + + public static final String SERIALIZED_NAME_NAMESERVERS = "nameservers"; + @SerializedName(SERIALIZED_NAME_NAMESERVERS) + @javax.annotation.Nullable + private List nameservers; + + public static final String SERIALIZED_NAME_PREFIX = "prefix"; + @SerializedName(SERIALIZED_NAME_PREFIX) + @javax.annotation.Nonnull + private String prefix; + + public VPCNetworkRangeIPv6() { + } + + public VPCNetworkRangeIPv6( + OffsetDateTime createdAt, + UUID id, + OffsetDateTime updatedAt + ) { + this(); + this.createdAt = createdAt; + this.id = id; + this.updatedAt = updatedAt; + } + + /** + * Date-time when resource was created. + * @return createdAt + */ + @javax.annotation.Nullable + public OffsetDateTime getCreatedAt() { + return createdAt; + } + + + + public VPCNetworkRangeIPv6 description(@javax.annotation.Nullable String description) { + this.description = description; + return this; + } + + /** + * Description Object. Allows string up to 255 Characters. + * @return description + */ + @javax.annotation.Nullable + public String getDescription() { + return description; + } + + public void setDescription(@javax.annotation.Nullable String description) { + this.description = description; + } + + + /** + * Universally Unique Identifier (UUID). + * @return id + */ + @javax.annotation.Nullable + public UUID getId() { + return id; + } + + + + public VPCNetworkRangeIPv6 labels(@javax.annotation.Nullable Object labels) { + this.labels = labels; + return this; + } + + /** + * Object that represents the labels of an object. Regex for keys: `^(?=.{1,63}$)([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$`. Regex for values: `^(?=.{0,63}$)(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])*$`. Providing a `null` value for a key will remove that key. The `stackit-` prefix is reserved and cannot be used for Keys. + * @return labels + */ + @javax.annotation.Nullable + public Object getLabels() { + return labels; + } + + public void setLabels(@javax.annotation.Nullable Object labels) { + this.labels = labels; + } + + + public VPCNetworkRangeIPv6 status(@javax.annotation.Nullable String status) { + this.status = status; + return this; + } + + /** + * The state of a resource object. Possible values: `CREATING`, `CREATED`, `DELETING`, `DELETED`, `FAILED`, `UPDATED`, `UPDATING`. + * @return status + */ + @javax.annotation.Nullable + public String getStatus() { + return status; + } + + public void setStatus(@javax.annotation.Nullable String status) { + this.status = status; + } + + + /** + * Date-time when resource was last updated. + * @return updatedAt + */ + @javax.annotation.Nullable + public OffsetDateTime getUpdatedAt() { + return updatedAt; + } + + + + public VPCNetworkRangeIPv6 defaultPrefixLen(@javax.annotation.Nullable Long defaultPrefixLen) { + this.defaultPrefixLen = defaultPrefixLen; + return this; + } + + /** + * The ipv6 prefix lengths for subnets or network ranges in the VPC. + * minimum: 0 + * maximum: 128 + * @return defaultPrefixLen + */ + @javax.annotation.Nullable + public Long getDefaultPrefixLen() { + return defaultPrefixLen; + } + + public void setDefaultPrefixLen(@javax.annotation.Nullable Long defaultPrefixLen) { + this.defaultPrefixLen = defaultPrefixLen; + } + + + public VPCNetworkRangeIPv6 ipVersion(@javax.annotation.Nonnull IpVersionEnum ipVersion) { + this.ipVersion = ipVersion; + return this; + } + + /** + * Get ipVersion + * @return ipVersion + */ + @javax.annotation.Nonnull + public IpVersionEnum getIpVersion() { + return ipVersion; + } + + public void setIpVersion(@javax.annotation.Nonnull IpVersionEnum ipVersion) { + this.ipVersion = ipVersion; + } + + + public VPCNetworkRangeIPv6 maxPrefixLen(@javax.annotation.Nullable Long maxPrefixLen) { + this.maxPrefixLen = maxPrefixLen; + return this; + } + + /** + * The ipv6 prefix lengths for subnets or network ranges in the VPC. + * minimum: 0 + * maximum: 128 + * @return maxPrefixLen + */ + @javax.annotation.Nullable + public Long getMaxPrefixLen() { + return maxPrefixLen; + } + + public void setMaxPrefixLen(@javax.annotation.Nullable Long maxPrefixLen) { + this.maxPrefixLen = maxPrefixLen; + } + + + public VPCNetworkRangeIPv6 minPrefixLen(@javax.annotation.Nullable Long minPrefixLen) { + this.minPrefixLen = minPrefixLen; + return this; + } + + /** + * The ipv6 prefix lengths for subnets or network ranges in the VPC. + * minimum: 0 + * maximum: 128 + * @return minPrefixLen + */ + @javax.annotation.Nullable + public Long getMinPrefixLen() { + return minPrefixLen; + } + + public void setMinPrefixLen(@javax.annotation.Nullable Long minPrefixLen) { + this.minPrefixLen = minPrefixLen; + } + + + public VPCNetworkRangeIPv6 nameservers(@javax.annotation.Nullable List nameservers) { + this.nameservers = nameservers; + return this; + } + + public VPCNetworkRangeIPv6 addNameserversItem(String nameserversItem) { + if (this.nameservers == null) { + this.nameservers = new ArrayList<>(); + } + this.nameservers.add(nameserversItem); + return this; + } + + /** + * A list containing DNS Servers/Nameservers for IPv6. + * @return nameservers + */ + @javax.annotation.Nullable + public List getNameservers() { + return nameservers; + } + + public void setNameservers(@javax.annotation.Nullable List nameservers) { + this.nameservers = nameservers; + } + + + public VPCNetworkRangeIPv6 prefix(@javax.annotation.Nonnull String prefix) { + this.prefix = prefix; + return this; + } + + /** + * Classless Inter-Domain Routing (CIDR) for IPv6. + * @return prefix + */ + @javax.annotation.Nonnull + public String getPrefix() { + return prefix; + } + + public void setPrefix(@javax.annotation.Nonnull String prefix) { + this.prefix = prefix; + } + + /** + * A container for additional, undeclared properties. + * This is a holder for any undeclared properties as specified with + * the 'additionalProperties' keyword in the OAS document. + */ + private Map additionalProperties; + + /** + * Set the additional (undeclared) property with the specified name and value. + * If the property does not already exist, create it otherwise replace it. + * + * @param key name of the property + * @param value value of the property + * @return the VPCNetworkRangeIPv6 instance itself + */ + public VPCNetworkRangeIPv6 putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + VPCNetworkRangeIPv6 vpCNetworkRangeIPv6 = (VPCNetworkRangeIPv6) o; + return Objects.equals(this.createdAt, vpCNetworkRangeIPv6.createdAt) && + Objects.equals(this.description, vpCNetworkRangeIPv6.description) && + Objects.equals(this.id, vpCNetworkRangeIPv6.id) && + Objects.equals(this.labels, vpCNetworkRangeIPv6.labels) && + Objects.equals(this.status, vpCNetworkRangeIPv6.status) && + Objects.equals(this.updatedAt, vpCNetworkRangeIPv6.updatedAt) && + Objects.equals(this.defaultPrefixLen, vpCNetworkRangeIPv6.defaultPrefixLen) && + Objects.equals(this.ipVersion, vpCNetworkRangeIPv6.ipVersion) && + Objects.equals(this.maxPrefixLen, vpCNetworkRangeIPv6.maxPrefixLen) && + Objects.equals(this.minPrefixLen, vpCNetworkRangeIPv6.minPrefixLen) && + Objects.equals(this.nameservers, vpCNetworkRangeIPv6.nameservers) && + Objects.equals(this.prefix, vpCNetworkRangeIPv6.prefix)&& + Objects.equals(this.additionalProperties, vpCNetworkRangeIPv6.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(createdAt, description, id, labels, status, updatedAt, defaultPrefixLen, ipVersion, maxPrefixLen, minPrefixLen, nameservers, prefix, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class VPCNetworkRangeIPv6 {\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" labels: ").append(toIndentedString(labels)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" updatedAt: ").append(toIndentedString(updatedAt)).append("\n"); + sb.append(" defaultPrefixLen: ").append(toIndentedString(defaultPrefixLen)).append("\n"); + sb.append(" ipVersion: ").append(toIndentedString(ipVersion)).append("\n"); + sb.append(" maxPrefixLen: ").append(toIndentedString(maxPrefixLen)).append("\n"); + sb.append(" minPrefixLen: ").append(toIndentedString(minPrefixLen)).append("\n"); + sb.append(" nameservers: ").append(toIndentedString(nameservers)).append("\n"); + sb.append(" prefix: ").append(toIndentedString(prefix)).append("\n"); + sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(Arrays.asList("createdAt", "description", "id", "labels", "status", "updatedAt", "defaultPrefixLen", "ipVersion", "maxPrefixLen", "minPrefixLen", "nameservers", "prefix")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(Arrays.asList("ipVersion", "prefix")); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to VPCNetworkRangeIPv6 + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!VPCNetworkRangeIPv6.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field(s) %s in VPCNetworkRangeIPv6 is not found in the empty JSON string", VPCNetworkRangeIPv6.openapiRequiredFields.toString())); + } + } + + // check to make sure all required properties/fields are present in the JSON string + for (String requiredField : VPCNetworkRangeIPv6.openapiRequiredFields) { + if (jsonElement.getAsJsonObject().get(requiredField) == null) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + if ((jsonObj.get("description") != null && !jsonObj.get("description").isJsonNull()) && !jsonObj.get("description").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `description` to be a primitive type in the JSON string but got `%s`", jsonObj.get("description").toString())); + } + if ((jsonObj.get("id") != null && !jsonObj.get("id").isJsonNull()) && !jsonObj.get("id").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `id` to be a primitive type in the JSON string but got `%s`", jsonObj.get("id").toString())); + } + if ((jsonObj.get("status") != null && !jsonObj.get("status").isJsonNull()) && !jsonObj.get("status").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `status` to be a primitive type in the JSON string but got `%s`", jsonObj.get("status").toString())); + } + if (!jsonObj.get("ipVersion").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `ipVersion` to be a primitive type in the JSON string but got `%s`", jsonObj.get("ipVersion").toString())); + } + // OVERRIDE: this if block fixes oneOf issues + if (!"ipv6".equals(jsonObj.get("ipVersion").getAsString())) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expectd the field `ipVersion` to have value `ipv6` but got `%s`", + jsonObj.get("ipVersion") + ) + ); + } + // validate the required field `ipVersion` + IpVersionEnum.validateJsonElement(jsonObj.get("ipVersion")); + // ensure the optional json data is an array if present + if (jsonObj.get("nameservers") != null && !jsonObj.get("nameservers").isJsonNull() && !jsonObj.get("nameservers").isJsonArray()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `nameservers` to be an array in the JSON string but got `%s`", jsonObj.get("nameservers").toString())); + } + if (!jsonObj.get("prefix").isJsonPrimitive()) { + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "Expected the field `prefix` to be a primitive type in the JSON string but got `%s`", jsonObj.get("prefix").toString())); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!VPCNetworkRangeIPv6.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'VPCNetworkRangeIPv6' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter + = gson.getDelegateAdapter(this, TypeToken.get(VPCNetworkRangeIPv6.class)); + + return (TypeAdapter) new TypeAdapter() { + @Override + public void write(JsonWriter out, VPCNetworkRangeIPv6 value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty(entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public VPCNetworkRangeIPv6 read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + VPCNetworkRangeIPv6 instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty(entry.getKey(), entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException(String.format(java.util.Locale.ROOT, "The field `%s` has unknown primitive type. Value: %s", entry.getKey(), entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty(entry.getKey(), gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + + }.nullSafe(); + } + } + + /** + * Create an instance of VPCNetworkRangeIPv6 given an JSON string + * + * @param jsonString JSON string + * @return An instance of VPCNetworkRangeIPv6 + * @throws IOException if the JSON string is invalid with respect to VPCNetworkRangeIPv6 + */ + public static VPCNetworkRangeIPv6 fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, VPCNetworkRangeIPv6.class); + } + + /** + * Convert an instance of VPCNetworkRangeIPv6 to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} + diff --git a/scripts/generators/overrides/java/overrides.properties b/scripts/generators/overrides/java/overrides.properties index 47b5133..ad0273e 100644 --- a/scripts/generators/overrides/java/overrides.properties +++ b/scripts/generators/overrides/java/overrides.properties @@ -21,3 +21,11 @@ iaasV2AlphaApiNexthopBlackhole.hash=ae20d347b1ac740c33ecc3d4ee42c9c9 iaasV2AlphaApiNexthopInternet.path=iaas/src/main/java/cloud/stackit/sdk/iaas/v2alpha1api/model/NexthopInternet.java iaasV2AlphaApiNexthopInternet.replacementPath=iaas_v2alpha_model_nexthopInternet.java iaasV2AlphaApiNexthopInternet.hash=c56c0bab9c1772eacec3638d52af8aaa + +iaasV2AlphaApiVPCNetworkRangIPv4.path=iaas/src/main/java/cloud/stackit/sdk/iaas/v2alpha1api/model/VPCNetworkRangeIPv4.java +iaasV2AlphaApiVPCNetworkRangIPv4.replacementPath=iaas_v2alpha_model_vpcNetworkRangeIPv4.java +iaasV2AlphaApiVPCNetworkRangIPv4.hash=40609d6eae20476897b5e5be0de3d3fc + +iaasV2AlphaApiVPCNetworkRangIPv6.path=iaas/src/main/java/cloud/stackit/sdk/iaas/v2alpha1api/model/VPCNetworkRangeIPv6.java +iaasV2AlphaApiVPCNetworkRangIPv6.replacementPath=iaas_v2alpha_model_vpcNetworkRangeIPv6.java +iaasV2AlphaApiVPCNetworkRangIPv6.hash=d71c09fe5cb8b70c47888681f8d8d7a1