Skip to content
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

feat(java-sdk): model client responses #218

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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: 12 additions & 0 deletions config/clients/java/CHANGELOG.md.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## v0.2.0

### [0.2.0](https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/compare/v0.1.0...v0.2.0) (2023-10-11)

- feat(client): automatic retries for errors have been implemented. HTTP 429 and HTTP 5XX error responses
will automatically be retried. (With the exception of the HTTP 501 "Not Implemented" status code.)
- feat(client): new response error classes have been introduced to classify FGA error responses
- feat(client): response types have been enriched with HTTP status/header/body response data
- feat(client): response errors have been enriched with data from both the HTTP request and its repsonse
- [BREAKING] refactor(client): in the lower level OpenFgaApi class, api calls and api calls "...WithHttpInfo"
are collapsed into a single api call that always includes HTTP information.

## v0.1.0

### [0.1.0](https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/compare/v0.0.5...v0.1.0) (2023-09-27)
Expand Down
78 changes: 73 additions & 5 deletions config/clients/java/config.overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"gitRepoId": "java-sdk",
"artifactId": "openfga-sdk",
"groupId": "dev.openfga",
"packageVersion": "0.1.0",
"packageVersion": "0.2.0",
"apiPackage": "dev.openfga.sdk.api",
"authPackage": "dev.openfga.sdk.api.auth",
"clientPackage": "dev.openfga.sdk.api.client",
Expand Down Expand Up @@ -51,30 +51,90 @@
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientCheckRequest.java",
"templateType": "SupportingFiles"
},
"client-ClientCheckResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientCheckResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientCreateStoreResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientCreateStoreResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientDeleteStoreResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientDeleteStoreResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientExpandRequest.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientExpandRequest.java",
"templateType": "SupportingFiles"
},
"client-ClientExpandResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientExpandResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientGetStoreResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientGetStoreResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientListObjectsRequest.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientListObjectsRequest.java",
"templateType": "SupportingFiles"
},
"client-ClientListObjectsResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientListObjectsResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientListStoresResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientListStoresResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientListRelationsRequest.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientListRelationsRequest.java",
"templateType": "SupportingFiles"
},
"client-ClientReadAssertionsResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientReadAssertionsResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientReadAuthorizationModelResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientReadAuthorizationModelResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientReadAuthorizationModelsResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientReadAuthorizationModelsResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientReadChangesResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientReadChangesResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientReadRequest.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientReadRequest.java",
"templateType": "SupportingFiles"
},
"client-ClientReadResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientReadResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientTupleKey.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientTupleKey.java",
"templateType": "SupportingFiles"
},
"client-ClientWriteAssertionsResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientWriteAssertionsResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientWriteAuthorizationModelResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientWriteAuthorizationModelResponse.java",
"templateType": "SupportingFiles"
},
"client-ClientWriteRequest.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientWriteRequest.java",
"templateType": "SupportingFiles"
},
"client-ClientWriteResponse.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/ClientWriteResponse.java",
"templateType": "SupportingFiles"
},
"client-HttpRequestAttempt.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/api/client/HttpRequestAttempt.java",
"templateType": "SupportingFiles"
Expand Down Expand Up @@ -215,6 +275,18 @@
"destinationFilename": "src/main/java/dev/openfga/sdk/errors/FgaApiValidationError.java",
"templateType": "SupportingFiles"
},
"errors-FgaError.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/errors/FgaError.java",
"templateType": "SupportingFiles"
},
"errors-FgaInvalidParameterException.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/errors/FgaInvalidParameterException.java",
"templateType": "SupportingFiles"
},
"errors-HttpStatusCode.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/errors/HttpStatusCode.java",
"templateType": "SupportingFiles"
},
"Pair.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/util/Pair.java",
"templateType": "SupportingFiles"
Expand All @@ -231,10 +303,6 @@
"destinationFilename": "src/main/java/dev/openfga/sdk/errors/ApiException.java",
"templateType": "SupportingFiles"
},
"FgaInvalidParameterException.java.mustache" : {
"destinationFilename": "src/main/java/dev/openfga/sdk/errors/FgaInvalidParameterException.java",
"templateType": "SupportingFiles"
},
"OpenFgaApiTest.java.mustache" : {
"destinationFilename": "src/test/java/dev/openfga/sdk/api/OpenFgaApiTest.java",
"templateType": "SupportingFiles"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class OpenFgaApiIntegrationTest {
CreateStoreRequest createStoreRequest = new CreateStoreRequest().name(storeName);

// When
CreateStoreResponse response = api.createStore(createStoreRequest).get();
CreateStoreResponse response = api.createStore(createStoreRequest).get().getData();

// Then
assertEquals("OpenFgaApiIntegrationTest.createStore", response.getName());
Expand All @@ -56,7 +56,7 @@ public class OpenFgaApiIntegrationTest {
api.deleteStore(storeId).get();

// Then
ListStoresResponse response = api.listStores(100, null).get();
ListStoresResponse response = api.listStores(100, 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 All @@ -68,7 +68,7 @@ public class OpenFgaApiIntegrationTest {
String storeId = createStore(storeName);

// When
GetStoreResponse response = api.getStore(storeId).get();
GetStoreResponse response = api.getStore(storeId).get().getData();

// Then
assertEquals(storeName, response.getName());
Expand All @@ -87,7 +87,7 @@ public class OpenFgaApiIntegrationTest {
}

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

// Then
for (String store : stores) {
Expand All @@ -104,7 +104,8 @@ public class OpenFgaApiIntegrationTest {
String authModelId = writeAuthModel(storeId);

// When
ReadAuthorizationModelResponse response = api.readAuthorizationModel(storeId, authModelId).get();
ReadAuthorizationModelResponse response =
api.readAuthorizationModel(storeId, authModelId).get().getData();

// Then
AuthorizationModel authModel = response.getAuthorizationModel();
Expand All @@ -123,7 +124,8 @@ public class OpenFgaApiIntegrationTest {
String authModelId = writeAuthModel(storeId);

// When
ReadAuthorizationModelsResponse response = api.readAuthorizationModels(storeId, 100, null).get();
ReadAuthorizationModelsResponse response =
api.readAuthorizationModels(storeId, 100, null).get().getData();

// Then
response.getAuthorizationModels().stream()
Expand Down Expand Up @@ -151,7 +153,8 @@ public class OpenFgaApiIntegrationTest {
mapper.readValue(DEFAULT_AUTH_MODEL, WriteAuthorizationModelRequest.class);

// When
WriteAuthorizationModelResponse response = api.writeAuthorizationModel(storeId, request).get();
WriteAuthorizationModelResponse response =
api.writeAuthorizationModel(storeId, request).get().getData();

// Then
assertNotNull(response);
Expand All @@ -171,7 +174,7 @@ public class OpenFgaApiIntegrationTest {

// When
api.write(storeId, writeRequest).get();
ReadResponse response = api.read(storeId, readRequest).get();
ReadResponse response = api.read(storeId, readRequest).get().getData();

// Then
TupleKey key = response.getTuples().get(0).getKey();
Expand All @@ -192,7 +195,7 @@ public class OpenFgaApiIntegrationTest {

// When
api.write(storeId, writeRequest).get();
CheckResponse response = api.check(storeId, checkRequest).get();
CheckResponse response = api.check(storeId, checkRequest).get().getData();

// Then
assertTrue(response.getAllowed());
Expand All @@ -210,7 +213,7 @@ public class OpenFgaApiIntegrationTest {

// When
api.write(storeId, writeRequest).get();
ExpandResponse response = api.expand(storeId, expandRequest).get();
ExpandResponse response = api.expand(storeId, expandRequest).get().getData();

// Then
assertNotNull(response.getTree());
Expand All @@ -232,7 +235,8 @@ public class OpenFgaApiIntegrationTest {

// When
api.write(storeId, writeRequest).get();
ListObjectsResponse response = api.listObjects(storeId, listObjectsRequest).get();
ListObjectsResponse response =
api.listObjects(storeId, listObjectsRequest).get().getData();

// Then
assertEquals(1, response.getObjects().size());
Expand All @@ -249,7 +253,8 @@ public class OpenFgaApiIntegrationTest {

// When
api.write(storeId, writeRequest).get();
ReadChangesResponse response = api.readChanges(storeId, null, null, null).get();
ReadChangesResponse response =
api.readChanges(storeId, null, null, null).get().getData();

// Then
assertEquals(1, response.getChanges().size());
Expand All @@ -271,7 +276,8 @@ public class OpenFgaApiIntegrationTest {

// When
api.writeAssertions(storeId, authModelId, writeRequest).get();
ReadAssertionsResponse response = api.readAssertions(storeId, authModelId).get();
ReadAssertionsResponse response =
api.readAssertions(storeId, authModelId).get().getData();

// Then
String responseJson = mapper.writeValueAsString(response.getAssertions());
Expand All @@ -286,7 +292,8 @@ public class OpenFgaApiIntegrationTest {
* @return The created Store ID
*/
private String createStore(String storeName) throws Exception {
CreateStoreResponse response = api.createStore(new CreateStoreRequest().name(storeName)).get();
CreateStoreResponse response =
api.createStore(new CreateStoreRequest().name(storeName)).get().getData();
return response.getId();
}

Expand All @@ -298,7 +305,8 @@ public class OpenFgaApiIntegrationTest {
private String writeAuthModel(String storeId) throws Exception {
WriteAuthorizationModelRequest request =
mapper.readValue(DEFAULT_AUTH_MODEL, WriteAuthorizationModelRequest.class);
WriteAuthorizationModelResponse response = api.writeAuthorizationModel(storeId, request).get();
WriteAuthorizationModelResponse response =
api.writeAuthorizationModel(storeId, request).get().getData();
return response.getAuthorizationModelId();
}

Expand Down
Loading
Loading