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 ¶
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 ParseSchema ¶
func ParseSchema(path string) ([]schema.TypeDefinition, error)
ParseSchema reads an OpenFGA .fga file and returns type definitions. Uses the official OpenFGA language parser to ensure compatibility with the OpenFGA ecosystem and tooling.
The parser extracts type definitions, relations, and metadata that are then converted to melange's internal representation for code generation and database migration.
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.
Types ¶
This section is empty.