kitebuilder

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMapString

func GetMapString(v map[string]interface{}, key string) (string, error)

func PrintAPIs

func PrintAPIs(apis []API)

func UnmarshalJSONString

func UnmarshalJSONString(v map[string]interface{}, key string, dest interface{}) error

Types

type API

type API struct {
	ID                  string                        `json:"ksuid,omitempty"`
	URL                 string                        `json:"url"`
	SecurityDefinitions map[string]SecurityDefinition `json:"securityDefinitions"`
	Paths               map[Path]Operations           `json:"paths"`
}

func LoadJSONBytes

func LoadJSONBytes(buf []byte) ([]API, error)

LoadJSONBytes will load the schema from the provided bytes

func LoadJSONFile

func LoadJSONFile(filename string) (schema []API, err error)

LoadJSONFile will load the json schema from the specified file

func LoadJSONReader

func LoadJSONReader(r io.Reader) (schema []API, err error)

func LoadJSONString

func LoadJSONString(buf string) ([]API, error)

LoadString will load the schema from the provided string

func SlowLoadJSONBytes

func SlowLoadJSONBytes(buf []byte) ([]API, error)

SlowLoadJSONBytes will unmarshal the buf into an interface{} and attempt to unmarshal each individual API while printing errors about the object This is a painful manual process when the kitebuilder spec was non-finalised

func SlowLoadJSONFile

func SlowLoadJSONFile(filename string) (schema []API, err error)

SlowLoadJSONFile will load the json schema from the specified file

type ContentType

type ContentType string

type Operation

type Operation struct {
	Description string        `json:"description,omitempty"`
	OperationID string        `json:"operationId,omitempty"`
	Parameters  []Parameter   `json:"parameter,omitempty"`
	Consumes    []ContentType `json:"consume,omitempty"`
	Produces    []ContentType `json:"produce,omitempty"`
}

type OperationTypes

type OperationTypes string
var (
	GET     OperationTypes = "get"
	DELETE  OperationTypes = "delete"
	HEAD    OperationTypes = "head"
	OPTIONS OperationTypes = "options"
	PATCH   OperationTypes = "patch"
	POST    OperationTypes = "post"
	PUT     OperationTypes = "put"
)

type Operations

type Operations map[OperationTypes]Operation

Operations is a map of the verb to the operation data. technically we can have "parameters" here, but then we have dual types for this one object which is fucked

type Parameter

type Parameter struct {
	Description string      `json:"description,omitempty"`
	In          string      `json:"in,omitempty"`
	Name        string      `json:"name,omitempty"`
	Required    interface{} `json:"required,omitempty"`

	Schema *Schema `json:"schema,omitempty"` // if in == "body"

	// if in != "body"
	Type            string      `json:"type,omitempty"`
	AllowEmptyValue bool        `json:"allowEmptyValue,omitempty"`
	Pattern         string      `json:"pattern,omitempty"`
	Format          string      `json:"format,omitempty"`
	Example         interface{} `json:"example,omitempty"`

	Minimum   float64 `json:"minimum,omitempty"`
	Maximum   float64 `json:"maximum,omitempty"`
	MaxLength uint64  `json:"maxLength,omitempty"`
	MaxItems  uint64  `json:"maxItems,omitempty"`
	MinLength uint64  `json:"minLength,omitempty"`
	MinItems  uint64  `json:"minItems,omitempty"`

	Enum    []interface{} `json:"enum,omitempty"` // can be [1,2,3] ["a", "b", "c"]
	Default interface{}   `json:"default,omitempty"`

	Items *Schema `json:"items,omitempty"`
}

func (Parameter) GetAdditionalProperties

func (p Parameter) GetAdditionalProperties() *Schema

func (Parameter) GetAllOf

func (p Parameter) GetAllOf() []Schema

func (Parameter) GetDefault

func (p Parameter) GetDefault() interface{}

func (Parameter) GetExample

func (p Parameter) GetExample() interface{}

func (Parameter) GetFormat

func (p Parameter) GetFormat() string

func (Parameter) GetIn

func (p Parameter) GetIn() string

func (Parameter) GetItems

func (p Parameter) GetItems() *Schema

func (Parameter) GetMaximum

func (p Parameter) GetMaximum() float64

func (Parameter) GetMinimum

func (p Parameter) GetMinimum() float64

func (Parameter) GetName

func (p Parameter) GetName() string

func (Parameter) GetPattern

func (p Parameter) GetPattern() string

func (Parameter) GetProperties

func (p Parameter) GetProperties() map[string]Schema

func (Parameter) GetSchema

func (p Parameter) GetSchema() *Schema

func (Parameter) GetType

func (p Parameter) GetType() string

type Path

type Path string

type Schema

type Schema struct {
	Properties       map[string]Schema `json:"properties,omitempty"`
	Type             string            `json:"type,omitempty" yaml:"type,omitempty"`
	Title            string            `json:"title,omitempty" yaml:"title,omitempty"`
	Format           string            `json:"format,omitempty" yaml:"format,omitempty"`
	Description      string            `json:"description,omitempty" yaml:"description,omitempty"`
	Enum             []interface{}     `json:"enum,omitempty" yaml:"enum,omitempty"`
	Default          interface{}       `json:"default,omitempty" yaml:"default,omitempty"`
	Example          interface{}       `json:"example,omitempty" yaml:"example,omitempty"`
	Name             string            `json:"name,omitempty"`
	CollectionFormat string            `json:"collectionFormat,omitempty"`

	// Array-related, here for struct compactness
	UniqueItems bool `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"`
	// Number-related, here for struct compactness
	ExclusiveMin bool `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"`
	ExclusiveMax bool `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
	// Properties
	Nullable bool `json:"nullable,omitempty" yaml:"nullable,omitempty"`
	ReadOnly bool `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
	// can be either []string or bool. We don't actually pay attention to this field
	WriteOnly       bool        `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty"`
	AllowEmptyValue bool        `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"`
	XML             interface{} `json:"xml,omitempty" yaml:"xml,omitempty"`
	Deprecated      bool        `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`

	// Number
	Min        float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	Max        float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	MultipleOf float64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`

	// String
	MinLength uint64 `json:"minLength,omitempty" yaml:"minLength,omitempty"`
	MaxLength uint64 `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
	Pattern   string `json:"pattern,omitempty" yaml:"pattern,omitempty"`

	// Array
	MinItems             uint64  `json:"minItems,omitempty" yaml:"minItems,omitempty"`
	MaxItems             uint64  `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
	Items                *Schema `json:"items,omitempty" yaml:"items,omitempty"`
	AdditionalProperties *Schema `json:"additional_properties,omitempty"`

	// Object
	Required interface{} `json:"required,omitempty" yaml:"required,omitempty"`

	MinProps uint64   `json:"minProperties,omitempty" yaml:"minProperties,omitempty"`
	MaxProps uint64   `json:"maxProperties,omitempty" yaml:"maxProperties,omitempty"`
	AllOf    []Schema `json:"allOf,omitempty"`
}

func (Schema) GetAdditionalProperties

func (s Schema) GetAdditionalProperties() *Schema

func (Schema) GetAllOf

func (s Schema) GetAllOf() []Schema

func (Schema) GetDefault

func (s Schema) GetDefault() interface{}

func (Schema) GetExample

func (s Schema) GetExample() interface{}

func (Schema) GetFormat

func (s Schema) GetFormat() string

func (Schema) GetIn

func (s Schema) GetIn() string

func (Schema) GetItems

func (s Schema) GetItems() *Schema

func (Schema) GetMaximum

func (s Schema) GetMaximum() float64

func (Schema) GetMinimum

func (s Schema) GetMinimum() float64

func (Schema) GetName

func (s Schema) GetName() string

func (Schema) GetPattern

func (s Schema) GetPattern() string

func (Schema) GetProperties

func (s Schema) GetProperties() map[string]Schema

func (Schema) GetSchema

func (s Schema) GetSchema() *Schema

func (Schema) GetType

func (s Schema) GetType() string

func (Schema) IsZero

func (s Schema) IsZero() bool

type SecurityDefinition

type SecurityDefinition struct {
	In   string `json:"in"`
	Name string `json:"name"`
	Type string `json:"type"`
}

type Typer

type Typer interface {
	GetType() string
	GetName() string
	GetExample() interface{}
	GetFormat() string
	GetPattern() string
	GetDefault() interface{}

	GetIn() string // exclusive to parameter, so a schema should return empty

	GetMinimum() float64
	GetMaximum() float64

	GetProperties() map[string]Schema
	GetAdditionalProperties() *Schema
	GetSchema() *Schema
	GetItems() *Schema
	GetAllOf() []Schema
}

Typer provides an interface that makes parameter and schema generic. It provides a list of fields that allow both to be accessed as the same kind of object when reconstructing proute crumbs It doesnt totally fit over both, but its close/good enough with nillable types for determining whats possible and whats not possible

Jump to

Keyboard shortcuts

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