Skip to content

Commit

Permalink
Merge pull request #36 from openfga/java/update-interface
Browse files Browse the repository at this point in the history
chore: bump for latest interface updates
  • Loading branch information
adriantam authored Dec 11, 2023
2 parents c20ef78 + c671ff8 commit 4d42405
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 66 deletions.
4 changes: 4 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ api/openapi.yaml
build.gradle
docs/Any.md
docs/Assertion.md
docs/AssertionTupleKey.md
docs/AuthorizationModel.md
docs/CheckRequest.md
docs/CheckRequestTupleKey.md
Expand Down Expand Up @@ -146,6 +147,7 @@ src/main/java/dev/openfga/sdk/api/configuration/CredentialsMethod.java
src/main/java/dev/openfga/sdk/api/model/AbstractOpenApiSchema.java
src/main/java/dev/openfga/sdk/api/model/Any.java
src/main/java/dev/openfga/sdk/api/model/Assertion.java
src/main/java/dev/openfga/sdk/api/model/AssertionTupleKey.java
src/main/java/dev/openfga/sdk/api/model/AuthorizationModel.java
src/main/java/dev/openfga/sdk/api/model/CheckRequest.java
src/main/java/dev/openfga/sdk/api/model/CheckRequestTupleKey.java
Expand Down Expand Up @@ -222,6 +224,7 @@ src/main/java/dev/openfga/sdk/util/StringUtil.java
src/test-integration/java/dev/openfga/sdk/api/OpenFgaApiIntegrationTest.java
src/test-integration/java/dev/openfga/sdk/api/client/OpenFgaClientIntegrationTest.java
src/test-integration/java/package-info.java
src/test-integration/resources/auth-model.json
src/test/java/dev/openfga/sdk/api/OpenFgaApiTest.java
src/test/java/dev/openfga/sdk/api/OpenFgaApiTest.java
src/test/java/dev/openfga/sdk/api/auth/OAuth2ClientTest.java
Expand All @@ -230,6 +233,7 @@ src/test/java/dev/openfga/sdk/api/configuration/ClientCredentialsTest.java
src/test/java/dev/openfga/sdk/api/configuration/ConfigurationTest.java
src/test/java/dev/openfga/sdk/api/model/AnyTest.java
src/test/java/dev/openfga/sdk/api/model/AssertionTest.java
src/test/java/dev/openfga/sdk/api/model/AssertionTupleKeyTest.java
src/test/java/dev/openfga/sdk/api/model/AuthorizationModelTest.java
src/test/java/dev/openfga/sdk/api/model/CheckRequestTest.java
src/test/java/dev/openfga/sdk/api/model/CheckRequestTupleKeyTest.java
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ fgaClient.writeAssertions(assertions, options).get();

- [Assertion](https://github.com/openfga/java-sdk/blob/main/docs/Assertion.md)

- [AssertionTupleKey](https://github.com/openfga/java-sdk/blob/main/docs/AssertionTupleKey.md)

- [AuthorizationModel](https://github.com/openfga/java-sdk/blob/main/docs/AuthorizationModel.md)

- [CheckRequest](https://github.com/openfga/java-sdk/blob/main/docs/CheckRequest.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/Assertion.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**tupleKey** | [**CheckRequestTupleKey**](CheckRequestTupleKey.md) | | |
|**tupleKey** | [**AssertionTupleKey**](AssertionTupleKey.md) | | |
|**expectation** | **Boolean** | | |


Expand Down
15 changes: 15 additions & 0 deletions docs/AssertionTupleKey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


# AssertionTupleKey


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**_object** | **String** | | |
|**relation** | **String** | | |
|**user** | **String** | | |



4 changes: 2 additions & 2 deletions src/main/java/dev/openfga/sdk/api/client/ClientAssertion.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package dev.openfga.sdk.api.client;

import dev.openfga.sdk.api.model.Assertion;
import dev.openfga.sdk.api.model.CheckRequestTupleKey;
import dev.openfga.sdk.api.model.AssertionTupleKey;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -72,7 +72,7 @@ public boolean getExpectation() {
}

public Assertion asAssertion() {
var tupleKey = new CheckRequestTupleKey().user(user).relation(relation)._object(_object);
var tupleKey = new AssertionTupleKey().user(user).relation(relation)._object(_object);
return new Assertion().tupleKey(tupleKey).expectation(expectation);
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/openfga/sdk/api/model/Assertion.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
@JsonPropertyOrder({Assertion.JSON_PROPERTY_TUPLE_KEY, Assertion.JSON_PROPERTY_EXPECTATION})
public class Assertion {
public static final String JSON_PROPERTY_TUPLE_KEY = "tuple_key";
private CheckRequestTupleKey tupleKey;
private AssertionTupleKey tupleKey;

public static final String JSON_PROPERTY_EXPECTATION = "expectation";
private Boolean expectation;

public Assertion() {}

public Assertion tupleKey(CheckRequestTupleKey tupleKey) {
public Assertion tupleKey(AssertionTupleKey tupleKey) {
this.tupleKey = tupleKey;
return this;
}
Expand All @@ -45,13 +45,13 @@ public Assertion tupleKey(CheckRequestTupleKey tupleKey) {
@javax.annotation.Nonnull
@JsonProperty(JSON_PROPERTY_TUPLE_KEY)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public CheckRequestTupleKey getTupleKey() {
public AssertionTupleKey getTupleKey() {
return tupleKey;
}

@JsonProperty(JSON_PROPERTY_TUPLE_KEY)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setTupleKey(CheckRequestTupleKey tupleKey) {
public void setTupleKey(AssertionTupleKey tupleKey) {
this.tupleKey = tupleKey;
}

Expand Down
217 changes: 217 additions & 0 deletions src/main/java/dev/openfga/sdk/api/model/AssertionTupleKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
/*
* OpenFGA
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
*
* The version of the OpenAPI document: 0.1
* Contact: [email protected]
*
* 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.api.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.StringJoiner;

/**
* AssertionTupleKey
*/
@JsonPropertyOrder({
AssertionTupleKey.JSON_PROPERTY_OBJECT,
AssertionTupleKey.JSON_PROPERTY_RELATION,
AssertionTupleKey.JSON_PROPERTY_USER
})
public class AssertionTupleKey {
public static final String JSON_PROPERTY_OBJECT = "object";
private String _object;

public static final String JSON_PROPERTY_RELATION = "relation";
private String relation;

public static final String JSON_PROPERTY_USER = "user";
private String user;

public AssertionTupleKey() {}

public AssertionTupleKey _object(String _object) {
this._object = _object;
return this;
}

/**
* Get _object
* @return _object
**/
@javax.annotation.Nonnull
@JsonProperty(JSON_PROPERTY_OBJECT)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public String getObject() {
return _object;
}

@JsonProperty(JSON_PROPERTY_OBJECT)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setObject(String _object) {
this._object = _object;
}

public AssertionTupleKey relation(String relation) {
this.relation = relation;
return this;
}

/**
* Get relation
* @return relation
**/
@javax.annotation.Nonnull
@JsonProperty(JSON_PROPERTY_RELATION)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public String getRelation() {
return relation;
}

@JsonProperty(JSON_PROPERTY_RELATION)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setRelation(String relation) {
this.relation = relation;
}

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

/**
* Get user
* @return user
**/
@javax.annotation.Nonnull
@JsonProperty(JSON_PROPERTY_USER)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public String getUser() {
return user;
}

@JsonProperty(JSON_PROPERTY_USER)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setUser(String user) {
this.user = user;
}

/**
* Return true if this AssertionTupleKey object is equal to o.
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AssertionTupleKey assertionTupleKey = (AssertionTupleKey) o;
return Objects.equals(this._object, assertionTupleKey._object)
&& Objects.equals(this.relation, assertionTupleKey.relation)
&& Objects.equals(this.user, assertionTupleKey.user);
}

@Override
public int hashCode() {
return Objects.hash(_object, relation, user);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class AssertionTupleKey {\n");
sb.append(" _object: ").append(toIndentedString(_object)).append("\n");
sb.append(" relation: ").append(toIndentedString(relation)).append("\n");
sb.append(" user: ").append(toIndentedString(user)).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 ");
}

/**
* Convert the instance into URL query string.
*
* @return URL query string
*/
public String toUrlQueryString() {
return toUrlQueryString(null);
}

/**
* Convert the instance into URL query string.
*
* @param prefix prefix of the query string
* @return URL query string
*/
public String toUrlQueryString(String prefix) {
String suffix = "";
String containerSuffix = "";
String containerPrefix = "";
if (prefix == null) {
// style=form, explode=true, e.g. /pet?name=cat&type=manx
prefix = "";
} else {
// deepObject style e.g. /pet?id[name]=cat&id[type]=manx
prefix = prefix + "[";
suffix = "]";
containerSuffix = "]";
containerPrefix = "[";
}

StringJoiner joiner = new StringJoiner("&");

// add `object` to the URL query string
if (getObject() != null) {
joiner.add(String.format(
"%sobject%s=%s",
prefix,
suffix,
URLEncoder.encode(String.valueOf(getObject()), StandardCharsets.UTF_8)
.replaceAll("\\+", "%20")));
}

// add `relation` to the URL query string
if (getRelation() != null) {
joiner.add(String.format(
"%srelation%s=%s",
prefix,
suffix,
URLEncoder.encode(String.valueOf(getRelation()), StandardCharsets.UTF_8)
.replaceAll("\\+", "%20")));
}

// add `user` to the URL query string
if (getUser() != null) {
joiner.add(String.format(
"%suser%s=%s",
prefix,
suffix,
URLEncoder.encode(String.valueOf(getUser()), StandardCharsets.UTF_8)
.replaceAll("\\+", "%20")));
}

return joiner.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public void write_readAssertions() throws Exception {
String authModelId = writeAuthModel(storeId);
WriteAssertionsRequest writeRequest = new WriteAssertionsRequest()
.assertions(List.of(new Assertion()
.tupleKey(new CheckRequestTupleKey()
.tupleKey(new AssertionTupleKey()
.user(DEFAULT_USER)
.relation("reader")
._object(DEFAULT_DOC))
Expand All @@ -310,7 +310,7 @@ public void write_readAssertions() throws Exception {
// Then
String responseJson = mapper.writeValueAsString(response.getAssertions());
assertEquals(
"[{\"tuple_key\":{\"user\":\"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\"relation\":\"reader\",\"object\":\"document:2021-budget\"},\"expectation\":true}]",
"[{\"tuple_key\":{\"object\":\"document:2021-budget\",\"relation\":\"reader\",\"user\":\"user:81684243-9356-4421-8fbf-a4f8d36aa31b\"},\"expectation\":true}]",
responseJson);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void write_readAssertions() throws Exception {
// Then
String responseJson = mapper.writeValueAsString(response.getAssertions());
assertEquals(
"[{\"tuple_key\":{\"user\":\"user:81684243-9356-4421-8fbf-a4f8d36aa31b\",\"relation\":\"reader\",\"object\":\"document:2021-budget\"},\"expectation\":true}]",
"[{\"tuple_key\":{\"object\":\"document:2021-budget\",\"relation\":\"reader\",\"user\":\"user:81684243-9356-4421-8fbf-a4f8d36aa31b\"},\"expectation\":true}]",
responseJson);
}

Expand Down
Loading

0 comments on commit 4d42405

Please sign in to comment.