schema

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(input map[string]interface{}, obj interface{}) error

Decode decodes a map into an object

func DecodeString

func DecodeString(input string, obj interface{}) error

DecodeString decodes a string into an object

func Encode added in v0.1.3

func Encode(obj interface{}) (map[string]interface{}, error)

func GetKey added in v0.1.2

func GetKey(input map[string]interface{}, key string) (interface{}, bool)

func MapToSpec added in v0.1.3

func MapToSpec(m map[string]interface{}) *proto.Spec

func ReadByTag added in v0.1.2

func ReadByTag(obj interface{}, target string) []string

func ValidateRequired added in v0.1.2

func ValidateRequired(input map[string]interface{}, obj interface{}) error

Types

type Array

type Array struct {
	Elem Type
}

Array is an array of objects

func (*Array) Kind added in v0.1.3

func (a *Array) Kind() reflect.Type

func (*Array) Type

func (a *Array) Type() string

Type implements the Type interface

type Diff added in v0.1.3

type Diff map[string]DiffField

type DiffField added in v0.1.3

type DiffField struct {
	Old interface{}
	New interface{}
}

type Field

type Field struct {
	Type Type

	// Computed describes whether the field is a status
	Computed bool

	// Required specifies if the field is required
	Required bool

	// ForceNew describes whether a change in the field requires delete the old one
	ForceNew bool

	// Default value for the field
	Default string
}

Field is a field in a record

type Map

type Map struct {
	Elem Type
}

Map is a map<string, interface{}> without specific types

func (*Map) Kind added in v0.1.3

func (m *Map) Kind() reflect.Type

func (*Map) Type

func (m *Map) Type() string

Type implements the Type interface

type Record

type Record struct {
	Fields map[string]*Field
}

Record is an object with several values

func (*Record) Kind added in v0.1.3

func (r *Record) Kind() reflect.Type

func (*Record) OpenAPIV3

func (s *Record) OpenAPIV3() interface{}

OpenAPIV3 returns the OpenApi v3 representation of the schema

func (*Record) OpenAPIV3JSON

func (s *Record) OpenAPIV3JSON() ([]byte, error)

OpenAPIV3JSON creates the OpenAPIv3 spec for the Schema in JSON format

func (*Record) OpenAPIV3Yaml

func (s *Record) OpenAPIV3Yaml() ([]byte, error)

OpenAPIV3Yaml creates the OpenAPIv3 spec for the Schema in YAML format

func (*Record) Type

func (r *Record) Type() string

Type implements the Type interface

type ResourceData added in v0.1.3

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

func NewResourceData added in v0.1.3

func NewResourceData(sch *Schema2, data *proto.Spec) *ResourceData

func (*ResourceData) Decode added in v0.1.3

func (r *ResourceData) Decode(obj interface{}) error

func (*ResourceData) Get added in v0.1.3

func (r *ResourceData) Get(k string) interface{}

func (*ResourceData) GetOK added in v0.1.3

func (r *ResourceData) GetOK(k string) (interface{}, bool)

type ScalarType

type ScalarType int

ScalarType is a scalar type

const (
	// TypeString is a string type
	TypeString ScalarType = iota

	// TypeInt is a int type
	TypeInt

	// TypeBool is a bool type
	TypeBool
)

func (ScalarType) Kind added in v0.1.3

func (s ScalarType) Kind() reflect.Type

func (ScalarType) String

func (i ScalarType) String() string

func (ScalarType) Type

func (s ScalarType) Type() string

Type implements the Type interface

type Schema

type Schema struct {
	Spec   *Record
	Status *Record
}

Schema is an OpenAPIv3 schema of a resource

func GenerateSchema

func GenerateSchema(s interface{}) (*Schema, error)

GenerateSchema generates an OpenAPIv3 schema

type Schema2 added in v0.1.3

type Schema2 struct {
	Spec *Record
}

func (*Schema2) Diff added in v0.1.3

func (s *Schema2) Diff(i, j *proto.Spec) Diff

func (*Schema2) Get added in v0.1.3

func (s *Schema2) Get(k string) (*Field, error)

func (*Schema2) Validate added in v0.1.3

func (s *Schema2) Validate(spec *proto.Spec) error

type Type

type Type interface {
	Type() string
	Kind() reflect.Type
}

Type describes a valid type for the schema

Jump to

Keyboard shortcuts

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