Skip to content

Commit

Permalink
refactor(client): change naming of tuple key classes
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Dec 6, 2023
1 parent 58c2993 commit 17e8f04
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ src/main/java/dev/openfga/sdk/api/client/ClientReadRequest.java
src/main/java/dev/openfga/sdk/api/client/ClientReadResponse.java
src/main/java/dev/openfga/sdk/api/client/ClientRelationshipCondition.java
src/main/java/dev/openfga/sdk/api/client/ClientTupleKey.java
src/main/java/dev/openfga/sdk/api/client/ClientTupleKeyWithCondition.java
src/main/java/dev/openfga/sdk/api/client/ClientTupleKeyWithoutCondition.java
src/main/java/dev/openfga/sdk/api/client/ClientWriteAssertionsResponse.java
src/main/java/dev/openfga/sdk/api/client/ClientWriteAuthorizationModelResponse.java
src/main/java/dev/openfga/sdk/api/client/ClientWriteRequest.java
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ var request = new ClientWriteRequest()
._object("document:budget")
))
.deletes(List.of(
new ClientTupleKey()
new ClientTupleKeyWithoutCondition()
.user("user:81684243-9356-4421-8fbf-a4f8d36aa31b")
.relation("writer")
._object("document:roadmap")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ClientCheckRequest {
private String user;
private String relation;
private String _object;
private List<ClientTupleKeyWithCondition> contextualTuples;
private List<ClientTupleKey> contextualTuples;

public CheckRequestTupleKey asCheckRequestTupleKey() {
return new CheckRequestTupleKey().user(user).relation(relation)._object(_object);
Expand Down Expand Up @@ -64,12 +64,12 @@ public String getUser() {
return user;
}

public ClientCheckRequest contextualTuples(List<ClientTupleKeyWithCondition> contextualTuples) {
public ClientCheckRequest contextualTuples(List<ClientTupleKey> contextualTuples) {
this.contextualTuples = contextualTuples;
return this;
}

public List<ClientTupleKeyWithCondition> getContextualTuples() {
public List<ClientTupleKey> getContextualTuples() {
return contextualTuples;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ClientListObjectsRequest {
private String user;
private String relation;
private String type;
private List<ClientTupleKeyWithCondition> contextualTupleKeys;
private List<ClientTupleKey> contextualTupleKeys;

public ClientListObjectsRequest user(String user) {
this.user = user;
Expand Down Expand Up @@ -55,12 +55,12 @@ public String getType() {
return type;
}

public ClientListObjectsRequest contextualTupleKeys(List<ClientTupleKeyWithCondition> contextualTupleKeys) {
public ClientListObjectsRequest contextualTupleKeys(List<ClientTupleKey> contextualTupleKeys) {
this.contextualTupleKeys = contextualTupleKeys;
return this;
}

public List<ClientTupleKeyWithCondition> getContextualTupleKeys() {
public List<ClientTupleKey> getContextualTupleKeys() {
return contextualTupleKeys;
}
}
86 changes: 35 additions & 51 deletions src/main/java/dev/openfga/sdk/api/client/ClientTupleKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,77 +12,61 @@

package dev.openfga.sdk.api.client;

import dev.openfga.sdk.api.model.TupleKeyWithoutCondition;
import dev.openfga.sdk.api.model.WriteRequestDeletes;
import dev.openfga.sdk.api.model.ContextualTupleKeys;
import dev.openfga.sdk.api.model.TupleKey;
import dev.openfga.sdk.api.model.WriteRequestWrites;
import java.util.Collection;
import java.util.stream.Collectors;

public class ClientTupleKey {
private String user;
private String relation;
private String _object;
public class ClientTupleKey extends ClientTupleKeyWithoutCondition {
private ClientRelationshipCondition condition;

public TupleKeyWithoutCondition asTupleKeyWithoutCondition() {
return new TupleKeyWithoutCondition().user(user).relation(relation)._object(_object);
public ClientTupleKey condition(ClientRelationshipCondition condition) {
this.condition = condition;
return this;
}

public static WriteRequestDeletes asWriteRequestDeletes(Collection<ClientTupleKey> tupleKeys) {
return new WriteRequestDeletes()
.tupleKeys(tupleKeys.stream()
.map(ClientTupleKey::asTupleKeyWithoutCondition)
.collect(Collectors.toList()));
public ClientRelationshipCondition getCondition() {
return condition;
}

public ClientTupleKey _object(String _object) {
this._object = _object;
return this;
}
public TupleKey asTupleKey() {
var tupleKey = new TupleKey().user(getUser()).relation(getRelation())._object(getObject());

if (condition != null) {
tupleKey.condition(condition.asRelationshipCondition());
}

/**
* Get _object
* @return _object
**/
public String getObject() {
return _object;
return tupleKey;
}

public ClientTupleKey relation(String relation) {
this.relation = relation;
return this;
public static ContextualTupleKeys asContextualTupleKeys(Collection<ClientTupleKey> tupleKeys) {
return new ContextualTupleKeys()
.tupleKeys(tupleKeys.stream().map(ClientTupleKey::asTupleKey).collect(Collectors.toList()));
}

/**
* Get relation
* @return relation
**/
public String getRelation() {
return relation;
public static WriteRequestWrites asWriteRequestWrites(Collection<ClientTupleKey> tupleKeys) {
return new WriteRequestWrites()
.tupleKeys(tupleKeys.stream().map(ClientTupleKey::asTupleKey).collect(Collectors.toList()));
}

/* Overrides for correct typing */

@Override
public ClientTupleKey user(String user) {
this.user = user;
super.user(user);
return this;
}

/**
* Get user
* @return user
**/
public String getUser() {
return user;
@Override
public ClientTupleKey relation(String relation) {
super.relation(relation);
return this;
}

/**
* Adds a condition to the tuple key.
* @param condition a {@link ClientRelationshipCondition}
* @return a new {@link ClientTupleKeyWithCondition} with this {@link ClientTupleKey}'s
* user, relation, and object, and the passed condition.
*/
public ClientTupleKeyWithCondition condition(ClientRelationshipCondition condition) {
return new ClientTupleKeyWithCondition()
.user(user)
.relation(relation)
._object(_object)
.condition(condition);
@Override
public ClientTupleKey _object(String _object) {
super._object(_object);
return this;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.client;

import dev.openfga.sdk.api.model.TupleKeyWithoutCondition;
import dev.openfga.sdk.api.model.WriteRequestDeletes;
import java.util.Collection;
import java.util.stream.Collectors;

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

public TupleKeyWithoutCondition asTupleKeyWithoutCondition() {
return new TupleKeyWithoutCondition().user(user).relation(relation)._object(_object);
}

public static WriteRequestDeletes asWriteRequestDeletes(Collection<ClientTupleKeyWithoutCondition> tupleKeys) {
return new WriteRequestDeletes()
.tupleKeys(tupleKeys.stream()
.map(ClientTupleKeyWithoutCondition::asTupleKeyWithoutCondition)
.collect(Collectors.toList()));
}

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

/**
* Get _object
* @return _object
**/
public String getObject() {
return _object;
}

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

/**
* Get relation
* @return relation
**/
public String getRelation() {
return relation;
}

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

/**
* Get user
* @return user
**/
public String getUser() {
return user;
}

/**
* Adds a condition to the tuple key.
* @param condition a {@link ClientRelationshipCondition}
* @return a new {@link ClientTupleKey} with this {@link ClientTupleKeyWithoutCondition}'s
* user, relation, and object, and the passed condition.
*/
public ClientTupleKey condition(ClientRelationshipCondition condition) {
return new ClientTupleKey()
.user(user)
.relation(relation)
._object(_object)
.condition(condition);
}
}
16 changes: 8 additions & 8 deletions src/main/java/dev/openfga/sdk/api/client/ClientWriteRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@
import java.util.List;

public class ClientWriteRequest {
private List<ClientTupleKeyWithCondition> writes;
private List<ClientTupleKey> deletes;
private List<ClientTupleKey> writes;
private List<ClientTupleKeyWithoutCondition> deletes;

public static ClientWriteRequest ofWrites(List<ClientTupleKeyWithCondition> writes) {
public static ClientWriteRequest ofWrites(List<ClientTupleKey> writes) {
return new ClientWriteRequest().writes(writes);
}

public ClientWriteRequest writes(List<ClientTupleKeyWithCondition> writes) {
public ClientWriteRequest writes(List<ClientTupleKey> writes) {
this.writes = writes;
return this;
}

public List<ClientTupleKeyWithCondition> getWrites() {
public List<ClientTupleKey> getWrites() {
return writes;
}

public static ClientWriteRequest ofDeletes(List<ClientTupleKey> deletes) {
public static ClientWriteRequest ofDeletes(List<ClientTupleKeyWithoutCondition> deletes) {
return new ClientWriteRequest().deletes(deletes);
}

public ClientWriteRequest deletes(List<ClientTupleKey> deletes) {
public ClientWriteRequest deletes(List<ClientTupleKeyWithoutCondition> deletes) {
this.deletes = deletes;
return this;
}

public List<ClientTupleKey> getDeletes() {
public List<ClientTupleKeyWithoutCondition> getDeletes() {
return deletes;
}
}
Loading

0 comments on commit 17e8f04

Please sign in to comment.