Documentation
¶
Overview ¶
Package parser provides OpenFGA schema parsing for melange.
This package wraps the official OpenFGA language parser to convert .fga schema files into melange's internal TypeDefinition format. It isolates the OpenFGA parser dependency from other packages.
Basic Usage ¶
Parse a schema file:
types, err := parser.ParseSchema("schemas/schema.fga")
if err != nil {
log.Fatal(err)
}
Parse schema from a string:
types, err := parser.ParseSchemaString(schemaContent)
Dependency Isolation ¶
The parser package is the only melange package that imports the OpenFGA language parser. This keeps the runtime (github.com/pthm/melange/melange) free of external dependencies.
Consumers of parsed schemas should use pkg/schema types, which have no external dependencies.
Index ¶
- func ConvertProtoModel(model *openfgav1.AuthorizationModel) []schema.TypeDefinition
- func IsModularSchema(path string) bool
- func ParseManifestEntries(manifestContent string) (schemaVersion string, paths []string, err error)
- func ParseModularSchema(manifestPath string) ([]schema.TypeDefinition, error)
- func ParseModularSchemaFromStrings(modules map[string]string, schemaVersion string) ([]schema.TypeDefinition, error)
- func ParseSchema(path string) ([]schema.TypeDefinition, error)
- func ParseSchemaString(content string) ([]schema.TypeDefinition, error)
- func ReadManifestContents(manifestPath string) ([]byte, error)
- func ReadSchemaContent(path string) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertProtoModel ¶
func ConvertProtoModel(model *openfgav1.AuthorizationModel) []schema.TypeDefinition
ConvertProtoModel converts an OpenFGA protobuf AuthorizationModel to schema TypeDefinitions. This is useful when you have a protobuf model directly (e.g., from the OpenFGA API) rather than DSL text.
This function is used by the OpenFGA test suite adapter to convert test models without re-implementing the parsing logic.
func IsModularSchema ¶ added in v0.8.0
IsModularSchema reports whether path points to an fga.mod manifest.
func ParseManifestEntries ¶ added in v0.8.0
ParseManifestEntries parses an fga.mod manifest string and returns the schema version and relative paths of all referenced module files. This enables callers to read a manifest from any source (filesystem, git, etc.) and then fetch module files individually.
func ParseModularSchema ¶ added in v0.8.0
func ParseModularSchema(manifestPath string) ([]schema.TypeDefinition, error)
ParseModularSchema parses an fga.mod manifest and all referenced module files, merging them into a unified set of type definitions.
Uses the upstream OpenFGA library for manifest parsing (TransformModFile), module merging (TransformModuleFilesToModel), and all validation including duplicate relation detection, undefined type extensions, and schema version checks.
func ParseModularSchemaFromStrings ¶ added in v0.8.0
func ParseModularSchemaFromStrings(modules map[string]string, schemaVersion string) ([]schema.TypeDefinition, error)
ParseModularSchemaFromStrings parses pre-read module contents and merges them into unified type definitions. Useful for testing and embedded schemas where module files are already in memory.
Module names are sorted for deterministic processing order.
func ParseSchema ¶
func ParseSchema(path string) ([]schema.TypeDefinition, error)
ParseSchema reads an OpenFGA schema and returns type definitions. Accepts either a single .fga file or an fga.mod manifest for modular schemas.
For single .fga files, uses the existing single-file parser. For fga.mod manifests, reads all referenced module files and merges them into a unified model using the upstream OpenFGA library.
func ParseSchemaString ¶
func ParseSchemaString(content string) ([]schema.TypeDefinition, error)
ParseSchemaString parses OpenFGA DSL content and returns type definitions. This is the core parser used by both file-based and string-based parsing. Wraps the OpenFGA transformer to convert protobuf models to our format.
func ReadManifestContents ¶ added in v0.8.0
ReadManifestContents reads an fga.mod manifest and all referenced module files, returning their concatenated contents as a single byte slice. The output is deterministic (files ordered as listed in the manifest) and suitable for content hashing in migration skip detection.
func ReadSchemaContent ¶ added in v0.8.0
ReadSchemaContent reads the full content of a schema for hashing purposes. For single .fga files, returns the file bytes directly. For fga.mod manifests, returns the manifest plus all referenced module files concatenated in manifest order (deterministic).
Types ¶
This section is empty.