schema

package
v0.51.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Package schema provides a simple way to register and lookup schemas.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Insert added in v0.26.1

func Insert(id ID, data []byte) ([]byte, error)

Insert adds the provided schema ID to the JSON data provided.

func Register

func Register(base ID, objs ...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 RegisterIn

func RegisterIn(base ID, objs ...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 Extract added in v0.26.1

func Extract(data []byte) (ID, error)

Extract attempts to Unmarshal the provided JSON document in order to extract the payload's Schema 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