schema

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(base ID, obj interface{})

Register adds a new link between a schema ID and object to the global schema registry. This should be called for all GOBL models that will be included inside schema documents or included in an envelope document payload. The name of the object will be determined from the type of the object provided.

func RegisterAll

func RegisterAll(base ID, objs []interface{})

RegisterAll takes an array of objects to register as additional schema using the ID#Add method. Se `RegistereAllIn` for registering schema using anchors.

func RegisterAllIn

func RegisterAllIn(base ID, objs []interface{})

RegisterAllIn takes the base schema ID and adds all the provided objects as anchored entries in the base.

func RegisterIn

func RegisterIn(base ID, obj interface{})

RegisterIn will determine the anchor and add it to the base schema before adding to the global registry.

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase converts the provided string into snake case using dashes. This is useful for Schema IDs and definitions to be coherent with common JSON Schema examples.

func Type

func Type(id ID) reflect.Type

Type provides the type from a matching registered schema.

func Types

func Types() map[reflect.Type]ID

Types provides a complete map of types to schema IDs that have been registered.

Types

type ID

type ID string

ID contains the official schema URL.

const (
	// VERSION for the current version of the schema
	VERSION = "draft-0"
	// GOBL stores the base schema ID for GOBL, including current schema version.
	GOBL ID = "https://gobl.org/" + VERSION
)
const (
	// UnknownID is provided when the schema has not been registered
	UnknownID ID = ""
)

func List

func List() []ID

List of known schema IDs. Mainly used for debugging.

func Lookup

func Lookup(obj interface{}) ID

Lookup finds the objects schema ID, if set

func (ID) Add

func (id ID) Add(path string) ID

Add appends the provided path to the id, and removes any anchor data that might be there.

func (ID) Anchor

func (id ID) Anchor(name string) ID

Anchor either adds or replaces the anchor part of the schema URI.

func (ID) Base

func (id ID) Base() ID

Base removes any anchor information from the schema

func (ID) Interface

func (id ID) Interface() interface{}

Interface attempts to determine the type by looking up the ID in the registered list of schemas, and providing an empty instance.

func (ID) String

func (id ID) String() string

String provides string version of ID

func (ID) Validate

func (id ID) Validate() error

Validate ensures the schema ID looks good.

Jump to

Keyboard shortcuts

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