openfga / api

Protocol Buffers used by OpenFGA
Apache License 2.0
19 stars 14 forks source link

refactor: change TypeDefinition signature to be more canonical #77

Open jon-whit opened 1 year ago

jon-whit commented 1 year ago

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

miparnisari commented 1 year ago

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