Skip to content
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
12 changes: 8 additions & 4 deletions docs/OpenFgaApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ No authorization required

## listStores

> CompletableFuture<ListStoresResponse> listStores(pageSize, continuationToken)
> CompletableFuture<ListStoresResponse> listStores(pageSize, continuationToken, name)

List all stores

Expand All @@ -1181,8 +1181,9 @@ public class Example {
OpenFgaApi apiInstance = new OpenFgaApi(defaultClient);
Integer pageSize = 56; // Integer |
String continuationToken = "continuationToken_example"; // String |
String name = "name_example"; // String | The name parameter instructs the API to only include results that match that name.Multiple results may be returned. Only exact matches will be returned; substring matches and regexes will not be evaluated
try {
CompletableFuture<ListStoresResponse> result = apiInstance.listStores(pageSize, continuationToken);
CompletableFuture<ListStoresResponse> result = apiInstance.listStores(pageSize, continuationToken, name);
System.out.println(result.get());
} catch (ApiException e) {
System.err.println("Exception when calling OpenFgaApi#listStores");
Expand All @@ -1202,6 +1203,7 @@ public class Example {
|------------- | ------------- | ------------- | -------------|
| **pageSize** | **Integer**| | [optional] |
| **continuationToken** | **String**| | [optional] |
| **name** | **String**| The name parameter instructs the API to only include results that match that name.Multiple results may be returned. Only exact matches will be returned; substring matches and regexes will not be evaluated | [optional] |

### Return type

Expand Down Expand Up @@ -1231,7 +1233,7 @@ No authorization required

## listStoresWithHttpInfo

> CompletableFuture<ApiResponse<ListStoresResponse>> listStores listStoresWithHttpInfo(pageSize, continuationToken)
> CompletableFuture<ApiResponse<ListStoresResponse>> listStores listStoresWithHttpInfo(pageSize, continuationToken, name)

List all stores

Expand All @@ -1257,8 +1259,9 @@ public class Example {
OpenFgaApi apiInstance = new OpenFgaApi(defaultClient);
Integer pageSize = 56; // Integer |
String continuationToken = "continuationToken_example"; // String |
String name = "name_example"; // String | The name parameter instructs the API to only include results that match that name.Multiple results may be returned. Only exact matches will be returned; substring matches and regexes will not be evaluated
try {
CompletableFuture<ApiResponse<ListStoresResponse>> response = apiInstance.listStoresWithHttpInfo(pageSize, continuationToken);
CompletableFuture<ApiResponse<ListStoresResponse>> response = apiInstance.listStoresWithHttpInfo(pageSize, continuationToken, name);
System.out.println("Status code: " + response.get().getStatusCode());
System.out.println("Response headers: " + response.get().getHeaders());
System.out.println("Response body: " + response.get().getData());
Expand Down Expand Up @@ -1287,6 +1290,7 @@ public class Example {
|------------- | ------------- | ------------- | -------------|
| **pageSize** | **Integer**| | [optional] |
| **continuationToken** | **String**| | [optional] |
| **name** | **String**| The name parameter instructs the API to only include results that match that name.Multiple results may be returned. Only exact matches will be returned; substring matches and regexes will not be evaluated | [optional] |

### Return type

Expand Down
16 changes: 9 additions & 7 deletions src/main/java/dev/openfga/sdk/api/OpenFgaApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,35 +475,37 @@ private CompletableFuture<ApiResponse<ListObjectsResponse>> listObjects(
* Returns a paginated list of OpenFGA stores and a continuation token to get additional stores. The continuation token will be empty if there are no more stores.
* @param pageSize (optional)
* @param continuationToken (optional)
* @param name The name parameter instructs the API to only include results that match that name.Multiple results may be returned. Only exact matches will be returned; substring matches and regexes will not be evaluated (optional)
* @return CompletableFuture&lt;ApiResponse&lt;ListStoresResponse&gt;&gt;
* @throws ApiException if fails to make API call
*/
public CompletableFuture<ApiResponse<ListStoresResponse>> listStores(Integer pageSize, String continuationToken)
throws ApiException, FgaInvalidParameterException {
return listStores(pageSize, continuationToken, this.configuration);
public CompletableFuture<ApiResponse<ListStoresResponse>> listStores(
Integer pageSize, String continuationToken, String name) throws ApiException, FgaInvalidParameterException {
return listStores(pageSize, continuationToken, name, this.configuration);
}

/**
* List all stores
* Returns a paginated list of OpenFGA stores and a continuation token to get additional stores. The continuation token will be empty if there are no more stores.
* @param pageSize (optional)
* @param continuationToken (optional)
* @param name The name parameter instructs the API to only include results that match that name.Multiple results may be returned. Only exact matches will be returned; substring matches and regexes will not be evaluated (optional)
* @param configurationOverride Override the {@link Configuration} this OpenFgaApi was constructed with
* @return CompletableFuture&lt;ApiResponse&lt;ListStoresResponse&gt;&gt;
* @throws ApiException if fails to make API call
*/
public CompletableFuture<ApiResponse<ListStoresResponse>> listStores(
Integer pageSize, String continuationToken, ConfigurationOverride configurationOverride)
Integer pageSize, String continuationToken, String name, ConfigurationOverride configurationOverride)
throws ApiException, FgaInvalidParameterException {
return listStores(pageSize, continuationToken, this.configuration.override(configurationOverride));
return listStores(pageSize, continuationToken, name, this.configuration.override(configurationOverride));
}

private CompletableFuture<ApiResponse<ListStoresResponse>> listStores(
Integer pageSize, String continuationToken, Configuration configuration)
Integer pageSize, String continuationToken, String name, Configuration configuration)
throws ApiException, FgaInvalidParameterException {

String path = "/stores";
path = pathWithParams(path, "page_size", pageSize, "continuation_token", continuationToken);
path = pathWithParams(path, "page_size", pageSize, "continuation_token", continuationToken, "name", name);

Map<String, Object> methodParameters = new HashMap<>();

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void setConfiguration(ClientConfiguration configuration) throws FgaInvali
*/
public CompletableFuture<ClientListStoresResponse> listStores() throws FgaInvalidParameterException {
configuration.assertValid();
return call(() -> api.listStores(null, null)).thenApply(ClientListStoresResponse::new);
return call(() -> api.listStores(null, null, null)).thenApply(ClientListStoresResponse::new);
}

/**
Expand All @@ -94,7 +94,8 @@ public CompletableFuture<ClientListStoresResponse> listStores(ClientListStoresOp
throws FgaInvalidParameterException {
configuration.assertValid();
var overrides = new ConfigurationOverride().addHeaders(options);
return call(() -> api.listStores(options.getPageSize(), options.getContinuationToken(), overrides))
return call(() -> api.listStores(
options.getPageSize(), options.getContinuationToken(), options.getName(), overrides))
.thenApply(ClientListStoresResponse::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ClientListStoresOptions implements AdditionalHeadersSupplier {
private Map<String, String> additionalHeaders;
private Integer pageSize;
private String continuationToken;
private String name;

public ClientListStoresOptions additionalHeaders(Map<String, String> additionalHeaders) {
this.additionalHeaders = additionalHeaders;
Expand Down Expand Up @@ -46,4 +47,13 @@ public ClientListStoresOptions continuationToken(String continuationToken) {
public String getContinuationToken() {
return continuationToken;
}

public ClientListStoresOptions name(String name) {
this.name = name;
return this;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void deleteStore() throws Exception {
api.deleteStore(storeId).get();

// Then
ListStoresResponse response = api.listStores(100, null).get().getData();
ListStoresResponse response = api.listStores(100, null, null).get().getData();
boolean itWasDeleted = response.getStores().stream().map(Store::getId).noneMatch(storeId::equals);
assertTrue(itWasDeleted, String.format("No stores should remain with the id %s.", storeId));
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public void listStores() throws Exception {
}

// When
ListStoresResponse response = api.listStores(100, null).get().getData();
ListStoresResponse response = api.listStores(100, null, null).get().getData();

// Then
for (String store : stores) {
Expand All @@ -124,6 +124,30 @@ public void listStores() throws Exception {
}
}

@Test
public void listStoresWithNameFilter() throws Exception {
// Given
String testName = thisTestName();
String targetStore = testName + "-target-store";
String otherStore1 = testName + "-other-store-1";
String otherStore2 = testName + "-other-store-2";

// Create multiple stores
createStore(targetStore);
createStore(otherStore1);
createStore(otherStore2);

// When - Filter by name
ListStoresResponse response =
api.listStores(100, null, targetStore).get().getData();

// Then - Should only return the target store
List<String> storeNames =
response.getStores().stream().map(Store::getName).collect(java.util.stream.Collectors.toList());
assertTrue(storeNames.contains(targetStore), "Target store should be in the filtered response");
assertEquals(1, storeNames.size(), "Should return only one store when filtering by exact name");
}

@Test
public void readAuthModel() throws Exception {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,32 @@ public void listStores() throws Exception {
}
}

@Test
public void listStoresWithNameFilter() throws Exception {
// Given
String testName = thisTestName();
String targetStore = testName + "-target";
String otherStore1 = testName + "-other-1";
String otherStore2 = testName + "-other-2";

// Create multiple stores
createStore(targetStore);
createStore(otherStore1);
createStore(otherStore2);

ClientListStoresOptions options = new ClientListStoresOptions().name(targetStore);

// When - Filter by name using client options
ClientListStoresResponse response = fga.listStores(options).get();

// Then - Should only return the target store
assertNotNull(response.getStores());
List<String> storeNames =
response.getStores().stream().map(Store::getName).collect(java.util.stream.Collectors.toList());
assertTrue(storeNames.contains(targetStore), "Target store should be in the filtered response");
assertEquals(1, storeNames.size(), "Should return only one store when filtering by exact name");
}

@Test
public void readAuthModel() throws Exception {
// Given
Expand Down
90 changes: 86 additions & 4 deletions src/test/java/dev/openfga/sdk/api/OpenFgaApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -31,6 +32,7 @@
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;

/**
* API tests for OpenFgaApi.
Expand Down Expand Up @@ -74,6 +76,9 @@ public void beforeEachTest() throws Exception {
when(mockConfiguration.getMaxRetries()).thenReturn(DEFAULT_MAX_RETRIES);
when(mockConfiguration.getMinimumRetryDelay()).thenReturn(DEFAULT_RETRY_DELAY);
when(mockConfiguration.getTelemetryConfiguration()).thenReturn(DEFAULT_TELEMETRY_CONFIG);
when(mockConfiguration.override(ArgumentMatchers.any(ConfigurationOverride.class)))
.thenReturn(mockConfiguration);
doNothing().when(mockConfiguration).assertValid();

mockApiClient = mock(ApiClient.class);
when(mockApiClient.getObjectMapper()).thenReturn(mapper);
Expand All @@ -96,7 +101,84 @@ public void listStoresTest() throws Exception {
String continuationToken = null; // Input is optional

// When
var response = fga.listStores(pageSize, continuationToken).get();
var response = fga.listStores(pageSize, continuationToken, null).get();

// Then
mockHttpClient.verify().get("https://api.fga.example/stores").called(1);
assertNotNull(response.getData());
assertNotNull(response.getData().getStores());
var stores = response.getData().getStores();
assertEquals(1, stores.size());
assertEquals(DEFAULT_STORE_ID, stores.get(0).getId());
assertEquals(DEFAULT_STORE_NAME, stores.get(0).getName());
}

@Test
public void listStoresTest_withNameFilter() throws Exception {
// Given
String storeName = "test-store-name";
String responseBody =
String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, storeName);
mockHttpClient.onGet("https://api.fga.example/stores?name=" + storeName).doReturn(200, responseBody);
Integer pageSize = null; // Input is optional
String continuationToken = null; // Input is optional

// When
var response = fga.listStores(pageSize, continuationToken, storeName).get();

// Then
mockHttpClient
.verify()
.get("https://api.fga.example/stores?name=" + storeName)
.called(1);
assertNotNull(response.getData());
assertNotNull(response.getData().getStores());
var stores = response.getData().getStores();
assertEquals(1, stores.size());
assertEquals(DEFAULT_STORE_ID, stores.get(0).getId());
assertEquals(storeName, stores.get(0).getName());
}

@Test
public void listStoresTest_withNameOnly() throws Exception {
// Given
String responseBody =
String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME);
String storeName = "test-store";
String getUrl = String.format("https://api.fga.example/stores?name=%s", storeName);
mockHttpClient.onGet(getUrl).doReturn(200, responseBody);
Integer pageSize = null; // Input is optional
String continuationToken = null; // Input is optional

// When - This covers the specific line: return listStores(pageSize, continuationToken, name,
// this.configuration);
var response = fga.listStores(pageSize, continuationToken, storeName).get();

// Then
mockHttpClient.verify().get(getUrl).called(1);
assertNotNull(response.getData());
assertNotNull(response.getData().getStores());
var stores = response.getData().getStores();
assertEquals(1, stores.size());
assertEquals(DEFAULT_STORE_ID, stores.get(0).getId());
assertEquals(DEFAULT_STORE_NAME, stores.get(0).getName());
}

@Test
public void listStoresTest_withConfigurationOverride() throws Exception {
// Given
String responseBody =
String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME);
mockHttpClient.onGet("https://api.fga.example/stores").doReturn(200, responseBody);
Integer pageSize = null; // Input is optional
String continuationToken = null; // Input is optional
String name = null;
ConfigurationOverride configOverride = new ConfigurationOverride();

// When - This covers the specific line: return listStores(pageSize, continuationToken, null,
// this.configuration.override(configurationOverride));
var response = fga.listStores(pageSize, continuationToken, name, configOverride)
.get();

// Then
mockHttpClient.verify().get("https://api.fga.example/stores").called(1);
Expand All @@ -119,7 +201,7 @@ public void listStores_400() {

// When
ExecutionException execException =
assertThrows(ExecutionException.class, () -> fga.listStores(pageSize, continuationToken)
assertThrows(ExecutionException.class, () -> fga.listStores(pageSize, continuationToken, null)
.get());

// Then
Expand All @@ -142,7 +224,7 @@ public void listStores_404() throws Exception {

// When
ExecutionException execException =
assertThrows(ExecutionException.class, () -> fga.listStores(pageSize, continuationToken)
assertThrows(ExecutionException.class, () -> fga.listStores(pageSize, continuationToken, null)
.get());

// Then
Expand All @@ -164,7 +246,7 @@ public void listStores_500() throws Exception {

// When
ExecutionException execException =
assertThrows(ExecutionException.class, () -> fga.listStores(pageSize, continuationToken)
assertThrows(ExecutionException.class, () -> fga.listStores(pageSize, continuationToken, null)
.get());

// Then
Expand Down
Loading
Loading