openfga / language

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

Implement transforming `fga.mod` #165

Closed ewanharris closed 4 months ago

ewanharris commented 4 months ago

Description

Adds test cases for transforming and validating an fga.mod file and then implements the function for JS. Currently working on Go and will move to ready once completed. Just putting up the PR now to get a review of the JS side ahead of then.

The transformModFileToJSON function will take a string representing a fga.mod file, parse it and then validate the fields inside. Given that this is isn't a complex file I've decided to just go checking ourselves rather than offloading onto a package like ajv to perform JSON Schema validation.

All error cases and messages are up for discussion, I'm not particularly married to them just tried to hit most I could think of.

I still need to add test cases for invalid yaml file (if that's possible to do inside our YAML test definition file 🤔 )

There's maybe some contention around this living alongside the existing transform functions but also implementing validation. I'm not sure if we can extend this to a transform/validate function similar to others however due to the requirement on the yaml document when validating.

References

Closes #154

Review Checklist