shared

package
v0.1.1-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalFieldsJSON

func MarshalFieldsJSON(fields []Field) ([]byte, error)

MarshalFieldsJSON marshals an ordered list of fields as a JSON object. Fields whose values are considered empty (nil, zero-length, zero-value) are omitted.

func MarshalFieldsYAML

func MarshalFieldsYAML(fields []Field) (*yaml.Node, error)

MarshalFieldsYAML builds a *yaml.Node mapping from an ordered list of fields. Fields whose values are considered empty are omitted.

Types

type ElementBase

type ElementBase struct {
	VendorExtensions map[string]interface{} `json:"-" yaml:"-"`
	Trix             Trix                   `json:"-" yaml:"-"`
}

ElementBase is embedded in all OpenAPI types to provide vendor extensions and library metadata.

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field is a key-value pair for ordered marshalling.

func AppendExtensions

func AppendExtensions(fields []Field, extensions map[string]interface{}) []Field

AppendExtensions appends sorted vendor extension entries to a field list.

type HookFunc

type HookFunc func(field string, oldVal, newVal interface{}) error

HookFunc is called before a field is set. Return a non-nil error to reject the change.

type Location

type Location struct {
	Line   int `json:"-" yaml:"-"` // 1-based line number
	Column int `json:"-" yaml:"-"` // 1-based column number
}

Location represents a position in the source file.

type MarshalFieldsProvider

type MarshalFieldsProvider interface {
	MarshalFields() []Field
}

MarshalFieldsProvider is implemented by model types that support field-based marshalling. Used by the export package to build serializable trees with ref inlining.

type NodeSource

type NodeSource struct {
	Start Location    `json:"-" yaml:"-"` // Start position
	End   Location    `json:"-" yaml:"-"` // End position
	Raw   interface{} `json:"-" yaml:"-"` // Raw parsed data (map/slice/scalar)
}

NodeSource contains source location and raw parsed data for a node.

type ParseError

type ParseError struct {
	Message string   `json:"-" yaml:"-"` // Human-readable error message
	Path    []string `json:"-" yaml:"-"` // JSON path where the error occurred
	Kind    string   `json:"-" yaml:"-"` // Error kind: "error" or "unknown_field"
}

ParseError represents a parsing error associated with a specific node.

type Ref

type Ref[T any] struct {
	ElementBase
	Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	// contains filtered or unexported fields
}

Ref represents a JSON Reference ($ref) or an inline value of type T. Used by OpenAPI 2.0 and 3.0 models where $ref has no additional fields.

func NewRef

func NewRef[T any](ref string) *Ref[T]

NewRef creates a new Ref with the given $ref string.

func (*Ref[T]) Circular

func (r *Ref[T]) Circular() bool

Circular returns true if a circular reference was detected, blocking if resolution is in progress.

func (*Ref[T]) Done

func (r *Ref[T]) Done() <-chan struct{}

Done returns the done channel for waiting on resolution.

func (*Ref[T]) InitDone

func (r *Ref[T]) InitDone()

InitDone initializes the done channel, signaling this ref needs async resolution.

func (*Ref[T]) MarkDone

func (r *Ref[T]) MarkDone()

MarkDone closes the done channel, unblocking any waiters. Safe to call multiple times; only closes once.

func (*Ref[T]) MarshalJSON

func (r *Ref[T]) MarshalJSON() ([]byte, error)

MarshalJSON serializes the ref: if $ref is set, emits {"$ref":"..."}; if an inline value is set, delegates to the value; otherwise emits null.

func (*Ref[T]) MarshalYAML

func (r *Ref[T]) MarshalYAML() (interface{}, error)

MarshalYAML serializes the ref to YAML.

func (*Ref[T]) RawCircular

func (r *Ref[T]) RawCircular() bool

RawCircular returns the circular flag without blocking. For use by the resolver.

func (*Ref[T]) RawValue

func (r *Ref[T]) RawValue() *T

RawValue returns the value without blocking. For use by the resolver.

func (*Ref[T]) RefInfo

func (r *Ref[T]) RefInfo() (ref string, value interface{})

RefInfo returns the $ref string and the resolved value (or nil). Used by the export package to inspect refs without blocking.

func (*Ref[T]) ResolveErr

func (r *Ref[T]) ResolveErr() error

ResolveErr returns the resolution error, blocking if resolution is in progress.

func (*Ref[T]) SetCircular

func (r *Ref[T]) SetCircular(c bool)

SetCircular sets the circular flag.

func (*Ref[T]) SetResolveErr

func (r *Ref[T]) SetResolveErr(err error)

SetResolveErr sets the resolution error and adds it to Trix.Errors so it appears in ParseResult.Errors.

func (*Ref[T]) SetValue

func (r *Ref[T]) SetValue(v *T)

SetValue sets the resolved value.

func (*Ref[T]) Value

func (r *Ref[T]) Value() *T

Value returns the resolved value, blocking if background resolution is in progress.

type RefWithMeta

type RefWithMeta[T any] struct {
	ElementBase
	Ref         string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Summary     string `json:"summary,omitempty" yaml:"summary,omitempty"`
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	// contains filtered or unexported fields
}

RefWithMeta is like Ref but adds Summary and Description fields as permitted by OpenAPI 3.1's extended $ref syntax.

func NewRefWithMeta

func NewRefWithMeta[T any](ref string) *RefWithMeta[T]

NewRefWithMeta creates a new RefWithMeta with the given $ref string.

func (*RefWithMeta[T]) Circular

func (r *RefWithMeta[T]) Circular() bool

Circular returns true if a circular reference was detected, blocking if resolution is in progress.

func (*RefWithMeta[T]) Done

func (r *RefWithMeta[T]) Done() <-chan struct{}

Done returns the done channel for waiting on resolution.

func (*RefWithMeta[T]) InitDone

func (r *RefWithMeta[T]) InitDone()

InitDone initializes the done channel, signaling this ref needs async resolution.

func (*RefWithMeta[T]) MarkDone

func (r *RefWithMeta[T]) MarkDone()

MarkDone closes the done channel, unblocking any waiters. Safe to call multiple times; only closes once.

func (*RefWithMeta[T]) MarshalJSON

func (r *RefWithMeta[T]) MarshalJSON() ([]byte, error)

MarshalJSON serializes the ref: if $ref is set, emits {"$ref":"...", "summary":"...", "description":"..."}; if an inline value is set, delegates to the value; otherwise emits null.

func (*RefWithMeta[T]) MarshalYAML

func (r *RefWithMeta[T]) MarshalYAML() (interface{}, error)

MarshalYAML serializes the ref to YAML, including summary and description when present.

func (*RefWithMeta[T]) RawCircular

func (r *RefWithMeta[T]) RawCircular() bool

RawCircular returns the circular flag without blocking. For use by the resolver.

func (*RefWithMeta[T]) RawValue

func (r *RefWithMeta[T]) RawValue() *T

RawValue returns the value without blocking. For use by the resolver.

func (*RefWithMeta[T]) RefInfo

func (r *RefWithMeta[T]) RefInfo() (ref string, value interface{})

RefInfo returns the $ref string and the resolved value (or nil). Used by the export package to inspect refs without blocking.

func (*RefWithMeta[T]) ResolveErr

func (r *RefWithMeta[T]) ResolveErr() error

ResolveErr returns the resolution error, blocking if resolution is in progress.

func (*RefWithMeta[T]) SetCircular

func (r *RefWithMeta[T]) SetCircular(c bool)

SetCircular sets the circular flag.

func (*RefWithMeta[T]) SetResolveErr

func (r *RefWithMeta[T]) SetResolveErr(err error)

SetResolveErr sets the resolution error and adds it to Trix.Errors so it appears in ParseResult.Errors.

func (*RefWithMeta[T]) SetValue

func (r *RefWithMeta[T]) SetValue(v *T)

SetValue sets the resolved value.

func (*RefWithMeta[T]) Value

func (r *RefWithMeta[T]) Value() *T

Value returns the resolved value, blocking if background resolution is in progress.

type Trix

type Trix struct {
	Source NodeSource   `json:"-" yaml:"-"` // Source location info
	Errors []ParseError `json:"-" yaml:"-"` // Parsing errors attached to this node
	// contains filtered or unexported fields
}

Trix contains all library-level metadata and functionality. Everything under Trix is provided by the apitrix library, not part of the OpenAPI specification itself.

func (*Trix) OnSet

func (t *Trix) OnSet(field string, fn HookFunc)

OnSet registers a hook that runs before a field is set.

func (*Trix) RunHooks

func (t *Trix) RunHooks(field string, oldVal, newVal interface{}) error

RunHooks runs all registered hooks for the given field. Returns the first error encountered, or nil.

Jump to

Keyboard shortcuts

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