Skip to content

chore: cleanup tests, remove unused method, move urlEncode method #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025
Merged
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
2 changes: 2 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,6 @@ src/test/java/dev/openfga/sdk/telemetry/HistogramsTest.java
src/test/java/dev/openfga/sdk/telemetry/MetricTest.java
src/test/java/dev/openfga/sdk/telemetry/MetricsTest.java
src/test/java/dev/openfga/sdk/telemetry/TelemetryTest.java
src/test/java/dev/openfga/sdk/util/PairTest.java
src/test/java/dev/openfga/sdk/util/StringUtilTest.java
src/test/java/dev/openfga/sdk/util/ValidationTest.java
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jacocoTestReport {

ext {
jackson_version = "2.19.0"
junit_version = "5.12.2"
}

dependencies {
Expand All @@ -74,13 +73,13 @@ testing {
suites {
test {
useJUnitJupiter()

dependencies {
implementation project()
implementation "org.junit.jupiter:junit-jupiter:$junit_version"
implementation "org.mockito:mockito-core:5.17.0"
runtimeOnly "org.junit.platform:junit-platform-launcher"
implementation "org.wiremock:wiremock:3.13.0"
implementation 'org.assertj:assertj-core:3.27.3'
implementation 'org.mockito:mockito-core:5.17.0'
implementation 'org.junit.jupiter:junit-jupiter:5.12.2'
implementation 'org.wiremock:wiremock:3.13.0'

runtimeOnly 'org.junit.platform:junit-platform-launcher'

// This test-only dependency is convenient but not widely used.
// Review project activity before updating the version here.
Expand All @@ -99,6 +98,7 @@ testing {
}
}
}

integration(JvmTestSuite) {
testType = TestSuiteType.INTEGRATION_TEST
useJUnitJupiter()
Expand Down
37 changes: 19 additions & 18 deletions src/main/java/dev/openfga/sdk/api/OpenFgaApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import dev.openfga.sdk.telemetry.Attributes;
import dev.openfga.sdk.telemetry.Telemetry;
import dev.openfga.sdk.util.Pair;
import dev.openfga.sdk.util.StringUtil;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpRequest;
Expand Down Expand Up @@ -127,7 +128,7 @@ private CompletableFuture<ApiResponse<BatchCheckResponse>> batchCheck(

assertParamExists(body, "body", "batchCheck");

String path = "/stores/{store_id}/batch-check".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
String path = "/stores/{store_id}/batch-check".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -183,7 +184,7 @@ private CompletableFuture<ApiResponse<CheckResponse>> check(

assertParamExists(body, "body", "check");

String path = "/stores/{store_id}/check".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
String path = "/stores/{store_id}/check".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -283,7 +284,7 @@ private CompletableFuture<ApiResponse<Void>> deleteStore(String storeId, Configu

assertParamExists(storeId, "storeId", "deleteStore");

String path = "/stores/{store_id}".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
String path = "/stores/{store_id}".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -338,7 +339,7 @@ private CompletableFuture<ApiResponse<ExpandResponse>> expand(

assertParamExists(body, "body", "expand");

String path = "/stores/{store_id}/expand".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
String path = "/stores/{store_id}/expand".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -389,7 +390,7 @@ private CompletableFuture<ApiResponse<GetStoreResponse>> getStore(String storeId

assertParamExists(storeId, "storeId", "getStore");

String path = "/stores/{store_id}".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
String path = "/stores/{store_id}".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -444,7 +445,7 @@ private CompletableFuture<ApiResponse<ListObjectsResponse>> listObjects(

assertParamExists(body, "body", "listObjects");

String path = "/stores/{store_id}/list-objects".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
String path = "/stores/{store_id}/list-objects".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -551,7 +552,7 @@ private CompletableFuture<ApiResponse<ListUsersResponse>> listUsers(

assertParamExists(body, "body", "listUsers");

String path = "/stores/{store_id}/list-users".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
String path = "/stores/{store_id}/list-users".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -607,7 +608,7 @@ private CompletableFuture<ApiResponse<ReadResponse>> read(

assertParamExists(body, "body", "read");

String path = "/stores/{store_id}/read".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
String path = "/stores/{store_id}/read".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -664,8 +665,8 @@ private CompletableFuture<ApiResponse<ReadAssertionsResponse>> readAssertions(
assertParamExists(authorizationModelId, "authorizationModelId", "readAssertions");

String path = "/stores/{store_id}/assertions/{authorization_model_id}"
.replace("{store_id}", ApiClient.urlEncode(storeId.toString()))
.replace("{authorization_model_id}", ApiClient.urlEncode(authorizationModelId.toString()));
.replace("{store_id}", StringUtil.urlEncode(storeId.toString()))
.replace("{authorization_model_id}", StringUtil.urlEncode(authorizationModelId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -722,8 +723,8 @@ private CompletableFuture<ApiResponse<ReadAuthorizationModelResponse>> readAutho
assertParamExists(id, "id", "readAuthorizationModel");

String path = "/stores/{store_id}/authorization-models/{id}"
.replace("{store_id}", ApiClient.urlEncode(storeId.toString()))
.replace("{id}", ApiClient.urlEncode(id.toString()));
.replace("{store_id}", StringUtil.urlEncode(storeId.toString()))
.replace("{id}", StringUtil.urlEncode(id.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -787,7 +788,7 @@ private CompletableFuture<ApiResponse<ReadAuthorizationModelsResponse>> readAuth
assertParamExists(storeId, "storeId", "readAuthorizationModels");

String path = "/stores/{store_id}/authorization-models"
.replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
.replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
path = pathWithParams(path, "page_size", pageSize, "continuation_token", continuationToken);

Map<String, Object> methodParameters = new HashMap<>();
Expand Down Expand Up @@ -869,7 +870,7 @@ private CompletableFuture<ApiResponse<ReadChangesResponse>> readChanges(

assertParamExists(storeId, "storeId", "readChanges");

String path = "/stores/{store_id}/changes".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
String path = "/stores/{store_id}/changes".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
path = pathWithParams(
path,
"type",
Expand Down Expand Up @@ -933,7 +934,7 @@ private CompletableFuture<ApiResponse<Object>> write(String storeId, WriteReques

assertParamExists(body, "body", "write");

String path = "/stores/{store_id}/write".replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
String path = "/stores/{store_id}/write".replace("{store_id}", StringUtil.urlEncode(storeId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -998,8 +999,8 @@ private CompletableFuture<ApiResponse<Void>> writeAssertions(
assertParamExists(body, "body", "writeAssertions");

String path = "/stores/{store_id}/assertions/{authorization_model_id}"
.replace("{store_id}", ApiClient.urlEncode(storeId.toString()))
.replace("{authorization_model_id}", ApiClient.urlEncode(authorizationModelId.toString()));
.replace("{store_id}", StringUtil.urlEncode(storeId.toString()))
.replace("{authorization_model_id}", StringUtil.urlEncode(authorizationModelId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down Expand Up @@ -1057,7 +1058,7 @@ private CompletableFuture<ApiResponse<WriteAuthorizationModelResponse>> writeAut
assertParamExists(body, "body", "writeAuthorizationModel");

String path = "/stores/{store_id}/authorization-models"
.replace("{store_id}", ApiClient.urlEncode(storeId.toString()));
.replace("{store_id}", StringUtil.urlEncode(storeId.toString()));

Map<String, Object> methodParameters = new HashMap<>();
methodParameters.put("storeId", storeId);
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/dev/openfga/sdk/api/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import dev.openfga.sdk.api.configuration.Configuration;
import dev.openfga.sdk.errors.FgaInvalidParameterException;
import dev.openfga.sdk.util.StringUtil;
import java.io.InputStream;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.function.Consumer;
import org.openapitools.jackson.nullable.JsonNullableModule;

Expand Down Expand Up @@ -104,16 +103,6 @@ public ApiClient(HttpClient.Builder builder, ObjectMapper mapper) {
asyncResponseInterceptor = null;
}

private static String valueToString(Object value) {
if (value == null) {
return "";
}
if (value instanceof OffsetDateTime) {
return ((OffsetDateTime) value).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
return value.toString();
}

public static HttpRequest.Builder requestBuilder(String method, String path, Configuration configuration)
throws FgaInvalidParameterException {
return requestBuilder(method, path, HttpRequest.BodyPublishers.noBody(), configuration);
Expand Down Expand Up @@ -171,7 +160,9 @@ private static HttpRequest.Builder requestBuilder(
*
* @param s String to encode.
* @return URL-encoded representation of the input string.
* @deprecated in favor of {@link StringUtil#urlEncode(String)}
*/
@Deprecated(forRemoval = true, since = "0.8.2")
public static String urlEncode(String s) {
return URLEncoder.encode(s, UTF_8).replaceAll("\\+", "%20");
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/dev/openfga/sdk/telemetry/Attribute.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* OpenFGA
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
*
* The version of the OpenAPI document: 1.x
* Contact: community@openfga.dev
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package dev.openfga.sdk.telemetry;

/**
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/dev/openfga/sdk/telemetry/Attributes.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* OpenFGA
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
*
* The version of the OpenAPI document: 1.x
* Contact: community@openfga.dev
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package dev.openfga.sdk.telemetry;

import static dev.openfga.sdk.util.StringUtil.isNullOrWhitespace;
Expand All @@ -17,7 +29,6 @@
* This class represents a collection of attributes used for telemetry purposes.
*/
public class Attributes {

/**
* The client ID used in the request, if applicable.
*/
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/dev/openfga/sdk/telemetry/Counter.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* OpenFGA
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
*
* The version of the OpenAPI document: 1.x
* Contact: community@openfga.dev
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package dev.openfga.sdk.telemetry;

/**
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/dev/openfga/sdk/telemetry/Counters.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* OpenFGA
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
*
* The version of the OpenAPI document: 1.x
* Contact: community@openfga.dev
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package dev.openfga.sdk.telemetry;

/**
Expand All @@ -10,4 +22,6 @@ public class Counters {
public static final Counter CREDENTIALS_REQUEST = new Counter(
"fga-client.credentials.request",
"The total number of times new access tokens have been requested using ClientCredentials.");

private Counters() {} // Instantiation prevented.
}
12 changes: 12 additions & 0 deletions src/main/java/dev/openfga/sdk/telemetry/Histogram.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* OpenFGA
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
*
* The version of the OpenAPI document: 1.x
* Contact: community@openfga.dev
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package dev.openfga.sdk.telemetry;

/**
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/dev/openfga/sdk/telemetry/Histograms.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* OpenFGA
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
*
* The version of the OpenAPI document: 1.x
* Contact: community@openfga.dev
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package dev.openfga.sdk.telemetry;

/**
Expand All @@ -17,4 +29,6 @@ public class Histograms {
public static final Histogram QUERY_DURATION = new Histogram(
"fga-client.query.duration",
"The total time it took (in milliseconds) for the FGA server to process and evaluate the request.");

private Histograms() {} // Instantiation prevented.
}
16 changes: 14 additions & 2 deletions src/main/java/dev/openfga/sdk/telemetry/Metric.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
/*
* OpenFGA
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
*
* The version of the OpenAPI document: 1.x
* Contact: community@openfga.dev
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package dev.openfga.sdk.telemetry;

public class Metric {
protected final String name;
protected final String description;
private final String name;
private final String description;

/**
* Constructs a new metric with the specified name and description.
Expand Down
Loading