schemaparser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IntegerType represents JSON schema integer type
	IntegerType = "integer"
	// StringType represents JSON schema string type
	StringType = "string"
	// NumberType represents JSON schema number type
	NumberType = "number"
	// BooleanType represents JSON schema boolean type
	BooleanType = "boolean"
	// ArrayType represents JSON schema array type
	ArrayType = "array"
	// ObjectType represents JSON schema object type
	ObjectType = "object"
)

Variables

This section is empty.

Functions

func RegisterSchemas

func RegisterSchemas(service *service.Service, schemaRootDir string) ([]string, error)

RegisterSchemas registers all predefined schema into the metadata service and returns a list of registered type names. TODO(zhenghuiwang): adds the schemas as annotations into MLMD once it supports type annotations.

Types

type HRef

type HRef struct {
	Order   []string
	Schemas map[string]*SchemaJSON
	// contains filtered or unexported fields
}

HRef represents a Link href.

type Link struct {
	Title        string      `json:"title,omitempty"`
	Description  string      `json:"description,omitempty"`
	HRef         *HRef       `json:"href,omitempty"`
	Rel          string      `json:"rel,omitempty"`
	Method       string      `json:"method,omitempty"`
	Schema       *SchemaJSON `json:"schema,omitempty"`
	TargetSchema *SchemaJSON `json:"targetSchema,omitempty"`
	MediaType    string      `json:"mediaType,omitempty"`
	EncType      string      `json:"encType,omitempty"`
}

Link represents a Link description.

type Reference

type Reference string

Reference represents a JSON schema pointer.

type Schema

type Schema struct {
	// JSON is the Go struct representation of the schema itself.
	JSON *SchemaJSON
	// Validator is a compiled schema for validating JSON data.
	Validator *gojsonschema.Schema
}

Schema represent a JSON schema.

type SchemaJSON

type SchemaJSON struct {
	ID          string `json:"$id,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Version     string `json:"version,omitempty"`

	Default  interface{} `json:"default,omitempty"`
	ReadOnly bool        `json:"readOnly,omitempty"`
	Example  interface{} `json:"example,omitempty"`
	Format   string      `json:"format,omitempty"`

	Type interface{} `json:"type,omitempty"`

	Ref    *Reference `json:"$ref,omitempty"`
	Schema *Reference `json:"$schema,omitempty"`

	Definitions map[string]*SchemaJSON `json:"definitions,omitempty"`

	// Numbers
	MultipleOf       float64 `json:"multipleOf,omitempty"`
	Maximum          float64 `json:"maximum,omitempty"`
	ExclusiveMaximum bool    `json:"exclusiveMaximum,omitempty"`
	Minimum          float64 `json:"minimum,omitempty"`
	ExclusiveMinimum bool    `json:"exclusiveMinimum,omitempty"`

	// Strings
	MinLength int    `json:"minLength,omitempty"`
	MaxLength int    `json:"maxLength,omitempty"`
	Pattern   string `json:"pattern,omitempty"`

	// Objects
	MinProperties        int                    `json:"minProperties,omitempty"`
	MaxProperties        int                    `json:"maxProperties,omitempty"`
	Required             []string               `json:"required,omitempty"`
	Properties           map[string]*SchemaJSON `json:"properties,omitempty"`
	Dependencies         map[string]interface{} `json:"dependencies,omitempty"`
	AdditionalProperties interface{}            `json:"additionalProperties,omitempty"`
	PatternProperties    map[string]*SchemaJSON `json:"patternProperties,omitempty"`

	// Arrays
	Items           *SchemaJSON `json:"items,omitempty"`
	MinItems        int         `json:"minItems,omitempty"`
	MaxItems        int         `json:"maxItems,omitempty"`
	UniqueItems     bool        `json:"uniqueItems,omitempty"`
	AdditionalItems interface{} `json:"additionalItems,omitempty"`

	// All
	Enum     []string `json:"enum,omitempty"`
	Constant string   `json:"constant,omitempty"`

	// Schemas
	OneOf []SchemaJSON `json:"oneOf,omitempty"`
	AnyOf []SchemaJSON `json:"anyOf,omitempty"`
	AllOf []SchemaJSON `json:"allOf,omitempty"`
	Not   *SchemaJSON  `json:"not,omitempty"`

	// Links
	Links []*Link `json:"links,omitempty"`
}

SchemaJSON is a Go struct representation of a JSON schema.

func NewSchemaJSON

func NewSchemaJSON(b []byte) (*SchemaJSON, error)

NewSchemaJSON cast bytes into *SchemaJSON.

func (*SchemaJSON) GetType

func (sj *SchemaJSON) GetType() string

GetType return the type defined in this schema

func (*SchemaJSON) IsSimpleType

func (sj *SchemaJSON) IsSimpleType() bool

IsSimpleType returns if a type is of a simple type, i.e. string, integer or number.

type SchemaSet

type SchemaSet struct {
	Schemas map[string]*Schema
	// contains filtered or unexported fields
}

SchemaSet maps schema $id to its Schema. SchemaSet is inclusive, i.e. all references of schemas in this schema set must also be included in the set.

func NewSchemaSetFromADir

func NewSchemaSetFromADir(dir string) (*SchemaSet, error)

NewSchemaSetFromADir create a SchemaSet from all schema files under a directory and its descendant directories.

func NewSchemaSetFromFiles

func NewSchemaSetFromFiles(files []string) (*SchemaSet, error)

NewSchemaSetFromFiles create a SchemaSet from an arry of files. These files can refer each other in their definitions.

func (*SchemaSet) AddSchema

func (ss *SchemaSet) AddSchema(b []byte) (string, error)

AddSchema adds a new schema into the set. It returns the schema ID or an error.

func (*SchemaSet) ConstantStringType

func (ss *SchemaSet) ConstantStringType(id, name string) (string, error)

ConstantStringType returns the constant value of a string type.

func (*SchemaSet) PropertyType

func (ss *SchemaSet) PropertyType(id, name string) (*SchemaJSON, error)

PropertyType returns the type definition of property with given name in the schema of id.

func (*SchemaSet) SimpleProperties

func (ss *SchemaSet) SimpleProperties(id string) (SimpleProperties, error)

SimpleProperties returns a map of simple properties for a schema with given id.

func (*SchemaSet) TypeName

func (ss *SchemaSet) TypeName(id string) (namespace string, name string, err error)

TypeName extract the {namespace}/{version} as type namepace and {kind} as type name, where {namespace}, {kind}, and {version} are from constant string properties defined in JSON schema.

type SimpleProperties

type SimpleProperties map[string]string

SimpleProperties are properties of type integer, double and string. The map is from property name to its type.

Jump to

Keyboard shortcuts

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