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/resourcemanager/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 @@ -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;
import java.util.UUID;

/** ContainerSearchResult */
Expand Down Expand Up @@ -239,6 +240,50 @@ public void setOrganizationId(@javax.annotation.Nullable UUID organizationId) {
this.organizationId = organizationId;
}

/**
* 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 ContainerSearchResult instance itself
*/
public ContainerSearchResult 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 @@ -253,12 +298,21 @@ public boolean equals(Object o) {
&& Objects.equals(this.id, containerSearchResult.id)
&& Objects.equals(this.lifecycleState, containerSearchResult.lifecycleState)
&& Objects.equals(this.name, containerSearchResult.name)
&& Objects.equals(this.organizationId, containerSearchResult.organizationId);
&& Objects.equals(this.organizationId, containerSearchResult.organizationId)
&& Objects.equals(
this.additionalProperties, containerSearchResult.additionalProperties);
}

@Override
public int hashCode() {
return Objects.hash(containerId, containerType, id, lifecycleState, name, organizationId);
return Objects.hash(
containerId,
containerType,
id,
lifecycleState,
name,
organizationId,
additionalProperties);
}

@Override
Expand All @@ -271,6 +325,9 @@ public String toString() {
sb.append(" lifecycleState: ").append(toIndentedString(lifecycleState)).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" organizationId: ").append(toIndentedString(organizationId)).append("\n");
sb.append(" additionalProperties: ")
.append(toIndentedString(additionalProperties))
.append("\n");
sb.append("}");
return sb.toString();
}
Expand Down Expand Up @@ -323,17 +380,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 (!ContainerSearchResult.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(
String.format(
"The field `%s` in the JSON string is not defined in the `ContainerSearchResult` properties. JSON: %s",
entry.getKey(), jsonElement.toString()));
}
}

// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : ContainerSearchResult.openapiRequiredFields) {
if (jsonElement.getAsJsonObject().get(requiredField) == null) {
Expand Down Expand Up @@ -400,14 +446,71 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
public void write(JsonWriter out, ContainerSearchResult 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 ContainerSearchResult 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
ContainerSearchResult 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 @@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -158,6 +159,50 @@ public void setName(@javax.annotation.Nonnull String name) {
this.name = name;
}

/**
* 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 CreateFolderPayload instance itself
*/
public CreateFolderPayload 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 @@ -170,12 +215,14 @@ public boolean equals(Object o) {
return Objects.equals(this.containerParentId, createFolderPayload.containerParentId)
&& Objects.equals(this.labels, createFolderPayload.labels)
&& Objects.equals(this.members, createFolderPayload.members)
&& Objects.equals(this.name, createFolderPayload.name);
&& Objects.equals(this.name, createFolderPayload.name)
&& Objects.equals(
this.additionalProperties, createFolderPayload.additionalProperties);
}

@Override
public int hashCode() {
return Objects.hash(containerParentId, labels, members, name);
return Objects.hash(containerParentId, labels, members, name, additionalProperties);
}

@Override
Expand All @@ -188,6 +235,9 @@ public String toString() {
sb.append(" labels: ").append(toIndentedString(labels)).append("\n");
sb.append(" members: ").append(toIndentedString(members)).append("\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" additionalProperties: ")
.append(toIndentedString(additionalProperties))
.append("\n");
sb.append("}");
return sb.toString();
}
Expand Down Expand Up @@ -233,17 +283,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 (!CreateFolderPayload.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(
String.format(
"The field `%s` in the JSON string is not defined in the `CreateFolderPayload` properties. JSON: %s",
entry.getKey(), jsonElement.toString()));
}
}

// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : CreateFolderPayload.openapiRequiredFields) {
if (jsonElement.getAsJsonObject().get(requiredField) == null) {
Expand Down Expand Up @@ -303,14 +342,71 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
public void write(JsonWriter out, CreateFolderPayload 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 CreateFolderPayload 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
CreateFolderPayload 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