Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions services/serverbackup/oas_commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ed4e4fbee2f5db4d95725108fb3d736e5363fb2f
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<String, Object> 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<String, Object>();
}
this.additionalProperties.put(key, value);
return this;
}

/**
* Return the additional (undeclared) property.
*
* @return a map of objects
*/
public Map<String, Object> 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) {
Expand All @@ -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
Expand All @@ -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();
}
Expand Down Expand Up @@ -400,17 +456,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
}
}

Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
// check to see if the JSON string contains additional fields
for (Map.Entry<String, JsonElement> 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) {
Expand Down Expand Up @@ -496,14 +541,71 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> 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<String, Object> entry :
value.getAdditionalProperties().entrySet()) {
if (entry.getValue() instanceof String)
obj.addProperty(entry.getKey(), (String) entry.getValue());
else if (entry.getValue() instanceof Number)
obj.addProperty(entry.getKey(), (Number) entry.getValue());
else if (entry.getValue() instanceof Boolean)
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
else if (entry.getValue() instanceof Character)
obj.addProperty(
entry.getKey(), (Character) entry.getValue());
else {
JsonElement jsonElement = gson.toJsonTree(entry.getValue());
if (jsonElement.isJsonArray()) {
obj.add(entry.getKey(), jsonElement.getAsJsonArray());
} else {
obj.add(entry.getKey(), jsonElement.getAsJsonObject());
}
}
}
}
elementAdapter.write(out, obj);
}

@Override
public 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<String, JsonElement> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<String, Object> 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<String, Object>();
}
this.additionalProperties.put(key, value);
return this;
}

/**
* Return the additional (undeclared) property.
*
* @return a map of objects
*/
public Map<String, Object> 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) {
Expand All @@ -70,19 +115,23 @@ 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
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();
}
Expand Down Expand Up @@ -126,17 +175,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
}
}

Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
// check to see if the JSON string contains additional fields
for (Map.Entry<String, JsonElement> 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) {
Expand Down Expand Up @@ -171,14 +209,71 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> 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<String, Object> entry :
value.getAdditionalProperties().entrySet()) {
if (entry.getValue() instanceof String)
obj.addProperty(entry.getKey(), (String) entry.getValue());
else if (entry.getValue() instanceof Number)
obj.addProperty(entry.getKey(), (Number) entry.getValue());
else if (entry.getValue() instanceof Boolean)
obj.addProperty(entry.getKey(), (Boolean) entry.getValue());
else if (entry.getValue() instanceof Character)
obj.addProperty(
entry.getKey(), (Character) entry.getValue());
else {
JsonElement jsonElement = gson.toJsonTree(entry.getValue());
if (jsonElement.isJsonArray()) {
obj.add(entry.getKey(), jsonElement.getAsJsonArray());
} else {
obj.add(entry.getKey(), jsonElement.getAsJsonObject());
}
}
}
}
elementAdapter.write(out, obj);
}

@Override
public 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<String, JsonElement> 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();
}
Expand Down
Loading