openfga / language

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

add methods to validate types, relations, ids and tuples #226

Open rhamzeh opened 3 months ago

rhamzeh commented 3 months ago

Let's plan on moving this logic to language and have test cases for them, we can then implement this in several languages consistently

Originally posted by @rhamzeh in https://github.com/openfga/vscode-ext/pull/215#pullrequestreview-1981267968

Current set of regexes used:

Protos:

API: https://github.com/openfga/openfga/blob/main/pkg/tuple/tuple.go#L35-L38

    userIDRegex   = regexp.MustCompile(`^[^:#\s]+$`)
    objectRegex   = regexp.MustCompile(`^[^:#\s]+:[^#:\s]+$`)
    userSetRegex  = regexp.MustCompile(`^[^:#\s]+:[^#\s]+#[^:#\s]+$`)
    relationRegex = regexp.MustCompile(`^[^:#@\s]+$`)

Validation has to pass both sets of regexes above in order to be valid according to the API.


On the VS Code/Playground side we use a different set of less permissive regexes: https://github.com/openfga/vscode-ext/blob/07e65ccd3a0d533bcbbb2b4495899d73d2656e3b/server/src/openfga-yaml-schema.ts#L126-L154

We have yet more regexes in language: https://github.com/openfga/language/blob/35310a2e97386126a01db1c4360e013d984f98f2/pkg/js/validator/validate-dsl.ts#L7-L10