core

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package core contains the backing models for AsyncAPI schemas, retaining the YAML/JSON nodes they were parsed from.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMultiFormatNode

func IsMultiFormatNode(ctx context.Context, node *yaml.Node) bool

IsMultiFormatNode returns true if the node is a Multi Format Schema Object according to the SchemaUnion selection rules.

Types

type Dependency

type Dependency struct {
	marshaller.CoreModel `model:"dependency"`

	Schema     *values.EitherValue[Schema, bool]
	Properties []marshaller.Node[string]
	IsList     bool
}

Dependency is the backing model for a value of the `dependencies` keyword: a list of property names or a schema.

It is a dedicated type rather than a generic EitherValue because it is part of the recursive Schema definition.

func (*Dependency) SyncChanges

func (d *Dependency) SyncChanges(ctx context.Context, model any, valueNode *yaml.Node) (*yaml.Node, error)

func (*Dependency) Unmarshal

func (d *Dependency) Unmarshal(ctx context.Context, parentName string, node *yaml.Node) ([]error, error)

type ExternalDocumentation

type ExternalDocumentation struct {
	marshaller.CoreModel `model:"externalDocumentation"`

	Ref         marshaller.Node[*string] `key:"$ref"`
	Description marshaller.Node[*string] `key:"description"`
	URL         marshaller.Node[*string] `key:"url"`

	Extensions core.Extensions `key:"extensions"`
}

ExternalDocumentation is the backing model for an AsyncAPI External Documentation Object (or a Reference Object to one).

type Items

type Items struct {
	marshaller.CoreModel `model:"items"`

	Schema  *values.EitherValue[Schema, bool]
	Schemas []*values.EitherValue[Schema, bool]
	IsList  bool
}

Items is the backing model for the `items` keyword: a list of schemas (tuple validation) or a single schema.

It is a dedicated type rather than a generic EitherValue because it is part of the recursive Schema definition.

func (*Items) SyncChanges

func (i *Items) SyncChanges(ctx context.Context, model any, valueNode *yaml.Node) (*yaml.Node, error)

func (*Items) Unmarshal

func (i *Items) Unmarshal(ctx context.Context, parentName string, node *yaml.Node) ([]error, error)

type JSONSchema

type JSONSchema = *values.EitherValue[Schema, bool]

JSONSchema is either a Schema Object or a boolean schema.

type MultiFormatSchema

type MultiFormatSchema struct {
	marshaller.CoreModel `model:"multiFormatSchema"`

	SchemaFormat marshaller.Node[string]            `key:"schemaFormat"`
	Schema       marshaller.Node[*SchemaDefinition] `key:"schema" required:"true"`

	Extensions core.Extensions `key:"extensions"`
}

MultiFormatSchema is the backing model for an AsyncAPI Multi Format Schema Object.

func (*MultiFormatSchema) Unmarshal

func (m *MultiFormatSchema) Unmarshal(ctx context.Context, parentName string, node *yaml.Node) ([]error, error)

Unmarshal determines the declared schema format before unmarshalling the object, so the `schema` value is interpreted using that format regardless of key order.

type Schema

type Schema struct {
	marshaller.CoreModel `model:"schema"`

	Ref                  marshaller.Node[*string]                                                `key:"$ref"`
	ID                   marshaller.Node[*string]                                                `key:"$id"`
	Schema               marshaller.Node[*string]                                                `key:"$schema"`
	Comment              marshaller.Node[*string]                                                `key:"$comment"`
	Title                marshaller.Node[*string]                                                `key:"title"`
	Description          marshaller.Node[*string]                                                `key:"description"`
	Default              marshaller.Node[values.Value]                                           `key:"default"`
	ReadOnly             marshaller.Node[*bool]                                                  `key:"readOnly"`
	WriteOnly            marshaller.Node[*bool]                                                  `key:"writeOnly"`
	Examples             marshaller.Node[[]marshaller.Node[values.Value]]                        `key:"examples"`
	MultipleOf           marshaller.Node[*float64]                                               `key:"multipleOf"`
	Maximum              marshaller.Node[*float64]                                               `key:"maximum"`
	ExclusiveMaximum     marshaller.Node[*float64]                                               `key:"exclusiveMaximum"`
	Minimum              marshaller.Node[*float64]                                               `key:"minimum"`
	ExclusiveMinimum     marshaller.Node[*float64]                                               `key:"exclusiveMinimum"`
	MaxLength            marshaller.Node[*int64]                                                 `key:"maxLength"`
	MinLength            marshaller.Node[*int64]                                                 `key:"minLength"`
	Pattern              marshaller.Node[*string]                                                `key:"pattern"`
	AdditionalItems      marshaller.Node[JSONSchema]                                             `key:"additionalItems"`
	Items                marshaller.Node[*Items]                                                 `key:"items"`
	MaxItems             marshaller.Node[*int64]                                                 `key:"maxItems"`
	MinItems             marshaller.Node[*int64]                                                 `key:"minItems"`
	UniqueItems          marshaller.Node[*bool]                                                  `key:"uniqueItems"`
	Contains             marshaller.Node[JSONSchema]                                             `key:"contains"`
	MaxProperties        marshaller.Node[*int64]                                                 `key:"maxProperties"`
	MinProperties        marshaller.Node[*int64]                                                 `key:"minProperties"`
	Required             marshaller.Node[[]marshaller.Node[string]]                              `key:"required"`
	AdditionalProperties marshaller.Node[JSONSchema]                                             `key:"additionalProperties"`
	Definitions          marshaller.Node[*sequencedmap.Map[string, JSONSchema]]                  `key:"definitions"`
	Properties           marshaller.Node[*sequencedmap.Map[string, JSONSchema]]                  `key:"properties"`
	PatternProperties    marshaller.Node[*sequencedmap.Map[string, JSONSchema]]                  `key:"patternProperties"`
	Dependencies         marshaller.Node[*sequencedmap.Map[string, *Dependency]]                 `key:"dependencies"`
	PropertyNames        marshaller.Node[JSONSchema]                                             `key:"propertyNames"`
	Const                marshaller.Node[values.Value]                                           `key:"const"`
	Enum                 marshaller.Node[[]marshaller.Node[values.Value]]                        `key:"enum"`
	Type                 marshaller.Node[*values.EitherValue[[]marshaller.Node[string], string]] `key:"type"`
	Format               marshaller.Node[*string]                                                `key:"format"`
	ContentMediaType     marshaller.Node[*string]                                                `key:"contentMediaType"`
	ContentEncoding      marshaller.Node[*string]                                                `key:"contentEncoding"`
	If                   marshaller.Node[JSONSchema]                                             `key:"if"`
	Then                 marshaller.Node[JSONSchema]                                             `key:"then"`
	Else                 marshaller.Node[JSONSchema]                                             `key:"else"`
	AllOf                marshaller.Node[[]JSONSchema]                                           `key:"allOf"`
	AnyOf                marshaller.Node[[]JSONSchema]                                           `key:"anyOf"`
	OneOf                marshaller.Node[[]JSONSchema]                                           `key:"oneOf"`
	Not                  marshaller.Node[JSONSchema]                                             `key:"not"`
	Discriminator        marshaller.Node[*string]                                                `key:"discriminator"`
	ExternalDocs         marshaller.Node[*ExternalDocumentation]                                 `key:"externalDocs"`
	Deprecated           marshaller.Node[*bool]                                                  `key:"deprecated"`

	Extensions core.Extensions `key:"extensions"`
}

Schema is the backing model for an AsyncAPI Schema Object, a superset of JSON Schema Draft 07. It is also used for schemas explicitly declared as JSON Schema Draft 07.

type SchemaDefinition

type SchemaDefinition struct {
	marshaller.CoreModel `model:"schemaDefinition"`

	Schema *values.EitherValue[Schema, bool]
	Raw    values.Value
}

SchemaDefinition is the backing model for the `schema` value of a Multi Format Schema Object. JSON Schema based formats (the native AsyncAPI Schema Object and JSON Schema Draft 07) are parsed into Schema, all other formats are retained as the raw node in Raw.

func (*SchemaDefinition) SyncChanges

func (d *SchemaDefinition) SyncChanges(ctx context.Context, model any, valueNode *yaml.Node) (*yaml.Node, error)

func (*SchemaDefinition) Unmarshal

func (d *SchemaDefinition) Unmarshal(ctx context.Context, parentName string, node *yaml.Node) ([]error, error)

type SchemaUnion

type SchemaUnion struct {
	marshaller.CoreModel `model:"schemaUnion"`

	Schema      *values.EitherValue[Schema, bool]
	MultiFormat *MultiFormatSchema
}

SchemaUnion is the backing model for the values AsyncAPI accepts wherever a schema is expected: a Schema Object, a boolean schema, a Reference Object or a Multi Format Schema Object.

A mapping containing `$ref` is a Reference Object (unmarshalled into Schema). Otherwise a mapping containing `schemaFormat` is a Multi Format Schema Object. Anything else is a Schema Object.

func (*SchemaUnion) SyncChanges

func (u *SchemaUnion) SyncChanges(ctx context.Context, model any, valueNode *yaml.Node) (*yaml.Node, error)

func (*SchemaUnion) Unmarshal

func (u *SchemaUnion) Unmarshal(ctx context.Context, parentName string, node *yaml.Node) ([]error, error)

Jump to

Keyboard shortcuts

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