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

fix/client empty read #31

Merged
merged 3 commits into from
Oct 31, 2023
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v0.2.2

### [0.2.2](https://github.com/openfga/java-sdk/compare/v0.2.1...v0.2.2) (2023-10-31)

- fix(client): an empty read request will no longer send an empty tuple
- fix(client): an unused "user" field, and related methods, was removed from ClientExpandRequest

## v0.2.1

### [0.2.1](https://github.com/openfga/java-sdk/compare/v0.2.0...v0.2.1) (2023-10-13)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ It can be used with the following:
* Gradle (Groovy)

```groovy
implementation 'dev.openfga:openfga-sdk:0.2.1'
implementation 'dev.openfga:openfga-sdk:0.2.2'
```

* Gradle (Kotlin)

```kotlin
implementation("dev.openfga:openfga-sdk:0.2.1")
implementation("dev.openfga:openfga-sdk:0.2.2")
```

* Apache Maven
Expand All @@ -89,26 +89,26 @@ implementation("dev.openfga:openfga-sdk:0.2.1")
<dependency>
<groupId>dev.openfga</groupId>
<artifactId>openfga-sdk</artifactId>
<version>0.2.1</version>
<version>0.2.2</version>
</dependency>
```

* Ivy

```xml
<dependency org="dev.openfga" name="openfga-sdk" rev="0.2.1"/>
<dependency org="dev.openfga" name="openfga-sdk" rev="0.2.2"/>
```

* SBT

```scala
libraryDependencies += "dev.openfga" % "openfga-sdk" % "0.2.1"
libraryDependencies += "dev.openfga" % "openfga-sdk" % "0.2.2"
```

* Leiningen

```edn
[dev.openfga/openfga-sdk "0.2.1"]
[dev.openfga/openfga-sdk "0.2.2"]
```


Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
apply from: 'publish.gradle'

group = 'dev.openfga'
version = '0.2.1'
version = '0.2.2'

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publishing {
pom {
group = 'dev.openfga'
name = 'openfga-sdk'
version = '0.2.1'
version = '0.2.2'
description = 'This is an autogenerated Java SDK for OpenFGA. It provides a wrapper around the [OpenFGA API definition](https://openfga.dev/api).'
url = 'https://openfga.dev'
licenses {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package dev.openfga.sdk.api.client;

public class ClientExpandRequest {
private String user;
private String relation;
private String _object;

Expand Down Expand Up @@ -42,17 +41,4 @@ public ClientExpandRequest relation(String relation) {
public String getRelation() {
return relation;
}

public ClientExpandRequest user(String user) {
this.user = user;
return this;
}

/**
* Get user
* @return user
**/
public String getUser() {
return user;
}
}
13 changes: 5 additions & 8 deletions src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,18 @@ public CompletableFuture<ClientReadResponse> read(ClientReadRequest request, Cli
String storeId = configuration.getStoreIdChecked();

ReadRequest body = new ReadRequest();
TupleKey tupleKey = new TupleKey();

if (request != null) {
if (request != null
&& (request.getUser() != null || request.getRelation() != null || request.getObject() != null)) {
TupleKey tupleKey = new TupleKey();
tupleKey.user(request.getUser()).relation(request.getRelation())._object(request.getObject());
body.tupleKey(tupleKey);
}

if (options != null) {
body.pageSize(options.getPageSize()).continuationToken(options.getContinuationToken());
}

body.tupleKey(tupleKey);

return call(() -> api.read(storeId, body)).thenApply(ClientReadResponse::new);
}

Expand Down Expand Up @@ -408,10 +408,7 @@ public CompletableFuture<ClientExpandResponse> expand(ClientExpandRequest reques
ExpandRequest body = new ExpandRequest();

if (request != null) {
body.tupleKey(new TupleKey()
.user(request.getUser())
.relation(request.getRelation())
._object(request.getObject()));
body.tupleKey(new TupleKey().relation(request.getRelation())._object(request.getObject()));
}

if (options != null && !isNullOrWhitespace(options.getAuthorizationModelId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
* Configurations for an api client.
*/
public class Configuration implements BaseConfiguration {
public static final String VERSION = "0.2.1";
public static final String VERSION = "0.2.2";

private static final String DEFAULT_API_URL = "http://localhost:8080";
private static final String DEFAULT_USER_AGENT = "openfga-sdk java/0.2.1";
private static final String DEFAULT_USER_AGENT = "openfga-sdk java/0.2.2";
private static final Duration DEFAULT_READ_TIMEOUT = Duration.ofSeconds(10);
private static final Duration DEFAULT_CONNECT_TIMEOUT = Duration.ofSeconds(10);

Expand Down
25 changes: 19 additions & 6 deletions src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,21 @@ public void readTest() throws Exception {
assertEquals(DEFAULT_OBJECT, key.getObject());
}

@Test
public void read_emptyRequestSendsNoTupleKey() throws Exception {
// Given
String postUrl = String.format("https://localhost/stores/%s/read", DEFAULT_STORE_ID);
String expectedBody = "{\"tuple_key\":null,\"page_size\":null,\"continuation_token\":null}";
mockHttpClient.onPost(postUrl).withBody(is(expectedBody)).doReturn(200, EMPTY_RESPONSE_BODY);
ClientReadRequest request = new ClientReadRequest();

// When
ClientReadResponse response = fga.read(request).get();

// Then
mockHttpClient.verify().post(postUrl).withBody(is(expectedBody)).called(1);
}

@Test
public void read_storeIdRequired() {
// Given
Expand Down Expand Up @@ -1303,16 +1318,14 @@ public void expandTest() throws Exception {
// Given
String postPath = "https://localhost/stores/01YCP46JKYM8FJCQ37NMBYHE5X/expand";
String expectedBody = String.format(
"{\"tuple_key\":{\"object\":\"%s\",\"relation\":\"%s\",\"user\":\"%s\"},\"authorization_model_id\":\"%s\"}",
DEFAULT_OBJECT, DEFAULT_RELATION, DEFAULT_USER, DEFAULT_AUTH_MODEL_ID);
"{\"tuple_key\":{\"object\":\"%s\",\"relation\":\"%s\",\"user\":null},\"authorization_model_id\":\"%s\"}",
DEFAULT_OBJECT, DEFAULT_RELATION, DEFAULT_AUTH_MODEL_ID);
String responseBody = String.format(
"{\"tree\":{\"root\":{\"union\":{\"nodes\":[{\"leaf\":{\"users\":{\"users\":[\"%s\"]}}}]}}}}",
DEFAULT_USER);
mockHttpClient.onPost(postPath).withBody(is(expectedBody)).doReturn(200, responseBody);
ClientExpandRequest request = new ClientExpandRequest()
.user(DEFAULT_USER)
.relation(DEFAULT_RELATION)
._object(DEFAULT_OBJECT);
ClientExpandRequest request =
new ClientExpandRequest().relation(DEFAULT_RELATION)._object(DEFAULT_OBJECT);
ClientExpandOptions options = new ClientExpandOptions().authorizationModelId(DEFAULT_AUTH_MODEL_ID);

// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class ConfigurationTest {
private static final String DEFAULT_API_URL = "http://localhost:8080";
private static final String DEFAULT_USER_AGENT = "openfga-sdk java/0.2.1";
private static final String DEFAULT_USER_AGENT = "openfga-sdk java/0.2.2";
private static final Duration DEFAULT_READ_TIMEOUT = Duration.ofSeconds(10);
private static final Duration DEFAULT_CONNECT_TIMEOUT = Duration.ofSeconds(10);

Expand Down