openfga / language

Grammar for the OpenFGA modeling language
https://openfga.dev
Apache License 2.0
17 stars 7 forks source link

Language incorrectly transforms JSON syntax that is not supported in the DSL #59

Closed rhamzeh closed 1 year ago

rhamzeh commented 1 year ago

For example, the below currently cannot be represented in JSON

{
  "schema_version": "1.1",
  "type_definitions": [
    {
      "type": "user",
      "relations": {}
    },
    {
      "type": "folder",
      "relations": {
        "admin": {
          "this": {}
        },
        "viewer": {
          "this": {}
        },
        "blocked": {
          "this": {}
        },
        "can_view": {
          "union": {
            "child": [
              {
                "computedUserset": {
                  "object": "",
                  "relation": "admin"
                }
              },
              {
                "difference": {
                  "base": {
                    "computedUserset": {
                      "object": "",
                      "relation": "viewer"
                    }
                  },
                  "subtract": {
                    "computedUserset": {
                      "object": "",
                      "relation": "blocked"
                    }
                  }
                }
              }
            ]
          }
        }
      },
      "metadata": {
        "relations": {
          "admin": {
            "directly_related_user_types": [
              {
                "type": "user"
              }
            ]
          },
          "viewer": {
            "directly_related_user_types": [
              {
                "type": "user"
              }
            ]
          },
          "blocked": {
            "directly_related_user_types": [
              {
                "type": "user"
              }
            ]
          },
          "can_view": {
            "directly_related_user_types": []
          }
        }
      }
    }
  ]
}

and the language transforms it to:

model
  schema 1.1

type user

type folder
  relations
    define admin: [user]
    define blocked: [user]
    define can_view: admin or
    define viewer: [user]