api icon indicating copy to clipboard operation
api copied to clipboard

refactor: change TypeDefinition signature to be more canonical

Open jon-whit opened this issue 1 year ago • 1 comments

Today a TypeDefinition has the following protobuf definition:

message TypeDefinition {
    string type = 1;
    map<string, Userset> relations = 2;
    Metadata metadata = 3;
}

https://github.com/openfga/api/blob/main/openfga/v1/authzmodel.proto#L26

A more canonical and easier consume definition of a TypeDefinition would look like:

message TypeDefinition {
    string type = 1;
    map<string, Relation> relations = 2;
}

https://github.com/openfga/api/blob/main/openfga/v1/authzmodel.proto#L42

The only reason(s) why the metadata field is needed today is because we did not want to break existing compatibility with the Userset definition in the map<string, Userset> and so we introduced an additional field. The Relation definition itself should encapsulate all of the information/metadata associated with the relation. Doing so will allow the OpenFGA core and other integrations to more seemlessly make use of a TypeDefinition and the relations contained therein without having to reconstruct a map[string]Relation all over the place in client code.

References: https://github.com/openfga/openfga/pull/726/files#r1189164147

jon-whit avatar May 09 '23 21:05 jon-whit

Note that this will be a breaking change for the WriteAuthorizationModel API

miparnisari avatar May 09 '23 22:05 miparnisari