notes

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT, BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package notes defines a type that holds information passed between keywords during schema validation. This permits validation of one keyword to depend on information gathered while validating another keyword.

For example, this supports keywords like "unevaluatedItems", that impose requirements only on fields that were not already validated by other keywords like "items" or "contains".

This package is visible to support people who want to define their JSON schema definitions. People who are only interested in validating JSON objects using standard JSON schemas do not need to use this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendNote

func AppendNote[E any](n *Notes, name string, val ...E)

AppendNote appends values to a note. This is a function, not a method, so that it can be generic. This expects any existing note to have type []E, and panics if it does not.

Types

type Notes

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

Notes is a set of notes. Each note has a name and a value. The name should normally be the name of a JSON schema keyword. The value may be anything; it is normally a bool, an int, or a slice of some elements.

The zero value of Notes is directly usable. Notes may not be used concurrently by multiple goroutines.

Notes are not annotations as defined by the JSON schema definition. Currently this module does not support JSON schema annotations. Notes could evolve into annotations if that seems desirable; we would need a way to save them and make them available after validation, and we would need to record the instance location and the schema location.

func (*Notes) AddNotes

func (n *Notes) AddNotes(ns ...Notes)

AddNotes adds all notes in the elements of ns to n. Scalar values in added notes replace those in n. Slices in added notes are appended to slices in n; if the element types differ, or if the value in n is not a slice, AddNotes will panic. Names in n that do not appear in added notes are unchanged.

func (*Notes) Clear

func (n *Notes) Clear()

Clear clears all current notes.

func (*Notes) Get

func (n *Notes) Get(name string) (any, bool)

Get retrieves a note, including reporting whether it exists.

func (*Notes) IsEmpty

func (n *Notes) IsEmpty() bool

IsEmpty reports whether there are no notes.

func (*Notes) Set

func (n *Notes) Set(name string, val any)

Set adds a note. If there is an existing note with the same name, the old value is replaced with the new one.

func (Notes) String

func (n Notes) String() string

String returns a printable Notes.

Jump to

Keyboard shortcuts

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