schema

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package schema provides schema parsing, serialization, and resolution.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

Schema provides parsing and marshaling for Cedar schemas.

Example
package main

import (
	"fmt"

	"github.com/cedar-policy/cedar-go/x/exp/schema"
)

const exampleCedar = `entity User in [Group] {
	name: String,
	age?: Long
};

entity Group;

entity Photo {
	owner: User,
	tags: Set<String>
};

entity Status enum ["active", "inactive"];

action viewPhoto appliesTo {
	principal: User,
	resource: Photo,
	context: {}
};
`

func main() {
	var s schema.Schema
	if err := s.UnmarshalCedar([]byte(exampleCedar)); err != nil {
		fmt.Println("schema parse error:", err)
		return
	}

	resolved, err := s.Resolve()
	if err != nil {
		fmt.Println("schema resolve error:", err)
		return
	}

	for entityType := range resolved.Entities {
		fmt.Println("entity:", entityType)
	}
	for _, enum := range resolved.Enums {
		fmt.Println("enum:", enum.Name)
	}
	for actionUID := range resolved.Actions {
		fmt.Println("action:", actionUID)
	}
}
Output:

entity: User
entity: Group
entity: Photo
enum: Status
action: Action::"viewPhoto"

func NewSchemaFromAST added in v1.5.1

func NewSchemaFromAST(in *ast.Schema) *Schema

NewSchemaFromAST creates a Schema from an AST.

func (*Schema) AST added in v1.5.1

func (s *Schema) AST() *ast.Schema

AST returns the underlying AST.

func (*Schema) MarshalCedar

func (s *Schema) MarshalCedar() ([]byte, error)

MarshalCedar encodes the Schema in the human-readable format.

func (*Schema) MarshalJSON

func (s *Schema) MarshalJSON() ([]byte, error)

MarshalJSON encodes the Schema in the JSON format.

func (*Schema) Resolve added in v1.5.1

func (s *Schema) Resolve() (*resolved.Schema, error)

Resolve returns a resolved.Schema with type references resolved and declarations indexed.

func (*Schema) SetFilename

func (s *Schema) SetFilename(filename string)

SetFilename sets the filename for error reporting.

func (*Schema) UnmarshalCedar

func (s *Schema) UnmarshalCedar(b []byte) error

UnmarshalCedar parses a Schema in the human-readable format.

func (*Schema) UnmarshalJSON

func (s *Schema) UnmarshalJSON(b []byte) error

UnmarshalJSON parses a Schema in the JSON format.

Directories

Path Synopsis
Package ast provides types for constructing Cedar schema ASTs programmatically.
Package ast provides types for constructing Cedar schema ASTs programmatically.
internal
json
Package json provides JSON marshaling and unmarshaling for Cedar schema ASTs.
Package json provides JSON marshaling and unmarshaling for Cedar schema ASTs.
parser
Package parser provides Cedar schema text parsing and formatting.
Package parser provides Cedar schema text parsing and formatting.
Package resolved transforms an AST schema into a resolved schema where all type references are fully qualified and common types are inlined.
Package resolved transforms an AST schema into a resolved schema where all type references are fully qualified and common types are inlined.

Jump to

Keyboard shortcuts

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