json

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const JSON = "https://json.org#"

JSON namespace

View Source
const X_LS = "x-ls"

Variables

View Source
var (
	StringTypeTerm  = ls.NewTerm(JSON, "string").SetComposition(ls.OverrideComposition).SetTags(ls.SchemaElementTag).Register()
	NumberTypeTerm  = ls.NewTerm(JSON, "number").SetComposition(ls.OverrideComposition).SetTags(ls.SchemaElementTag).Register()
	IntegerTypeTerm = ls.NewTerm(JSON, "integer").SetComposition(ls.OverrideComposition).SetTags(ls.SchemaElementTag).Register()
	BooleanTypeTerm = ls.NewTerm(JSON, "boolean").SetComposition(ls.OverrideComposition).SetTags(ls.SchemaElementTag).Register()
	ObjectTypeTerm  = ls.NewTerm(JSON, "object").SetComposition(ls.OverrideComposition).SetTags(ls.SchemaElementTag).Register()
	ArrayTypeTerm   = ls.NewTerm(JSON, "array").SetComposition(ls.OverrideComposition).SetTags(ls.SchemaElementTag).Register()
)

JSON related vocabulry

View Source
var PolyHintBlock = func(*jsonom.KeyValue) {}

Functions

func ComposeSchema

func ComposeSchema(ctx *ls.Context, name string, overlays []string, loader func(*ls.Context, string) (io.ReadCloser, error)) (jsonom.Node, error)

ComposeSchema composes a JSON schema with zero or more overlays. The return is a JSON schema. While composing, matching objects are merged, matching arrays and values are overridden by the overlays. Overlays are composed in the order given.

func DefaultBuildNodeKeyFunc

func DefaultBuildNodeKeyFunc(node *lpg.Node) (string, bool, error)

DefaultBuildNodeKeyFunc returns the attribute name term property from the node if it exists. If not, it looks at the attributeName of the node reached by instanceOf edge. If none found it return false

func Export

func Export(node *lpg.Node, options ExportOptions) (jsonom.Node, error)

Export the document subtree to the target. The returned result is OM, which respects element ordering

func GetBuildNodeKeyBySchemaNodeFunc

func GetBuildNodeKeyBySchemaNodeFunc(f func(schemaNode, docNode *lpg.Node) (string, bool, error)) func(*lpg.Node) (string, bool, error)

GetBuildNodeKeyBySchemaNodeFunc returns a function that gets the schema node and the doc node. If the doc node does not have a schema node, it is not exported. The function `f` should decide what key to use

func IngestBytes

func IngestBytes(ctx *ls.Context, baseID string, input []byte, parser Parser, builder ls.GraphBuilder, ingester *ls.Ingester) (*lpg.Node, error)

func IngestStream

func IngestStream(ctx *ls.Context, baseID string, input io.Reader, parser Parser, builder ls.GraphBuilder, ingester *ls.Ingester) (*lpg.Node, error)

Types

type CompiledEntity

type CompiledEntity struct {
	Entity
	Schema *jsonschema.Schema
}

CompiledEntity contains the JSON schema for the entity

func CompileEntities

func CompileEntities(entities ...Entity) ([]CompiledEntity, error)

CompileEntities compiles given entities

func CompileEntitiesWith

func CompileEntitiesWith(compiler *jsonschema.Compiler, entities ...Entity) ([]CompiledEntity, error)

CompileEntitiesWith compiles all entities as a single json schema unit using the given compiler

type Entity

type Entity struct {
	// Reference to the schema. This includes the full reference to the
	// JSON schema, and the reference in that schema that defines the
	// entity. For example, this can be
	// https://somenamespace/myschema.json#/definitions/Object
	Ref string `json:"ref" bson:"ref" yaml:"ref"`
	// ID of the layer that will be generated
	LayerID string `json:"layerId,omitempty" bson:"layerId,omitempty" yaml:"layerId,omitempty"`
	// The ID of the root node. If empty, ValueType is used for the root node id
	RootNodeID string `json:"rootNodeId,omitempty" bson:"rootNodeId,omitempty" yaml:"rootNodeId,omitempty"`
	// ValueType is the value type of the schema, that is, the entity type defined with this schema
	ValueType string `json:"valueType" bson:"valueType" yaml:"valueType"`

	// If specified, all attribute will be imported in this
	// namespace. If not, valueType, if that too is empty, rootNodeID
	AttrNamespace string `json:"attrNamespace" bson:"attrNamespace" yaml:"attrNamespace"`
}

Entity defines an entity as a layered schema with respect to a JSON schema

func FindEntityByRef

func FindEntityByRef(entities []Entity, ref string) *Entity

FindEntityByRef finds the entity by ref value

func FindEntityByValueType

func FindEntityByValueType(entities []Entity, valueType string) *Entity

FindEntityByValueType finds the entity by ValueType value

func (Entity) GetLayerRoot

func (e Entity) GetLayerRoot() string

type EntityLayer

type EntityLayer struct {
	Entity CompiledEntity

	Layer *ls.Layer `json:"-"`
}

EntityLayer contains the layer for the entity

func BuildEntityGraph

func BuildEntityGraph(targetGraph *lpg.Graph, typeTerm string, linkRefsBy LinkRefsBy, entities ...CompiledEntity) ([]EntityLayer, error)

BuildEntityGraph imports JSON schemas or overlays

A JSON schema may include many object definitions. This import algorithm creates a layer for each entity in the given target graph.

typeTerm should be either ls.SchemaTerm or ls.OverlayTerm

type ErrCyclicSchema

type ErrCyclicSchema struct {
	Loop []*jsonschema.Schema
}

func (ErrCyclicSchema) Error

func (e ErrCyclicSchema) Error() string

type ErrInvalidBooleanValue

type ErrInvalidBooleanValue struct {
	NodeID string
	Value  string
}

func (ErrInvalidBooleanValue) Error

func (e ErrInvalidBooleanValue) Error() string

type ErrValueExpected

type ErrValueExpected struct {
	NodeID string
}

func (ErrValueExpected) Error

func (e ErrValueExpected) Error() string

type ExportOptions

type ExportOptions struct {
	// BuildNodeKeyFunc builds a node key from the node
	BuildNodeKeyFunc func(*lpg.Node) (string, bool, error)

	// If ExportTypeProperty is set, exports "@type" properties that
	// have non-LS related types
	ExportTypeProperty bool
}

ExportOptions are used to produce the output from the document

func (ExportOptions) BuildNodeKey

func (options ExportOptions) BuildNodeKey(node *lpg.Node) (string, bool, error)

type LinkRefsBy

type LinkRefsBy int

LinkRefsBy is an enumeration that specifies how the links for the imported schema should be written

const (
	// Remote references are schema references (entity.Ref)
	LinkRefsBySchemaRef LinkRefsBy = iota
	// Remote references are layer ids (entity.LayerID)
	LinkRefsByLayerID
	// Remote references are value types (entity.ValueType)
	LinkRefsByValueType
)

type ParsedDocNode

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

func (ParsedDocNode) GetAttributeIndex

func (i ParsedDocNode) GetAttributeIndex() int

func (ParsedDocNode) GetAttributeName

func (i ParsedDocNode) GetAttributeName() string

func (ParsedDocNode) GetChildren

func (i ParsedDocNode) GetChildren() []ls.ParsedDocNode

func (ParsedDocNode) GetID

func (i ParsedDocNode) GetID() string

func (ParsedDocNode) GetProperties

func (i ParsedDocNode) GetProperties() map[string]interface{}

func (ParsedDocNode) GetSchemaNode

func (i ParsedDocNode) GetSchemaNode() *lpg.Node

func (ParsedDocNode) GetTypeTerm

func (i ParsedDocNode) GetTypeTerm() string

func (ParsedDocNode) GetValue

func (i ParsedDocNode) GetValue() string

func (ParsedDocNode) GetValueTypes

func (i ParsedDocNode) GetValueTypes() []string

type Parser

type Parser struct {
	OnlySchemaAttributes bool
	IngestNullValues     bool
	Layer                *ls.Layer
	// contains filtered or unexported fields
}

func (*Parser) ParseDoc

func (ing *Parser) ParseDoc(context *ls.Context, baseID string, input jsonom.Node) (*ParsedDocNode, error)

Directories

Path Synopsis
This is copied from https://github.com/santhosh-tekuri/jsonschema/
This is copied from https://github.com/santhosh-tekuri/jsonschema/

Jump to

Keyboard shortcuts

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