clientgen

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package clientgen provides a public API for generating type-safe client code from authorization schemas.

This package wraps the internal generator registry, providing a stable public interface for programmatic code generation. For CLI usage, see the melange command: `melange generate client --runtime go`.

Supported Runtimes

Currently supported:

  • "go" - Type-safe Go code with constants and constructors

Registered but not yet implemented:

  • "typescript" - TypeScript types and factory functions (stub)

Example Usage

types, _ := parser.ParseSchema("schema.fga")
files, err := clientgen.Generate("go", types, nil)
if err != nil {
    log.Fatal(err)
}
for filename, content := range files {
    os.WriteFile(filename, content, 0644)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(runtime string, types []TypeDefinition, cfg *Config) (map[string][]byte, error)

Generate produces client code for the specified runtime.

Supported runtimes: "go"

Returns a map of filename -> content. For single-file outputs (like Go), the map contains one entry. Multi-file outputs (like TypeScript) will contain multiple entries.

Returns an error if the runtime is not registered or generation fails.

func GenerateGo deprecated

func GenerateGo(w io.Writer, types []TypeDefinition, cfg *GenerateConfig) error

GenerateGo writes type-safe Go code from a parsed OpenFGA schema.

This function is provided for backwards compatibility. New code should use Generate("go", types, cfg) instead.

Deprecated: Use Generate("go", types, cfg) instead.

func ListRuntimes

func ListRuntimes() []string

ListRuntimes returns all registered runtime names.

func Registered

func Registered(name string) bool

Registered returns true if a generator exists for the given runtime name.

Types

type Config

type Config = clientgen.Config

Config is an alias for the internal Config type. This allows users to configure code generation without importing internal packages.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns sensible defaults for code generation. Package: "authz", no relation filter (all relations), string IDs.

type GenerateConfig deprecated

type GenerateConfig struct {
	// Package name for generated code. Default: "authz"
	Package string

	// RelationPrefixFilter is a prefix filter for relation names.
	// Only relations with this prefix will have constants generated.
	// If empty, all relations will be generated.
	RelationPrefixFilter string

	// IDType specifies the type to use for object IDs.
	// Default: "string"
	IDType string
}

GenerateConfig is provided for backwards compatibility. New code should use Config instead.

Deprecated: Use Config instead.

func DefaultGenerateConfig deprecated

func DefaultGenerateConfig() *GenerateConfig

DefaultGenerateConfig returns sensible defaults for code generation.

Deprecated: Use DefaultConfig instead.

type TypeDefinition

type TypeDefinition = schema.TypeDefinition

TypeDefinition is an alias for schema.TypeDefinition.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL