/* * 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.GrantType; 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; /** * TokenRequest */ @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 TokenRequest { public static final String SERIALIZED_NAME_GRANT_TYPE = "grant_type"; @SerializedName(SERIALIZED_NAME_GRANT_TYPE) @javax.annotation.Nullable private GrantType grantType; public static final String SERIALIZED_NAME_CODE = "code"; @SerializedName(SERIALIZED_NAME_CODE) @javax.annotation.Nullable private String code; public static final String SERIALIZED_NAME_USERNAME = "username"; @SerializedName(SERIALIZED_NAME_USERNAME) @javax.annotation.Nullable private String username; public static final String SERIALIZED_NAME_PASSWORD = "password"; @SerializedName(SERIALIZED_NAME_PASSWORD) @javax.annotation.Nullable private String password; public static final String SERIALIZED_NAME_REFRESH_TOKEN = "refresh_token"; @SerializedName(SERIALIZED_NAME_REFRESH_TOKEN) @javax.annotation.Nullable private String refreshToken; 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_REDIRECT_URI = "redirect_uri"; @SerializedName(SERIALIZED_NAME_REDIRECT_URI) @javax.annotation.Nullable private String redirectUri; public static final String SERIALIZED_NAME_CODE_VERIFIER = "code_verifier"; @SerializedName(SERIALIZED_NAME_CODE_VERIFIER) @javax.annotation.Nullable private String codeVerifier; public TokenRequest() { } public TokenRequest grantType(@javax.annotation.Nullable GrantType grantType) { this.grantType = grantType; return this; } /** * Get grantType * @return grantType */ @javax.annotation.Nullable public GrantType getGrantType() { return grantType; } public void setGrantType(@javax.annotation.Nullable GrantType grantType) { this.grantType = grantType; } public TokenRequest code(@javax.annotation.Nullable String code) { this.code = code; return this; } /** * Get code * @return code */ @javax.annotation.Nullable public String getCode() { return code; } public void setCode(@javax.annotation.Nullable String code) { this.code = code; } public TokenRequest username(@javax.annotation.Nullable String username) { this.username = username; return this; } /** * Get username * @return username */ @javax.annotation.Nullable public String getUsername() { return username; } public void setUsername(@javax.annotation.Nullable String username) { this.username = username; } public TokenRequest password(@javax.annotation.Nullable String password) { this.password = password; return this; } /** * Get password * @return password */ @javax.annotation.Nullable public String getPassword() { return password; } public void setPassword(@javax.annotation.Nullable String password) { this.password = password; } public TokenRequest refreshToken(@javax.annotation.Nullable String refreshToken) { this.refreshToken = refreshToken; return this; } /** * Get refreshToken * @return refreshToken */ @javax.annotation.Nullable public String getRefreshToken() { return refreshToken; } public void setRefreshToken(@javax.annotation.Nullable String refreshToken) { this.refreshToken = refreshToken; } public TokenRequest 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 TokenRequest 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 TokenRequest codeVerifier(@javax.annotation.Nullable String codeVerifier) { this.codeVerifier = codeVerifier; return this; } /** * Get codeVerifier * @return codeVerifier */ @javax.annotation.Nullable public String getCodeVerifier() { return codeVerifier; } public void setCodeVerifier(@javax.annotation.Nullable String codeVerifier) { this.codeVerifier = codeVerifier; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } TokenRequest tokenRequest = (TokenRequest) o; return Objects.equals(this.grantType, tokenRequest.grantType) && Objects.equals(this.code, tokenRequest.code) && Objects.equals(this.username, tokenRequest.username) && Objects.equals(this.password, tokenRequest.password) && Objects.equals(this.refreshToken, tokenRequest.refreshToken) && Objects.equals(this.clientId, tokenRequest.clientId) && Objects.equals(this.redirectUri, tokenRequest.redirectUri) && Objects.equals(this.codeVerifier, tokenRequest.codeVerifier); } 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(grantType, code, username, password, refreshToken, clientId, redirectUri, codeVerifier); } 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 TokenRequest {\n"); sb.append(" grantType: ").append(toIndentedString(grantType)).append("\n"); sb.append(" code: ").append(toIndentedString(code)).append("\n"); sb.append(" username: ").append(toIndentedString(username)).append("\n"); sb.append(" password: ").append(toIndentedString(password)).append("\n"); sb.append(" refreshToken: ").append(toIndentedString(refreshToken)).append("\n"); sb.append(" clientId: ").append(toIndentedString(clientId)).append("\n"); sb.append(" redirectUri: ").append(toIndentedString(redirectUri)).append("\n"); sb.append(" codeVerifier: ").append(toIndentedString(codeVerifier)).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("grant_type"); openapiFields.add("code"); openapiFields.add("username"); openapiFields.add("password"); openapiFields.add("refresh_token"); openapiFields.add("client_id"); openapiFields.add("redirect_uri"); openapiFields.add("code_verifier"); // 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 TokenRequest */ public static void validateJsonElement(JsonElement jsonElement) throws IOException { if (jsonElement == null) { if (!TokenRequest.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null throw new IllegalArgumentException(String.format("The required field(s) %s in TokenRequest is not found in the empty JSON string", TokenRequest.openapiRequiredFields.toString())); } } Set> entries = jsonElement.getAsJsonObject().entrySet(); // check to see if the JSON string contains additional fields for (Map.Entry entry : entries) { if (!TokenRequest.openapiFields.contains(entry.getKey())) { throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `TokenRequest` properties. JSON: %s", entry.getKey(), jsonElement.toString())); } } JsonObject jsonObj = jsonElement.getAsJsonObject(); // validate the optional field `grant_type` if (jsonObj.get("grant_type") != null && !jsonObj.get("grant_type").isJsonNull()) { GrantType.validateJsonElement(jsonObj.get("grant_type")); } if ((jsonObj.get("code") != null && !jsonObj.get("code").isJsonNull()) && !jsonObj.get("code").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `code` to be a primitive type in the JSON string but got `%s`", jsonObj.get("code").toString())); } if ((jsonObj.get("username") != null && !jsonObj.get("username").isJsonNull()) && !jsonObj.get("username").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `username` to be a primitive type in the JSON string but got `%s`", jsonObj.get("username").toString())); } if ((jsonObj.get("password") != null && !jsonObj.get("password").isJsonNull()) && !jsonObj.get("password").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `password` to be a primitive type in the JSON string but got `%s`", jsonObj.get("password").toString())); } if ((jsonObj.get("refresh_token") != null && !jsonObj.get("refresh_token").isJsonNull()) && !jsonObj.get("refresh_token").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `refresh_token` to be a primitive type in the JSON string but got `%s`", jsonObj.get("refresh_token").toString())); } 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("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("code_verifier") != null && !jsonObj.get("code_verifier").isJsonNull()) && !jsonObj.get("code_verifier").isJsonPrimitive()) { throw new IllegalArgumentException(String.format("Expected the field `code_verifier` to be a primitive type in the JSON string but got `%s`", jsonObj.get("code_verifier").toString())); } } public static class CustomTypeAdapterFactory implements TypeAdapterFactory { @SuppressWarnings("unchecked") @Override public TypeAdapter create(Gson gson, TypeToken type) { if (!TokenRequest.class.isAssignableFrom(type.getRawType())) { return null; // this class only serializes 'TokenRequest' and its subtypes } final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class); final TypeAdapter thisAdapter = gson.getDelegateAdapter(this, TypeToken.get(TokenRequest.class)); return (TypeAdapter) new TypeAdapter() { @Override public void write(JsonWriter out, TokenRequest value) throws IOException { JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); elementAdapter.write(out, obj); } @Override public TokenRequest read(JsonReader in) throws IOException { JsonElement jsonElement = elementAdapter.read(in); validateJsonElement(jsonElement); return thisAdapter.fromJsonTree(jsonElement); } }.nullSafe(); } } /** * Create an instance of TokenRequest given an JSON string * * @param jsonString JSON string * @return An instance of TokenRequest * @throws IOException if the JSON string is invalid with respect to TokenRequest */ public static TokenRequest fromJson(String jsonString) throws IOException { return JSON.getGson().fromJson(jsonString, TokenRequest.class); } /** * Convert an instance of TokenRequest to an JSON string * * @return JSON string */ public String toJson() { return JSON.getGson().toJson(this); } }