/* * Tribufu API * REST API to access Tribufu services. * * The version of the OpenAPI document: 1.1.0 * Contact: contact@tribufu.com * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ package com.tribufu.generated.models; import java.util.Objects; import com.google.gson.TypeAdapter; import com.google.gson.annotations.JsonAdapter; import com.google.gson.annotations.SerializedName; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import com.tribufu.generated.models.CodeChallengeMethod; import com.tribufu.generated.models.ResponseType; import java.io.IOException; import java.util.Arrays; import org.openapitools.jackson.nullable.JsonNullable; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import com.tribufu.generated.JSON; /** * AuthorizeRequest */ @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2025-05-26T22:04:46.763378600-03:00[America/Sao_Paulo]", comments = "Generator version: 7.12.0") public class AuthorizeRequest { public static final String SERIALIZED_NAME_RESPONSE_TYPE = "response_type"; @SerializedName(SERIALIZED_NAME_RESPONSE_TYPE) @javax.annotation.Nullable private ResponseType responseType; public static final String SERIALIZED_NAME_CLIENT_ID = "client_id"; @SerializedName(SERIALIZED_NAME_CLIENT_ID) @javax.annotation.Nullable private String clientId; public static final String SERIALIZED_NAME_CODE_CHALLENGE = "code_challenge"; @SerializedName(SERIALIZED_NAME_CODE_CHALLENGE) @javax.annotation.Nullable private String codeChallenge; public static final String SERIALIZED_NAME_CODE_CHALLENGE_METHOD = "code_challenge_method"; @SerializedName(SERIALIZED_NAME_CODE_CHALLENGE_METHOD) @javax.annotation.Nullable private CodeChallengeMethod codeChallengeMethod; public static final String SERIALIZED_NAME_REDIRECT_URI = "redirect_uri"; @SerializedName(SERIALIZED_NAME_REDIRECT_URI) @javax.annotation.Nullable private String redirectUri; public static final String SERIALIZED_NAME_SCOPE = "scope"; @SerializedName(SERIALIZED_NAME_SCOPE) @javax.annotation.Nullable private String scope; public static final String SERIALIZED_NAME_STATE = "state"; @SerializedName(SERIALIZED_NAME_STATE) @javax.annotation.Nullable private String state; public AuthorizeRequest() { } public AuthorizeRequest responseType(@javax.annotation.Nullable ResponseType responseType) { this.responseType = responseType; return this; } /** * Get responseType * @return responseType */ @javax.annotation.Nullable public ResponseType getResponseType() { return responseType; } public void setResponseType(@javax.annotation.Nullable ResponseType responseType) { this.responseType = responseType; } public AuthorizeRequest clientId(@javax.annotation.Nullable String clientId) { this.clientId = clientId; return this; } /** * Get clientId * @return clientId */ @javax.annotation.Nullable public String getClientId() { return clientId; } public void setClientId(@javax.annotation.Nullable String clientId) { this.clientId = clientId; } public AuthorizeRequest codeChallenge(@javax.annotation.Nullable String codeChallenge) { this.codeChallenge = codeChallenge; return this; } /** * Get codeChallenge * @return codeChallenge */ @javax.annotation.Nullable public String getCodeChallenge() { return codeChallenge; } public void setCodeChallenge(@javax.annotation.Nullable String codeChallenge) { this.codeChallenge = codeChallenge; } public AuthorizeRequest codeChallengeMethod(@javax.annotation.Nullable CodeChallengeMethod codeChallengeMethod) { this.codeChallengeMethod = codeChallengeMethod; return this; } /** * Get codeChallengeMethod * @return codeChallengeMethod */ @javax.annotation.Nullable public CodeChallengeMethod getCodeChallengeMethod() { return codeChallengeMethod; } public void setCodeChallengeMethod(@javax.annotation.Nullable CodeChallengeMethod codeChallengeMethod) { this.codeChallengeMethod = codeChallengeMethod; } public AuthorizeRequest redirectUri(@javax.annotation.Nullable String redirectUri) { this.redirectUri = redirectUri; return this; } /** * Get redirectUri * @return redirectUri */ @javax.annotation.Nullable public String getRedirectUri() { return redirectUri; } public void setRedirectUri(@javax.annotation.Nullable String redirectUri) { this.redirectUri = redirectUri; } public AuthorizeRequest scope(@javax.annotation.Nullable String scope) { this.scope = scope; return this; } /** * Get scope * @return scope */ @javax.annotation.Nullable public String getScope() { return scope; } public void setScope(@javax.annotation.Nullable String scope) { this.scope = scope; } public AuthorizeRequest state(@javax.annotation.Nullable String state) { this.state = state; return this; } /** * Get state * @return state */ @javax.annotation.Nullable public String getState() { return state; } public void setState(@javax.annotation.Nullable String state) { this.state = state; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } AuthorizeRequest authorizeRequest = (AuthorizeRequest) o; return Objects.equals(this.responseType, authorizeRequest.responseType) && Objects.equals(this.clientId, authorizeRequest.clientId) && Objects.equals(this.codeChallenge, authorizeRequest.codeChallenge) && Objects.equals(this.codeChallengeMethod, authorizeRequest.codeChallengeMethod) && Objects.equals(this.redirectUri, authorizeRequest.redirectUri) && Objects.equals(this.scope, authorizeRequest.scope) && Objects.equals(this.state, authorizeRequest.state); } private static boolean equalsNullable(JsonNullable a, JsonNullable b) { return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get())); } @Override public int hashCode() { return Objects.hash(responseType, clientId, codeChallenge, codeChallengeMethod, redirectUri, scope, state); } private static int hashCodeNullable(JsonNullable a) { if (a == null) { return 1; } return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AuthorizeRequest {\n"); sb.append(" responseType: ").append(toIndentedString(responseType)).append("\n"); sb.append(" clientId: ").append(toIndentedString(clientId)).append("\n"); sb.append(" codeChallenge: ").append(toIndentedString(codeChallenge)).append("\n"); sb.append(" codeChallengeMethod: ").append(toIndentedString(codeChallengeMethod)).append("\n"); sb.append(" redirectUri: ").append(toIndentedString(redirectUri)).append("\n"); sb.append(" scope: ").append(toIndentedString(scope)).append("\n"); sb.append(" state: ").append(toIndentedString(state)).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(); openapiFields.add("response_type"); openapiFields.add("client_id"); openapiFields.add("code_challenge"); openapiFields.add("code_challenge_method"); openapiFields.add("redirect_uri"); openapiFields.add("scope"); openapiFields.add("state"); // a set of required properties/fields (JSON key names) openapiRequiredFields = new HashSet(); } /** * 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 AuthorizeRequest */ public static void validateJsonElement(JsonElement jsonElement) throws IOException { if (jsonElement == null) { if (!AuthorizeRequest.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null throw new IllegalArgumentException(String.format("The required field(s) %s in AuthorizeRequest is not found in the empty JSON string", AuthorizeRequest.openapiRequiredFields.toString())); } } Set> entries = jsonElement.getAsJsonObject().entrySet(); // check to see if the JSON string contains additional fields for (Map.Entry entry : entries) { if (!AuthorizeRequest.openapiFields.contains(entry.getKey())) { throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `AuthorizeRequest` properties. JSON: %s", entry.getKey(), jsonElement.toString())); } } JsonObject jsonObj = jsonElement.getAsJsonObject(); // validate the optional field `response_type` if (jsonObj.get("response_type") != null && !jsonObj.get("response_type").isJsonNull()) { ResponseType.validateJsonElement(jsonObj.get("response_type")); } if ((jsonObj.get("client_id") != null && !jsonObj.get("client_id").isJsonNull()) && !jsonObj.get("client_id").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `client_id` to be a primitive type in the JSON string but got `%s`", jsonObj.get("client_id").toString())); } if ((jsonObj.get("code_challenge") != null && !jsonObj.get("code_challenge").isJsonNull()) && !jsonObj.get("code_challenge").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `code_challenge` to be a primitive type in the JSON string but got `%s`", jsonObj.get("code_challenge").toString())); } // validate the optional field `code_challenge_method` if (jsonObj.get("code_challenge_method") != null && !jsonObj.get("code_challenge_method").isJsonNull()) { CodeChallengeMethod.validateJsonElement(jsonObj.get("code_challenge_method")); } if ((jsonObj.get("redirect_uri") != null && !jsonObj.get("redirect_uri").isJsonNull()) && !jsonObj.get("redirect_uri").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `redirect_uri` to be a primitive type in the JSON string but got `%s`", jsonObj.get("redirect_uri").toString())); } if ((jsonObj.get("scope") != null && !jsonObj.get("scope").isJsonNull()) && !jsonObj.get("scope").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `scope` to be a primitive type in the JSON string but got `%s`", jsonObj.get("scope").toString())); } if ((jsonObj.get("state") != null && !jsonObj.get("state").isJsonNull()) && !jsonObj.get("state").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `state` to be a primitive type in the JSON string but got `%s`", jsonObj.get("state").toString())); } } public static class CustomTypeAdapterFactory implements TypeAdapterFactory { @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { if (!AuthorizeRequest.class.isAssignableFrom(type.getRawType())) { return null; // this class only serializes 'AuthorizeRequest' and its subtypes } final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); final TypeAdapter thisAdapter = gson.getDelegateAdapter(this, TypeToken.get(AuthorizeRequest.class)); return (TypeAdapter) new TypeAdapter() { @Override public void write(JsonWriter out, AuthorizeRequest value) throws IOException { JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); elementAdapter.write(out, obj); } @Override public AuthorizeRequest read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); return thisAdapter.fromJsonTree(jsonElement); } }.nullSafe(); } } /** * Create an instance of AuthorizeRequest given an JSON string * * @param jsonString JSON string * @return An instance of AuthorizeRequest * @throws IOException if the JSON string is invalid with respect to AuthorizeRequest */ public static AuthorizeRequest fromJson(String jsonString) throws IOException { return JSON.getGson().fromJson(jsonString, AuthorizeRequest.class); } /** * Convert an instance of AuthorizeRequest to an JSON string * * @return JSON string */ public String toJson() { return JSON.getGson().toJson(this); } }