diff --git a/services/serverbackup/oas_commit b/services/serverbackup/oas_commit new file mode 100644 index 0000000..148a7d9 --- /dev/null +++ b/services/serverbackup/oas_commit @@ -0,0 +1 @@ +ed4e4fbee2f5db4d95725108fb3d736e5363fb2f diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/Backup.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/Backup.java index 39ad8cb..5fd73df 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/Backup.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/Backup.java @@ -27,11 +27,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** Backup */ @javax.annotation.Generated( @@ -309,6 +309,50 @@ public void setVolumeBackups( this.volumeBackups = volumeBackups; } + /** + * 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 Backup instance itself + */ + public Backup 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) { @@ -325,13 +369,22 @@ public boolean equals(Object o) { && Objects.equals(this.name, backup.name) && Objects.equals(this.size, backup.size) && Objects.equals(this.status, backup.status) - && Objects.equals(this.volumeBackups, backup.volumeBackups); + && Objects.equals(this.volumeBackups, backup.volumeBackups) + && Objects.equals(this.additionalProperties, backup.additionalProperties); } @Override public int hashCode() { return Objects.hash( - createdAt, expireAt, id, lastRestoredAt, name, size, status, volumeBackups); + createdAt, + expireAt, + id, + lastRestoredAt, + name, + size, + status, + volumeBackups, + additionalProperties); } @Override @@ -346,6 +399,9 @@ public String toString() { sb.append(" size: ").append(toIndentedString(size)).append("\n"); sb.append(" status: ").append(toIndentedString(status)).append("\n"); sb.append(" volumeBackups: ").append(toIndentedString(volumeBackups)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -400,17 +456,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!Backup.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `Backup` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } - // check to make sure all required properties/fields are present in the JSON string for (String requiredField : Backup.openapiRequiredFields) { if (jsonElement.getAsJsonObject().get(requiredField) == null) { @@ -496,6 +541,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { @Override public void write(JsonWriter out, Backup 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); } @@ -503,7 +572,40 @@ public void write(JsonWriter out, Backup value) throws IOException { public Backup read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + Backup 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupJob.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupJob.java index 41e2504..3c74998 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupJob.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupJob.java @@ -24,10 +24,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** BackupJob */ @javax.annotation.Generated( @@ -61,6 +62,50 @@ public void setId(@javax.annotation.Nonnull String id) { this.id = id; } + /** + * 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 BackupJob instance itself + */ + public BackupJob 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) { @@ -70,12 +115,13 @@ public boolean equals(Object o) { return false; } BackupJob backupJob = (BackupJob) o; - return Objects.equals(this.id, backupJob.id); + return Objects.equals(this.id, backupJob.id) + && Objects.equals(this.additionalProperties, backupJob.additionalProperties); } @Override public int hashCode() { - return Objects.hash(id); + return Objects.hash(id, additionalProperties); } @Override @@ -83,6 +129,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class BackupJob {\n"); sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -126,17 +175,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!BackupJob.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `BackupJob` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } - // check to make sure all required properties/fields are present in the JSON string for (String requiredField : BackupJob.openapiRequiredFields) { if (jsonElement.getAsJsonObject().get(requiredField) == null) { @@ -171,6 +209,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { @Override public void write(JsonWriter out, BackupJob 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); } @@ -178,7 +240,40 @@ public void write(JsonWriter out, BackupJob value) throws IOException { public BackupJob read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + BackupJob 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupPolicy.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupPolicy.java index e977874..7814a7d 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupPolicy.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupPolicy.java @@ -24,10 +24,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** BackupPolicy */ @javax.annotation.Generated( @@ -199,6 +200,50 @@ public void setRrule(@javax.annotation.Nullable String rrule) { this.rrule = rrule; } + /** + * 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 BackupPolicy instance itself + */ + public BackupPolicy 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) { @@ -214,12 +259,21 @@ public boolean equals(Object o) { && Objects.equals(this.enabled, backupPolicy.enabled) && Objects.equals(this.id, backupPolicy.id) && Objects.equals(this.name, backupPolicy.name) - && Objects.equals(this.rrule, backupPolicy.rrule); + && Objects.equals(this.rrule, backupPolicy.rrule) + && Objects.equals(this.additionalProperties, backupPolicy.additionalProperties); } @Override public int hashCode() { - return Objects.hash(backupProperties, _default, description, enabled, id, name, rrule); + return Objects.hash( + backupProperties, + _default, + description, + enabled, + id, + name, + rrule, + additionalProperties); } @Override @@ -233,6 +287,9 @@ public String toString() { sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" rrule: ").append(toIndentedString(rrule)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -284,17 +341,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti BackupPolicy.openapiRequiredFields.toString())); } } - - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!BackupPolicy.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `BackupPolicy` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } JsonObject jsonObj = jsonElement.getAsJsonObject(); // validate the optional field `backupProperties` if (jsonObj.get("backupProperties") != null @@ -347,6 +393,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { @Override public void write(JsonWriter out, BackupPolicy 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); } @@ -354,7 +424,40 @@ public void write(JsonWriter out, BackupPolicy value) throws IOException { public BackupPolicy read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + BackupPolicy 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupPolicyBackupProperties.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupPolicyBackupProperties.java index 458901f..ef5e65a 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupPolicyBackupProperties.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupPolicyBackupProperties.java @@ -24,10 +24,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** BackupPolicyBackupProperties */ @javax.annotation.Generated( @@ -83,6 +84,50 @@ public void setRetentionPeriod(@javax.annotation.Nullable Integer retentionPerio this.retentionPeriod = retentionPeriod; } + /** + * 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 BackupPolicyBackupProperties instance itself + */ + public BackupPolicyBackupProperties 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) { @@ -95,12 +140,15 @@ public boolean equals(Object o) { (BackupPolicyBackupProperties) o; return Objects.equals(this.name, backupPolicyBackupProperties.name) && Objects.equals( - this.retentionPeriod, backupPolicyBackupProperties.retentionPeriod); + this.retentionPeriod, backupPolicyBackupProperties.retentionPeriod) + && Objects.equals( + this.additionalProperties, + backupPolicyBackupProperties.additionalProperties); } @Override public int hashCode() { - return Objects.hash(name, retentionPeriod); + return Objects.hash(name, retentionPeriod, additionalProperties); } @Override @@ -109,6 +157,9 @@ public String toString() { sb.append("class BackupPolicyBackupProperties {\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" retentionPeriod: ").append(toIndentedString(retentionPeriod)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -152,17 +203,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti BackupPolicyBackupProperties.openapiRequiredFields.toString())); } } - - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!BackupPolicyBackupProperties.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `BackupPolicyBackupProperties` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } JsonObject jsonObj = jsonElement.getAsJsonObject(); if ((jsonObj.get("name") != null && !jsonObj.get("name").isJsonNull()) && !jsonObj.get("name").isJsonPrimitive()) { @@ -192,6 +232,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, BackupPolicyBackupProperties 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); } @@ -199,7 +263,41 @@ public void write(JsonWriter out, BackupPolicyBackupProperties value) public BackupPolicyBackupProperties read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + BackupPolicyBackupProperties 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupProperties.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupProperties.java index e267229..e48f980 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupProperties.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupProperties.java @@ -25,11 +25,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** BackupProperties */ @javax.annotation.Generated( @@ -119,6 +119,50 @@ public void setVolumeIds(@javax.annotation.Nullable List volumeIds) { this.volumeIds = volumeIds; } + /** + * 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 BackupProperties instance itself + */ + public BackupProperties 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) { @@ -130,12 +174,13 @@ public boolean equals(Object o) { BackupProperties backupProperties = (BackupProperties) o; return Objects.equals(this.name, backupProperties.name) && Objects.equals(this.retentionPeriod, backupProperties.retentionPeriod) - && Objects.equals(this.volumeIds, backupProperties.volumeIds); + && Objects.equals(this.volumeIds, backupProperties.volumeIds) + && Objects.equals(this.additionalProperties, backupProperties.additionalProperties); } @Override public int hashCode() { - return Objects.hash(name, retentionPeriod, volumeIds); + return Objects.hash(name, retentionPeriod, volumeIds, additionalProperties); } @Override @@ -145,6 +190,9 @@ public String toString() { sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" retentionPeriod: ").append(toIndentedString(retentionPeriod)).append("\n"); sb.append(" volumeIds: ").append(toIndentedString(volumeIds)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -188,17 +236,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!BackupProperties.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `BackupProperties` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } - // check to make sure all required properties/fields are present in the JSON string for (String requiredField : BackupProperties.openapiRequiredFields) { if (jsonElement.getAsJsonObject().get(requiredField) == null) { @@ -243,6 +280,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, BackupProperties 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); } @@ -250,7 +311,40 @@ public void write(JsonWriter out, BackupProperties value) public BackupProperties read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + BackupProperties 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupSchedule.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupSchedule.java index 66ac462..83e0053 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupSchedule.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupSchedule.java @@ -24,10 +24,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** BackupSchedule */ @javax.annotation.Generated( @@ -160,6 +161,50 @@ public void setRrule(@javax.annotation.Nonnull String rrule) { this.rrule = rrule; } + /** + * 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 BackupSchedule instance itself + */ + public BackupSchedule 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) { @@ -173,12 +218,13 @@ public boolean equals(Object o) { && Objects.equals(this.enabled, backupSchedule.enabled) && Objects.equals(this.id, backupSchedule.id) && Objects.equals(this.name, backupSchedule.name) - && Objects.equals(this.rrule, backupSchedule.rrule); + && Objects.equals(this.rrule, backupSchedule.rrule) + && Objects.equals(this.additionalProperties, backupSchedule.additionalProperties); } @Override public int hashCode() { - return Objects.hash(backupProperties, enabled, id, name, rrule); + return Objects.hash(backupProperties, enabled, id, name, rrule, additionalProperties); } @Override @@ -190,6 +236,9 @@ public String toString() { sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" rrule: ").append(toIndentedString(rrule)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -236,17 +285,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!BackupSchedule.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `BackupSchedule` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } - // check to make sure all required properties/fields are present in the JSON string for (String requiredField : BackupSchedule.openapiRequiredFields) { if (jsonElement.getAsJsonObject().get(requiredField) == null) { @@ -292,6 +330,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { @Override public void write(JsonWriter out, BackupSchedule 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); } @@ -299,7 +361,40 @@ public void write(JsonWriter out, BackupSchedule value) throws IOException { public BackupSchedule read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + BackupSchedule 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupVolumeBackupsInner.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupVolumeBackupsInner.java index 0835897..2839212 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupVolumeBackupsInner.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/BackupVolumeBackupsInner.java @@ -25,10 +25,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** BackupVolumeBackupsInner */ @javax.annotation.Generated( @@ -244,6 +245,50 @@ public void setVolumeId(@javax.annotation.Nullable String volumeId) { this.volumeId = volumeId; } + /** + * 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 BackupVolumeBackupsInner instance itself + */ + public BackupVolumeBackupsInner 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) { @@ -259,12 +304,21 @@ public boolean equals(Object o) { this.lastRestoredVolumeId, backupVolumeBackupsInner.lastRestoredVolumeId) && Objects.equals(this.size, backupVolumeBackupsInner.size) && Objects.equals(this.status, backupVolumeBackupsInner.status) - && Objects.equals(this.volumeId, backupVolumeBackupsInner.volumeId); + && Objects.equals(this.volumeId, backupVolumeBackupsInner.volumeId) + && Objects.equals( + this.additionalProperties, backupVolumeBackupsInner.additionalProperties); } @Override public int hashCode() { - return Objects.hash(id, lastRestoredAt, lastRestoredVolumeId, size, status, volumeId); + return Objects.hash( + id, + lastRestoredAt, + lastRestoredVolumeId, + size, + status, + volumeId, + additionalProperties); } @Override @@ -279,6 +333,9 @@ public String toString() { sb.append(" size: ").append(toIndentedString(size)).append("\n"); sb.append(" status: ").append(toIndentedString(status)).append("\n"); sb.append(" volumeId: ").append(toIndentedString(volumeId)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -329,17 +386,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti BackupVolumeBackupsInner.openapiRequiredFields.toString())); } } - - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!BackupVolumeBackupsInner.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `BackupVolumeBackupsInner` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } JsonObject jsonObj = jsonElement.getAsJsonObject(); if ((jsonObj.get("id") != null && !jsonObj.get("id").isJsonNull()) && !jsonObj.get("id").isJsonPrimitive()) { @@ -401,6 +447,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, BackupVolumeBackupsInner 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); } @@ -408,7 +478,40 @@ public void write(JsonWriter out, BackupVolumeBackupsInner value) public BackupVolumeBackupsInner read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + BackupVolumeBackupsInner 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/CreateBackupPayload.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/CreateBackupPayload.java index d7073bc..5890751 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/CreateBackupPayload.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/CreateBackupPayload.java @@ -25,11 +25,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** CreateBackupPayload */ @javax.annotation.Generated( @@ -119,6 +119,50 @@ public void setVolumeIds(@javax.annotation.Nullable List volumeIds) { this.volumeIds = volumeIds; } + /** + * 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 CreateBackupPayload instance itself + */ + public CreateBackupPayload 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) { @@ -130,12 +174,14 @@ public boolean equals(Object o) { CreateBackupPayload createBackupPayload = (CreateBackupPayload) o; return Objects.equals(this.name, createBackupPayload.name) && Objects.equals(this.retentionPeriod, createBackupPayload.retentionPeriod) - && Objects.equals(this.volumeIds, createBackupPayload.volumeIds); + && Objects.equals(this.volumeIds, createBackupPayload.volumeIds) + && Objects.equals( + this.additionalProperties, createBackupPayload.additionalProperties); } @Override public int hashCode() { - return Objects.hash(name, retentionPeriod, volumeIds); + return Objects.hash(name, retentionPeriod, volumeIds, additionalProperties); } @Override @@ -145,6 +191,9 @@ public String toString() { sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" retentionPeriod: ").append(toIndentedString(retentionPeriod)).append("\n"); sb.append(" volumeIds: ").append(toIndentedString(volumeIds)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -188,17 +237,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!CreateBackupPayload.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `CreateBackupPayload` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } - // check to make sure all required properties/fields are present in the JSON string for (String requiredField : CreateBackupPayload.openapiRequiredFields) { if (jsonElement.getAsJsonObject().get(requiredField) == null) { @@ -243,6 +281,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, CreateBackupPayload 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); } @@ -250,7 +312,40 @@ public void write(JsonWriter out, CreateBackupPayload value) public CreateBackupPayload read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + CreateBackupPayload 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/CreateBackupSchedulePayload.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/CreateBackupSchedulePayload.java index 46a7f93..124dd95 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/CreateBackupSchedulePayload.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/CreateBackupSchedulePayload.java @@ -24,10 +24,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** CreateBackupSchedulePayload */ @javax.annotation.Generated( @@ -135,6 +136,50 @@ public void setRrule(@javax.annotation.Nonnull String rrule) { this.rrule = rrule; } + /** + * 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 CreateBackupSchedulePayload instance itself + */ + public CreateBackupSchedulePayload 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) { @@ -147,12 +192,15 @@ public boolean equals(Object o) { return Objects.equals(this.backupProperties, createBackupSchedulePayload.backupProperties) && Objects.equals(this.enabled, createBackupSchedulePayload.enabled) && Objects.equals(this.name, createBackupSchedulePayload.name) - && Objects.equals(this.rrule, createBackupSchedulePayload.rrule); + && Objects.equals(this.rrule, createBackupSchedulePayload.rrule) + && Objects.equals( + this.additionalProperties, + createBackupSchedulePayload.additionalProperties); } @Override public int hashCode() { - return Objects.hash(backupProperties, enabled, name, rrule); + return Objects.hash(backupProperties, enabled, name, rrule, additionalProperties); } @Override @@ -163,6 +211,9 @@ public String toString() { sb.append(" enabled: ").append(toIndentedString(enabled)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" rrule: ").append(toIndentedString(rrule)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -208,17 +259,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!CreateBackupSchedulePayload.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `CreateBackupSchedulePayload` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } - // check to make sure all required properties/fields are present in the JSON string for (String requiredField : CreateBackupSchedulePayload.openapiRequiredFields) { if (jsonElement.getAsJsonObject().get(requiredField) == null) { @@ -266,6 +306,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, CreateBackupSchedulePayload 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); } @@ -273,7 +337,41 @@ public void write(JsonWriter out, CreateBackupSchedulePayload value) public CreateBackupSchedulePayload read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + CreateBackupSchedulePayload 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/EnableServiceResourcePayload.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/EnableServiceResourcePayload.java index 18a53ad..1d9fd06 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/EnableServiceResourcePayload.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/EnableServiceResourcePayload.java @@ -24,10 +24,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; import java.util.UUID; /** EnableServiceResourcePayload */ @@ -61,6 +62,50 @@ public void setBackupPolicyId(@javax.annotation.Nullable UUID backupPolicyId) { this.backupPolicyId = backupPolicyId; } + /** + * 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 EnableServiceResourcePayload instance itself + */ + public EnableServiceResourcePayload 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) { @@ -71,12 +116,15 @@ public boolean equals(Object o) { } EnableServiceResourcePayload enableServiceResourcePayload = (EnableServiceResourcePayload) o; - return Objects.equals(this.backupPolicyId, enableServiceResourcePayload.backupPolicyId); + return Objects.equals(this.backupPolicyId, enableServiceResourcePayload.backupPolicyId) + && Objects.equals( + this.additionalProperties, + enableServiceResourcePayload.additionalProperties); } @Override public int hashCode() { - return Objects.hash(backupPolicyId); + return Objects.hash(backupPolicyId, additionalProperties); } @Override @@ -84,6 +132,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class EnableServiceResourcePayload {\n"); sb.append(" backupPolicyId: ").append(toIndentedString(backupPolicyId)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -127,17 +178,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti EnableServiceResourcePayload.openapiRequiredFields.toString())); } } - - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!EnableServiceResourcePayload.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `EnableServiceResourcePayload` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } JsonObject jsonObj = jsonElement.getAsJsonObject(); if ((jsonObj.get("backupPolicyId") != null && !jsonObj.get("backupPolicyId").isJsonNull()) && !jsonObj.get("backupPolicyId").isJsonPrimitive()) { @@ -167,6 +207,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, EnableServiceResourcePayload 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); } @@ -174,7 +238,41 @@ public void write(JsonWriter out, EnableServiceResourcePayload value) public EnableServiceResourcePayload read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + EnableServiceResourcePayload 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/ErrorResponse.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/ErrorResponse.java index d800072..712c39c 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/ErrorResponse.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/ErrorResponse.java @@ -24,10 +24,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** ErrorResponse */ @javax.annotation.Generated( @@ -86,6 +87,50 @@ public void setStatus(@javax.annotation.Nonnull String status) { this.status = status; } + /** + * 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 ErrorResponse instance itself + */ + public ErrorResponse 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) { @@ -96,12 +141,13 @@ public boolean equals(Object o) { } ErrorResponse errorResponse = (ErrorResponse) o; return Objects.equals(this.message, errorResponse.message) - && Objects.equals(this.status, errorResponse.status); + && Objects.equals(this.status, errorResponse.status) + && Objects.equals(this.additionalProperties, errorResponse.additionalProperties); } @Override public int hashCode() { - return Objects.hash(message, status); + return Objects.hash(message, status, additionalProperties); } @Override @@ -110,6 +156,9 @@ public String toString() { sb.append("class ErrorResponse {\n"); sb.append(" message: ").append(toIndentedString(message)).append("\n"); sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -153,17 +202,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!ErrorResponse.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `ErrorResponse` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } - // check to make sure all required properties/fields are present in the JSON string for (String requiredField : ErrorResponse.openapiRequiredFields) { if (jsonElement.getAsJsonObject().get(requiredField) == null) { @@ -204,6 +242,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { @Override public void write(JsonWriter out, ErrorResponse 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); } @@ -211,7 +273,40 @@ public void write(JsonWriter out, ErrorResponse value) throws IOException { public ErrorResponse read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + ErrorResponse 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupPoliciesResponse.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupPoliciesResponse.java index c36a4a7..ce2c16f 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupPoliciesResponse.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupPoliciesResponse.java @@ -26,11 +26,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** GetBackupPoliciesResponse */ @javax.annotation.Generated( @@ -70,6 +70,50 @@ public void setItems(@javax.annotation.Nullable List items) { this.items = items; } + /** + * 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 GetBackupPoliciesResponse instance itself + */ + public GetBackupPoliciesResponse 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) { @@ -79,12 +123,14 @@ public boolean equals(Object o) { return false; } GetBackupPoliciesResponse getBackupPoliciesResponse = (GetBackupPoliciesResponse) o; - return Objects.equals(this.items, getBackupPoliciesResponse.items); + return Objects.equals(this.items, getBackupPoliciesResponse.items) + && Objects.equals( + this.additionalProperties, getBackupPoliciesResponse.additionalProperties); } @Override public int hashCode() { - return Objects.hash(items); + return Objects.hash(items, additionalProperties); } @Override @@ -92,6 +138,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class GetBackupPoliciesResponse {\n"); sb.append(" items: ").append(toIndentedString(items)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -134,17 +183,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti GetBackupPoliciesResponse.openapiRequiredFields.toString())); } } - - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!GetBackupPoliciesResponse.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `GetBackupPoliciesResponse` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } JsonObject jsonObj = jsonElement.getAsJsonObject(); if (jsonObj.get("items") != null && !jsonObj.get("items").isJsonNull()) { JsonArray jsonArrayitems = jsonObj.getAsJsonArray("items"); @@ -184,6 +222,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, GetBackupPoliciesResponse 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); } @@ -191,7 +253,40 @@ public void write(JsonWriter out, GetBackupPoliciesResponse value) public GetBackupPoliciesResponse read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + GetBackupPoliciesResponse 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupSchedulesResponse.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupSchedulesResponse.java index bcbfc78..1e218c8 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupSchedulesResponse.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupSchedulesResponse.java @@ -26,11 +26,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** GetBackupSchedulesResponse */ @javax.annotation.Generated( @@ -70,6 +70,50 @@ public void setItems(@javax.annotation.Nullable List items) { this.items = items; } + /** + * 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 GetBackupSchedulesResponse instance itself + */ + public GetBackupSchedulesResponse 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) { @@ -79,12 +123,14 @@ public boolean equals(Object o) { return false; } GetBackupSchedulesResponse getBackupSchedulesResponse = (GetBackupSchedulesResponse) o; - return Objects.equals(this.items, getBackupSchedulesResponse.items); + return Objects.equals(this.items, getBackupSchedulesResponse.items) + && Objects.equals( + this.additionalProperties, getBackupSchedulesResponse.additionalProperties); } @Override public int hashCode() { - return Objects.hash(items); + return Objects.hash(items, additionalProperties); } @Override @@ -92,6 +138,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class GetBackupSchedulesResponse {\n"); sb.append(" items: ").append(toIndentedString(items)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -134,17 +183,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti GetBackupSchedulesResponse.openapiRequiredFields.toString())); } } - - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!GetBackupSchedulesResponse.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `GetBackupSchedulesResponse` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } JsonObject jsonObj = jsonElement.getAsJsonObject(); if (jsonObj.get("items") != null && !jsonObj.get("items").isJsonNull()) { JsonArray jsonArrayitems = jsonObj.getAsJsonArray("items"); @@ -184,6 +222,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, GetBackupSchedulesResponse 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); } @@ -191,7 +253,40 @@ public void write(JsonWriter out, GetBackupSchedulesResponse value) public GetBackupSchedulesResponse read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + GetBackupSchedulesResponse 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupServiceResponse.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupServiceResponse.java index 7223249..3130568 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupServiceResponse.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupServiceResponse.java @@ -24,10 +24,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** GetBackupServiceResponse */ @javax.annotation.Generated( @@ -59,6 +60,50 @@ public void setEnabled(@javax.annotation.Nullable Boolean enabled) { this.enabled = enabled; } + /** + * 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 GetBackupServiceResponse instance itself + */ + public GetBackupServiceResponse 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) { @@ -68,12 +113,14 @@ public boolean equals(Object o) { return false; } GetBackupServiceResponse getBackupServiceResponse = (GetBackupServiceResponse) o; - return Objects.equals(this.enabled, getBackupServiceResponse.enabled); + return Objects.equals(this.enabled, getBackupServiceResponse.enabled) + && Objects.equals( + this.additionalProperties, getBackupServiceResponse.additionalProperties); } @Override public int hashCode() { - return Objects.hash(enabled); + return Objects.hash(enabled, additionalProperties); } @Override @@ -81,6 +128,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class GetBackupServiceResponse {\n"); sb.append(" enabled: ").append(toIndentedString(enabled)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -123,17 +173,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti GetBackupServiceResponse.openapiRequiredFields.toString())); } } - - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!GetBackupServiceResponse.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `GetBackupServiceResponse` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } JsonObject jsonObj = jsonElement.getAsJsonObject(); } @@ -155,6 +194,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, GetBackupServiceResponse 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); } @@ -162,7 +225,40 @@ public void write(JsonWriter out, GetBackupServiceResponse value) public GetBackupServiceResponse read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + GetBackupServiceResponse 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupsListResponse.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupsListResponse.java index c34c5d1..b570cd8 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupsListResponse.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/GetBackupsListResponse.java @@ -26,11 +26,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** GetBackupsListResponse */ @javax.annotation.Generated( @@ -70,6 +70,50 @@ public void setItems(@javax.annotation.Nullable List items) { this.items = items; } + /** + * 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 GetBackupsListResponse instance itself + */ + public GetBackupsListResponse 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) { @@ -79,12 +123,14 @@ public boolean equals(Object o) { return false; } GetBackupsListResponse getBackupsListResponse = (GetBackupsListResponse) o; - return Objects.equals(this.items, getBackupsListResponse.items); + return Objects.equals(this.items, getBackupsListResponse.items) + && Objects.equals( + this.additionalProperties, getBackupsListResponse.additionalProperties); } @Override public int hashCode() { - return Objects.hash(items); + return Objects.hash(items, additionalProperties); } @Override @@ -92,6 +138,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class GetBackupsListResponse {\n"); sb.append(" items: ").append(toIndentedString(items)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -134,17 +183,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti GetBackupsListResponse.openapiRequiredFields.toString())); } } - - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!GetBackupsListResponse.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `GetBackupsListResponse` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } JsonObject jsonObj = jsonElement.getAsJsonObject(); if (jsonObj.get("items") != null && !jsonObj.get("items").isJsonNull()) { JsonArray jsonArrayitems = jsonObj.getAsJsonArray("items"); @@ -183,6 +221,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, GetBackupsListResponse 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); } @@ -190,7 +252,40 @@ public void write(JsonWriter out, GetBackupsListResponse value) public GetBackupsListResponse read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + GetBackupsListResponse 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/RestoreBackupPayload.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/RestoreBackupPayload.java index 6de6a8c..ca2ea29 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/RestoreBackupPayload.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/RestoreBackupPayload.java @@ -25,11 +25,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** RestoreBackupPayload */ @javax.annotation.Generated( @@ -97,6 +97,50 @@ public void setVolumeIds(@javax.annotation.Nullable List volumeIds) { this.volumeIds = volumeIds; } + /** + * 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 RestoreBackupPayload instance itself + */ + public RestoreBackupPayload 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) { @@ -108,12 +152,14 @@ public boolean equals(Object o) { RestoreBackupPayload restoreBackupPayload = (RestoreBackupPayload) o; return Objects.equals( this.startServerAfterRestore, restoreBackupPayload.startServerAfterRestore) - && Objects.equals(this.volumeIds, restoreBackupPayload.volumeIds); + && Objects.equals(this.volumeIds, restoreBackupPayload.volumeIds) + && Objects.equals( + this.additionalProperties, restoreBackupPayload.additionalProperties); } @Override public int hashCode() { - return Objects.hash(startServerAfterRestore, volumeIds); + return Objects.hash(startServerAfterRestore, volumeIds, additionalProperties); } @Override @@ -124,6 +170,9 @@ public String toString() { .append(toIndentedString(startServerAfterRestore)) .append("\n"); sb.append(" volumeIds: ").append(toIndentedString(volumeIds)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -167,17 +216,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!RestoreBackupPayload.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `RestoreBackupPayload` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } - // check to make sure all required properties/fields are present in the JSON string for (String requiredField : RestoreBackupPayload.openapiRequiredFields) { if (jsonElement.getAsJsonObject().get(requiredField) == null) { @@ -216,6 +254,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, RestoreBackupPayload 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); } @@ -223,7 +285,40 @@ public void write(JsonWriter out, RestoreBackupPayload value) public RestoreBackupPayload read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + RestoreBackupPayload 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/RestoreVolumeBackupPayload.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/RestoreVolumeBackupPayload.java index 314de92..13c9efb 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/RestoreVolumeBackupPayload.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/RestoreVolumeBackupPayload.java @@ -24,10 +24,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** RestoreVolumeBackupPayload */ @javax.annotation.Generated( @@ -62,6 +63,50 @@ public void setRestoreVolumeId(@javax.annotation.Nonnull String restoreVolumeId) this.restoreVolumeId = restoreVolumeId; } + /** + * 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 RestoreVolumeBackupPayload instance itself + */ + public RestoreVolumeBackupPayload 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) { @@ -71,12 +116,14 @@ public boolean equals(Object o) { return false; } RestoreVolumeBackupPayload restoreVolumeBackupPayload = (RestoreVolumeBackupPayload) o; - return Objects.equals(this.restoreVolumeId, restoreVolumeBackupPayload.restoreVolumeId); + return Objects.equals(this.restoreVolumeId, restoreVolumeBackupPayload.restoreVolumeId) + && Objects.equals( + this.additionalProperties, restoreVolumeBackupPayload.additionalProperties); } @Override public int hashCode() { - return Objects.hash(restoreVolumeId); + return Objects.hash(restoreVolumeId, additionalProperties); } @Override @@ -84,6 +131,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class RestoreVolumeBackupPayload {\n"); sb.append(" restoreVolumeId: ").append(toIndentedString(restoreVolumeId)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -127,17 +177,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!RestoreVolumeBackupPayload.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `RestoreVolumeBackupPayload` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } - // check to make sure all required properties/fields are present in the JSON string for (String requiredField : RestoreVolumeBackupPayload.openapiRequiredFields) { if (jsonElement.getAsJsonObject().get(requiredField) == null) { @@ -174,6 +213,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, RestoreVolumeBackupPayload 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); } @@ -181,7 +244,40 @@ public void write(JsonWriter out, RestoreVolumeBackupPayload value) public RestoreVolumeBackupPayload read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + RestoreVolumeBackupPayload 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( + "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(); } diff --git a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/UpdateBackupSchedulePayload.java b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/UpdateBackupSchedulePayload.java index 9d558dd..e1732d7 100644 --- a/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/UpdateBackupSchedulePayload.java +++ b/services/serverbackup/src/main/java/cloud/stackit/sdk/serverbackup/model/UpdateBackupSchedulePayload.java @@ -24,10 +24,11 @@ import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; /** UpdateBackupSchedulePayload */ @javax.annotation.Generated( @@ -135,6 +136,50 @@ public void setRrule(@javax.annotation.Nonnull String rrule) { this.rrule = rrule; } + /** + * 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 UpdateBackupSchedulePayload instance itself + */ + public UpdateBackupSchedulePayload 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) { @@ -147,12 +192,15 @@ public boolean equals(Object o) { return Objects.equals(this.backupProperties, updateBackupSchedulePayload.backupProperties) && Objects.equals(this.enabled, updateBackupSchedulePayload.enabled) && Objects.equals(this.name, updateBackupSchedulePayload.name) - && Objects.equals(this.rrule, updateBackupSchedulePayload.rrule); + && Objects.equals(this.rrule, updateBackupSchedulePayload.rrule) + && Objects.equals( + this.additionalProperties, + updateBackupSchedulePayload.additionalProperties); } @Override public int hashCode() { - return Objects.hash(backupProperties, enabled, name, rrule); + return Objects.hash(backupProperties, enabled, name, rrule, additionalProperties); } @Override @@ -163,6 +211,9 @@ public String toString() { sb.append(" enabled: ").append(toIndentedString(enabled)).append("\n"); sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" rrule: ").append(toIndentedString(rrule)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); sb.append("}"); return sb.toString(); } @@ -208,17 +259,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } - Set> entries = jsonElement.getAsJsonObject().entrySet(); - // check to see if the JSON string contains additional fields - for (Map.Entry entry : entries) { - if (!UpdateBackupSchedulePayload.openapiFields.contains(entry.getKey())) { - throw new IllegalArgumentException( - String.format( - "The field `%s` in the JSON string is not defined in the `UpdateBackupSchedulePayload` properties. JSON: %s", - entry.getKey(), jsonElement.toString())); - } - } - // check to make sure all required properties/fields are present in the JSON string for (String requiredField : UpdateBackupSchedulePayload.openapiRequiredFields) { if (jsonElement.getAsJsonObject().get(requiredField) == null) { @@ -266,6 +306,30 @@ public TypeAdapter create(Gson gson, TypeToken type) { public void write(JsonWriter out, UpdateBackupSchedulePayload 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); } @@ -273,7 +337,41 @@ public void write(JsonWriter out, UpdateBackupSchedulePayload value) public UpdateBackupSchedulePayload read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); - return thisAdapter.fromJsonTree(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + UpdateBackupSchedulePayload 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( + "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(); }