java-sdk icon indicating copy to clipboard operation
java-sdk copied to clipboard

The argument types of write api and delete api are inconsistent.

Open xXAvoraXx opened this issue 1 year ago • 2 comments

Checklist

  • [X] I have looked into the README and have not found a suitable solution or answer.
  • [X] I have looked into the documentation and have not found a suitable solution or answer.
  • [X] I have searched the issues and have not found a suitable solution or answer.
  • [X] I have upgraded to the latest version of OpenFGA and the issue still persists.
  • [X] I have searched the Slack community and have not found a suitable solution or answer.
  • [X] I agree to the terms within the OpenFGA Code of Conduct.

Description

I am using an object I created with the ClientTupleKey type for both write operation and delete operation, but I encounter a type error for delete operation.

The method deletes(List<ClientTupleKeyWithoutCondition>) in the type ClientWriteRequest is not applicable for the arguments (List<ClientTupleKey>) Java(67108979)

package dev.openfga.sdk.api.client.model;

import java.util.List;

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

   public ClientWriteRequest() {
   }

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

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

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

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

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

   public List<ClientTupleKeyWithoutCondition> getDeletes() {
      return this.deletes;
   }
}

Expectation

The arguments of the delete api must have the same type as the arguments of the write api.

Reproduction

        ClientWriteRequest client = new ClientWriteRequest();

        List<ClientTupleKey> tuples = new ArrayList<ClientTupleKey>();

        tuples.add(new ClientTupleKey()
                .user("parent_group:" + event.getEventUserId())
                .relation("assignee")
                ._object("group:" + event.getEventUserId()));
        tuples.add(new ClientTupleKey()
                .user("member_group:" + event.getEventUserId())
                .relation("assignee")
                ._object("group:" + event.getEventUserId()));

        if(event.isEventUserChildOfObject()){
            tuples.add(new ClientTupleKey()
                    .user("parent_group:" + event.getEventUserId())
                    .relation("parent")
                    ._object("parent_group:" + event.getEventObjectId()));

            tuples.add(new ClientTupleKey()
                    .user("member_group:" + event.getEventObjectId())
                    .relation("member")
                    ._object("member_group:" + event.getEventUserId()));
        }

        if(event.isWriteOperation()) {
            client.writes(tuples);
        }
        else if(event.isDeleteOperation()) {
            client.deletes(tuples);
        }

OpenFGA SDK version

0.5.0

OpenFGA version

1.5.7

SDK Configuration

Logs

No response

References

No response

xXAvoraXx avatar Jul 30 '24 12:07 xXAvoraXx

:wave: hi @xXAvoraXx, thanks for raising an issue!

If I am understanding correctly, you are expecting that the tuple arguments for write and delete are the same. However, the schema for writes vs. delete is actually different, hence the different argument types. The write schema looks like this, notice the different types for the argument to write versus delete (because write accepts a condition param, but delete does not):

image

As the models are generated from the API schema, we see that the SDK type is consistent with the API schema. Hope that helps clear up any confusion!

jimmyjames avatar Sep 10 '24 19:09 jimmyjames

Hi @jimmyjames I actually expect it to accept the same type conversions as in the .NET SDK, because there is no condition in the tuples value I create with ClientTupleKey and I waste time doing type conversions when I want to delete. If you examine the example I gave, I create the tuples with ClientTupleKey when the event is delete or write, but if it is delete, I have to do a type conversion.

xXAvoraXx avatar Sep 11 '24 09:09 xXAvoraXx

Hello @xXAvoraXx, while we try to maintain consistency across all languages of the SDKs, we do not have a requirement that makes this compulsory. As @jimmyjames mentioned, the models are generated from the OpenAPI schema. The response schemas for write and delete match the API and are therefore not inconsistent. This is an invalid bug and I will be closing this issue. Please let me know if you have further questions. Thank you.

dyeam0 avatar Aug 27 '25 03:08 dyeam0