Documentation ¶
Index ¶
- Constants
- func RegisterSchemas(service *service.Service, schemaRootDir string) ([]string, error)
- type HRef
- type Link
- type Reference
- type Schema
- type SchemaJSON
- type SchemaSet
- func (ss *SchemaSet) AddSchema(b []byte) (string, error)
- func (ss *SchemaSet) ConstantStringType(id, name string) (string, error)
- func (ss *SchemaSet) PropertyType(id, name string) (*SchemaJSON, error)
- func (ss *SchemaSet) SimpleProperties(id string) (SimpleProperties, error)
- func (ss *SchemaSet) TypeName(id string) (namespace string, name string, err error)
- type SimpleProperties
Constants ¶
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 ¶
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 ¶
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 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 ¶
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 ¶
NewSchemaSetFromADir create a SchemaSet from all schema files under a directory and its descendant directories.
func NewSchemaSetFromFiles ¶
NewSchemaSetFromFiles create a SchemaSet from an arry of files. These files can refer each other in their definitions.
func (*SchemaSet) AddSchema ¶
AddSchema adds a new schema into the set. It returns the schema ID or an error.
func (*SchemaSet) ConstantStringType ¶
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.
type SimpleProperties ¶
SimpleProperties are properties of type integer, double and string. The map is from property name to its type.