diff --git a/services/loadbalancer/oas_commit b/services/loadbalancer/oas_commit index 6694ae6..f1fc529 100644 --- a/services/loadbalancer/oas_commit +++ b/services/loadbalancer/oas_commit @@ -1 +1 @@ -29ed135519d2a7b1b043cd0c8243bb8d423a784b +a0507fbc8a743f261058ef285885928d2e8e0355 diff --git a/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/JSON.java b/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/JSON.java index b2dc44e..195201e 100644 --- a/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/JSON.java +++ b/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/JSON.java @@ -119,6 +119,9 @@ private static Class getClassByDiscriminator( gsonBuilder.registerTypeAdapterFactory( new cloud.stackit.sdk.loadbalancer.model.GoogleProtobufAny .CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory( + new cloud.stackit.sdk.loadbalancer.model.HttpHealthChecks + .CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory( new cloud.stackit.sdk.loadbalancer.model.ListCredentialsResponse .CustomTypeAdapterFactory()); @@ -172,6 +175,8 @@ private static Class getClassByDiscriminator( new cloud.stackit.sdk.loadbalancer.model.Target.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory( new cloud.stackit.sdk.loadbalancer.model.TargetPool.CustomTypeAdapterFactory()); + gsonBuilder.registerTypeAdapterFactory( + new cloud.stackit.sdk.loadbalancer.model.TlsConfig.CustomTypeAdapterFactory()); gsonBuilder.registerTypeAdapterFactory( new cloud.stackit.sdk.loadbalancer.model.UpdateCredentialsPayload .CustomTypeAdapterFactory()); diff --git a/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/model/ActiveHealthCheck.java b/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/model/ActiveHealthCheck.java index 6e41e96..d88dd93 100644 --- a/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/model/ActiveHealthCheck.java +++ b/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/model/ActiveHealthCheck.java @@ -35,11 +35,21 @@ value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.19.0") public class ActiveHealthCheck { + public static final String SERIALIZED_NAME_ALT_PORT = "altPort"; + + @SerializedName(SERIALIZED_NAME_ALT_PORT) + @javax.annotation.Nullable private Integer altPort; + public static final String SERIALIZED_NAME_HEALTHY_THRESHOLD = "healthyThreshold"; @SerializedName(SERIALIZED_NAME_HEALTHY_THRESHOLD) @javax.annotation.Nullable private Integer healthyThreshold; + public static final String SERIALIZED_NAME_HTTP_HEALTH_CHECKS = "httpHealthChecks"; + + @SerializedName(SERIALIZED_NAME_HTTP_HEALTH_CHECKS) + @javax.annotation.Nullable private HttpHealthChecks httpHealthChecks; + public static final String SERIALIZED_NAME_INTERVAL = "interval"; @SerializedName(SERIALIZED_NAME_INTERVAL) @@ -62,6 +72,24 @@ public class ActiveHealthCheck { public ActiveHealthCheck() {} + public ActiveHealthCheck altPort(@javax.annotation.Nullable Integer altPort) { + this.altPort = altPort; + return this; + } + + /** + * Overrides the default port used for health check probes. + * + * @return altPort + */ + @javax.annotation.Nullable public Integer getAltPort() { + return altPort; + } + + public void setAltPort(@javax.annotation.Nullable Integer altPort) { + this.altPort = altPort; + } + public ActiveHealthCheck healthyThreshold(@javax.annotation.Nullable Integer healthyThreshold) { this.healthyThreshold = healthyThreshold; return this; @@ -80,6 +108,25 @@ public void setHealthyThreshold(@javax.annotation.Nullable Integer healthyThresh this.healthyThreshold = healthyThreshold; } + public ActiveHealthCheck httpHealthChecks( + @javax.annotation.Nullable HttpHealthChecks httpHealthChecks) { + this.httpHealthChecks = httpHealthChecks; + return this; + } + + /** + * Get httpHealthChecks + * + * @return httpHealthChecks + */ + @javax.annotation.Nullable public HttpHealthChecks getHttpHealthChecks() { + return httpHealthChecks; + } + + public void setHttpHealthChecks(@javax.annotation.Nullable HttpHealthChecks httpHealthChecks) { + this.httpHealthChecks = httpHealthChecks; + } + public ActiveHealthCheck interval(@javax.annotation.Nullable String interval) { this.interval = interval; return this; @@ -206,7 +253,9 @@ public boolean equals(Object o) { return false; } ActiveHealthCheck activeHealthCheck = (ActiveHealthCheck) o; - return Objects.equals(this.healthyThreshold, activeHealthCheck.healthyThreshold) + return Objects.equals(this.altPort, activeHealthCheck.altPort) + && Objects.equals(this.healthyThreshold, activeHealthCheck.healthyThreshold) + && Objects.equals(this.httpHealthChecks, activeHealthCheck.httpHealthChecks) && Objects.equals(this.interval, activeHealthCheck.interval) && Objects.equals(this.intervalJitter, activeHealthCheck.intervalJitter) && Objects.equals(this.timeout, activeHealthCheck.timeout) @@ -218,7 +267,9 @@ public boolean equals(Object o) { @Override public int hashCode() { return Objects.hash( + altPort, healthyThreshold, + httpHealthChecks, interval, intervalJitter, timeout, @@ -230,7 +281,9 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ActiveHealthCheck {\n"); + sb.append(" altPort: ").append(toIndentedString(altPort)).append("\n"); sb.append(" healthyThreshold: ").append(toIndentedString(healthyThreshold)).append("\n"); + sb.append(" httpHealthChecks: ").append(toIndentedString(httpHealthChecks)).append("\n"); sb.append(" interval: ").append(toIndentedString(interval)).append("\n"); sb.append(" intervalJitter: ").append(toIndentedString(intervalJitter)).append("\n"); sb.append(" timeout: ").append(toIndentedString(timeout)).append("\n"); @@ -263,7 +316,9 @@ private String toIndentedString(Object o) { openapiFields = new HashSet( Arrays.asList( + "altPort", "healthyThreshold", + "httpHealthChecks", "interval", "intervalJitter", "timeout", @@ -291,6 +346,11 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti } } JsonObject jsonObj = jsonElement.getAsJsonObject(); + // validate the optional field `httpHealthChecks` + if (jsonObj.get("httpHealthChecks") != null + && !jsonObj.get("httpHealthChecks").isJsonNull()) { + HttpHealthChecks.validateJsonElement(jsonObj.get("httpHealthChecks")); + } if ((jsonObj.get("interval") != null && !jsonObj.get("interval").isJsonNull()) && !jsonObj.get("interval").isJsonPrimitive()) { throw new IllegalArgumentException( diff --git a/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/model/HttpHealthChecks.java b/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/model/HttpHealthChecks.java new file mode 100644 index 0000000..15727d9 --- /dev/null +++ b/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/model/HttpHealthChecks.java @@ -0,0 +1,367 @@ +/* + * STACKIT Network Load Balancer API + * This API offers an interface to provision and manage load balancing servers in your STACKIT project. It also has the possibility of pooling target servers for load balancing purposes. For each load balancer provided, two VMs are deployed in your OpenStack project subject to a fee. + * + * The version of the OpenAPI document: 2.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package cloud.stackit.sdk.loadbalancer.model; + +import cloud.stackit.sdk.loadbalancer.JSON; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.annotations.SerializedName; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +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; + +/** Options for the HTTP health checking. */ +@javax.annotation.Generated( + value = "org.openapitools.codegen.languages.JavaClientCodegen", + comments = "Generator version: 7.19.0") +public class HttpHealthChecks { + public static final String SERIALIZED_NAME_OK_STATUSES = "okStatuses"; + + @SerializedName(SERIALIZED_NAME_OK_STATUSES) + @javax.annotation.Nullable private List okStatuses = new ArrayList<>(); + + public static final String SERIALIZED_NAME_PATH = "path"; + + @SerializedName(SERIALIZED_NAME_PATH) + @javax.annotation.Nullable private String path; + + public static final String SERIALIZED_NAME_TLS = "tls"; + + @SerializedName(SERIALIZED_NAME_TLS) + @javax.annotation.Nullable private TlsConfig tls; + + public HttpHealthChecks() {} + + public HttpHealthChecks okStatuses(@javax.annotation.Nullable List okStatuses) { + this.okStatuses = okStatuses; + return this; + } + + public HttpHealthChecks addOkStatusesItem(String okStatusesItem) { + if (this.okStatuses == null) { + this.okStatuses = new ArrayList<>(); + } + this.okStatuses.add(okStatusesItem); + return this; + } + + /** + * List of HTTP status codes that indicate a healthy response + * + * @return okStatuses + */ + @javax.annotation.Nullable public List getOkStatuses() { + return okStatuses; + } + + public void setOkStatuses(@javax.annotation.Nullable List okStatuses) { + this.okStatuses = okStatuses; + } + + public HttpHealthChecks path(@javax.annotation.Nullable String path) { + this.path = path; + return this; + } + + /** + * Path to send the health check request to + * + * @return path + */ + @javax.annotation.Nullable public String getPath() { + return path; + } + + public void setPath(@javax.annotation.Nullable String path) { + this.path = path; + } + + public HttpHealthChecks tls(@javax.annotation.Nullable TlsConfig tls) { + this.tls = tls; + return this; + } + + /** + * Get tls + * + * @return tls + */ + @javax.annotation.Nullable public TlsConfig getTls() { + return tls; + } + + public void setTls(@javax.annotation.Nullable TlsConfig tls) { + this.tls = tls; + } + + /** + * 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 HttpHealthChecks instance itself + */ + public HttpHealthChecks putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + HttpHealthChecks httpHealthChecks = (HttpHealthChecks) o; + return Objects.equals(this.okStatuses, httpHealthChecks.okStatuses) + && Objects.equals(this.path, httpHealthChecks.path) + && Objects.equals(this.tls, httpHealthChecks.tls) + && Objects.equals(this.additionalProperties, httpHealthChecks.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(okStatuses, path, tls, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class HttpHealthChecks {\n"); + sb.append(" okStatuses: ").append(toIndentedString(okStatuses)).append("\n"); + sb.append(" path: ").append(toIndentedString(path)).append("\n"); + sb.append(" tls: ").append(toIndentedString(tls)).append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first + * line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = new HashSet(Arrays.asList("okStatuses", "path", "tls")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(0); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to HttpHealthChecks + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!HttpHealthChecks.openapiRequiredFields + .isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "The required field(s) %s in HttpHealthChecks is not found in the empty JSON string", + HttpHealthChecks.openapiRequiredFields.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // ensure the optional json data is an array if present + if (jsonObj.get("okStatuses") != null + && !jsonObj.get("okStatuses").isJsonNull() + && !jsonObj.get("okStatuses").isJsonArray()) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expected the field `okStatuses` to be an array in the JSON string but got `%s`", + jsonObj.get("okStatuses").toString())); + } + if ((jsonObj.get("path") != null && !jsonObj.get("path").isJsonNull()) + && !jsonObj.get("path").isJsonPrimitive()) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expected the field `path` to be a primitive type in the JSON string but got `%s`", + jsonObj.get("path").toString())); + } + // validate the optional field `tls` + if (jsonObj.get("tls") != null && !jsonObj.get("tls").isJsonNull()) { + TlsConfig.validateJsonElement(jsonObj.get("tls")); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!HttpHealthChecks.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'HttpHealthChecks' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter = + gson.getDelegateAdapter(this, TypeToken.get(HttpHealthChecks.class)); + + return (TypeAdapter) + new TypeAdapter() { + @Override + public void write(JsonWriter out, HttpHealthChecks value) + throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : + value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty( + entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public HttpHealthChecks read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + HttpHealthChecks instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty( + entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty( + entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty( + entry.getKey(), + entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "The field `%s` has unknown primitive type. Value: %s", + entry.getKey(), + entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty( + entry.getKey(), + gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty( + entry.getKey(), + gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + }.nullSafe(); + } + } + + /** + * Create an instance of HttpHealthChecks given an JSON string + * + * @param jsonString JSON string + * @return An instance of HttpHealthChecks + * @throws IOException if the JSON string is invalid with respect to HttpHealthChecks + */ + public static HttpHealthChecks fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, HttpHealthChecks.class); + } + + /** + * Convert an instance of HttpHealthChecks to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +} diff --git a/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/model/TlsConfig.java b/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/model/TlsConfig.java new file mode 100644 index 0000000..d38589b --- /dev/null +++ b/services/loadbalancer/src/main/java/cloud/stackit/sdk/loadbalancer/model/TlsConfig.java @@ -0,0 +1,359 @@ +/* + * STACKIT Network Load Balancer API + * This API offers an interface to provision and manage load balancing servers in your STACKIT project. It also has the possibility of pooling target servers for load balancing purposes. For each load balancer provided, two VMs are deployed in your OpenStack project subject to a fee. + * + * The version of the OpenAPI document: 2.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package cloud.stackit.sdk.loadbalancer.model; + +import cloud.stackit.sdk.loadbalancer.JSON; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.annotations.SerializedName; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +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; + +/** Set this to configure TLS settings. */ +@javax.annotation.Generated( + value = "org.openapitools.codegen.languages.JavaClientCodegen", + comments = "Generator version: 7.19.0") +public class TlsConfig { + public static final String SERIALIZED_NAME_CUSTOM_CA = "customCa"; + + @SerializedName(SERIALIZED_NAME_CUSTOM_CA) + @javax.annotation.Nullable private String customCa; + + public static final String SERIALIZED_NAME_ENABLED = "enabled"; + + @SerializedName(SERIALIZED_NAME_ENABLED) + @javax.annotation.Nullable private Boolean enabled; + + public static final String SERIALIZED_NAME_SKIP_CERTIFICATE_VALIDATION = + "skipCertificateValidation"; + + @SerializedName(SERIALIZED_NAME_SKIP_CERTIFICATE_VALIDATION) + @javax.annotation.Nullable private Boolean skipCertificateValidation; + + public TlsConfig() {} + + public TlsConfig customCa(@javax.annotation.Nullable String customCa) { + this.customCa = customCa; + return this; + } + + /** + * Specifies a custom Certificate Authority (CA). When provided, the target pool will trust + * certificates signed by this CA, in addition to any system-trusted CAs. This is useful for + * scenarios where the target pool needs to communicate with servers using self-signed or + * internally-issued certificates. Enabled needs to be set to true and skip validation to false + * for this option. + * + * @return customCa + */ + @javax.annotation.Nullable public String getCustomCa() { + return customCa; + } + + public void setCustomCa(@javax.annotation.Nullable String customCa) { + this.customCa = customCa; + } + + public TlsConfig enabled(@javax.annotation.Nullable Boolean enabled) { + this.enabled = enabled; + return this; + } + + /** + * Enable TLS (Transport Layer Security) bridging for the connection between Application Load + * Balancer and targets in this pool. When enabled, public CAs are trusted. Can be used in + * tandem with the options either custom CA or skip validation or alone. + * + * @return enabled + */ + @javax.annotation.Nullable public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(@javax.annotation.Nullable Boolean enabled) { + this.enabled = enabled; + } + + public TlsConfig skipCertificateValidation( + @javax.annotation.Nullable Boolean skipCertificateValidation) { + this.skipCertificateValidation = skipCertificateValidation; + return this; + } + + /** + * Bypass certificate validation for TLS bridging in this target pool. This option is insecure + * and can only be used with public CAs by setting enabled true. Meant to be used for testing + * purposes only! + * + * @return skipCertificateValidation + */ + @javax.annotation.Nullable public Boolean getSkipCertificateValidation() { + return skipCertificateValidation; + } + + public void setSkipCertificateValidation( + @javax.annotation.Nullable Boolean skipCertificateValidation) { + this.skipCertificateValidation = skipCertificateValidation; + } + + /** + * 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 TlsConfig instance itself + */ + public TlsConfig putAdditionalProperty(String key, Object value) { + if (this.additionalProperties == null) { + this.additionalProperties = new HashMap(); + } + this.additionalProperties.put(key, value); + return this; + } + + /** + * Return the additional (undeclared) property. + * + * @return a map of objects + */ + public Map getAdditionalProperties() { + return additionalProperties; + } + + /** + * Return the additional (undeclared) property with the specified name. + * + * @param key name of the property + * @return an object + */ + public Object getAdditionalProperty(String key) { + if (this.additionalProperties == null) { + return null; + } + return this.additionalProperties.get(key); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TlsConfig tlsConfig = (TlsConfig) o; + return Objects.equals(this.customCa, tlsConfig.customCa) + && Objects.equals(this.enabled, tlsConfig.enabled) + && Objects.equals( + this.skipCertificateValidation, tlsConfig.skipCertificateValidation) + && Objects.equals(this.additionalProperties, tlsConfig.additionalProperties); + } + + @Override + public int hashCode() { + return Objects.hash(customCa, enabled, skipCertificateValidation, additionalProperties); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TlsConfig {\n"); + sb.append(" customCa: ").append(toIndentedString(customCa)).append("\n"); + sb.append(" enabled: ").append(toIndentedString(enabled)).append("\n"); + sb.append(" skipCertificateValidation: ") + .append(toIndentedString(skipCertificateValidation)) + .append("\n"); + sb.append(" additionalProperties: ") + .append(toIndentedString(additionalProperties)) + .append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first + * line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static HashSet openapiFields; + public static HashSet openapiRequiredFields; + + static { + // a set of all properties/fields (JSON key names) + openapiFields = + new HashSet( + Arrays.asList("customCa", "enabled", "skipCertificateValidation")); + + // a set of required properties/fields (JSON key names) + openapiRequiredFields = new HashSet(0); + } + + /** + * Validates the JSON Element and throws an exception if issues found + * + * @param jsonElement JSON Element + * @throws IOException if the JSON Element is invalid with respect to TlsConfig + */ + public static void validateJsonElement(JsonElement jsonElement) throws IOException { + if (jsonElement == null) { + if (!TlsConfig.openapiRequiredFields + .isEmpty()) { // has required fields but JSON element is null + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "The required field(s) %s in TlsConfig is not found in the empty JSON string", + TlsConfig.openapiRequiredFields.toString())); + } + } + JsonObject jsonObj = jsonElement.getAsJsonObject(); + if ((jsonObj.get("customCa") != null && !jsonObj.get("customCa").isJsonNull()) + && !jsonObj.get("customCa").isJsonPrimitive()) { + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "Expected the field `customCa` to be a primitive type in the JSON string but got `%s`", + jsonObj.get("customCa").toString())); + } + } + + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!TlsConfig.class.isAssignableFrom(type.getRawType())) { + return null; // this class only serializes 'TlsConfig' and its subtypes + } + final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); + final TypeAdapter thisAdapter = + gson.getDelegateAdapter(this, TypeToken.get(TlsConfig.class)); + + return (TypeAdapter) + new TypeAdapter() { + @Override + public void write(JsonWriter out, TlsConfig value) throws IOException { + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); + obj.remove("additionalProperties"); + // serialize additional properties + if (value.getAdditionalProperties() != null) { + for (Map.Entry entry : + value.getAdditionalProperties().entrySet()) { + if (entry.getValue() instanceof String) + obj.addProperty(entry.getKey(), (String) entry.getValue()); + else if (entry.getValue() instanceof Number) + obj.addProperty(entry.getKey(), (Number) entry.getValue()); + else if (entry.getValue() instanceof Boolean) + obj.addProperty(entry.getKey(), (Boolean) entry.getValue()); + else if (entry.getValue() instanceof Character) + obj.addProperty( + entry.getKey(), (Character) entry.getValue()); + else { + JsonElement jsonElement = gson.toJsonTree(entry.getValue()); + if (jsonElement.isJsonArray()) { + obj.add(entry.getKey(), jsonElement.getAsJsonArray()); + } else { + obj.add(entry.getKey(), jsonElement.getAsJsonObject()); + } + } + } + } + elementAdapter.write(out, obj); + } + + @Override + public TlsConfig read(JsonReader in) throws IOException { + JsonElement jsonElement = elementAdapter.read(in); + validateJsonElement(jsonElement); + JsonObject jsonObj = jsonElement.getAsJsonObject(); + // store additional fields in the deserialized instance + TlsConfig instance = thisAdapter.fromJsonTree(jsonObj); + for (Map.Entry entry : jsonObj.entrySet()) { + if (!openapiFields.contains(entry.getKey())) { + if (entry.getValue().isJsonPrimitive()) { // primitive type + if (entry.getValue().getAsJsonPrimitive().isString()) + instance.putAdditionalProperty( + entry.getKey(), entry.getValue().getAsString()); + else if (entry.getValue().getAsJsonPrimitive().isNumber()) + instance.putAdditionalProperty( + entry.getKey(), entry.getValue().getAsNumber()); + else if (entry.getValue().getAsJsonPrimitive().isBoolean()) + instance.putAdditionalProperty( + entry.getKey(), + entry.getValue().getAsBoolean()); + else + throw new IllegalArgumentException( + String.format( + java.util.Locale.ROOT, + "The field `%s` has unknown primitive type. Value: %s", + entry.getKey(), + entry.getValue().toString())); + } else if (entry.getValue().isJsonArray()) { + instance.putAdditionalProperty( + entry.getKey(), + gson.fromJson(entry.getValue(), List.class)); + } else { // JSON object + instance.putAdditionalProperty( + entry.getKey(), + gson.fromJson(entry.getValue(), HashMap.class)); + } + } + } + return instance; + } + }.nullSafe(); + } + } + + /** + * Create an instance of TlsConfig given an JSON string + * + * @param jsonString JSON string + * @return An instance of TlsConfig + * @throws IOException if the JSON string is invalid with respect to TlsConfig + */ + public static TlsConfig fromJson(String jsonString) throws IOException { + return JSON.getGson().fromJson(jsonString, TlsConfig.class); + } + + /** + * Convert an instance of TlsConfig to an JSON string + * + * @return JSON string + */ + public String toJson() { + return JSON.getGson().toJson(this); + } +}