openapi

package
v1.8.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package openapi is a collection of libraries for fetching the openapi spec from a Kubernetes server and then indexing the type definitions. The openapi spec contains the object model definitions and extensions metadata such as the patchStrategy and patchMergeKey for creating patches.

Index

Constants

View Source
const (
	Integer = "integer"
	Number  = "number"
	String  = "string"
	Boolean = "boolean"
)

Defines openapi types.

View Source
const PrintColumnsKey = "x-kubernetes-print-columns"

Variables

This section is empty.

Functions

func GetPrintColumns

func GetPrintColumns(extensions spec.Extensions) (string, bool)

GetPrintColumns looks for the open API extension for the display columns.

Types

type Array

type Array struct {
	BaseSchema

	SubType Schema
}

Array must have all its element of the same `SubType`.

func (*Array) Accept

func (a *Array) Accept(v SchemaVisitor)

func (*Array) GetName

func (a *Array) GetName() string

type BaseSchema

type BaseSchema struct {
	Description string
	Extensions  map[string]interface{}

	Path Path
}

BaseSchema holds data used by each types of schema.

func (*BaseSchema) GetDescription

func (b *BaseSchema) GetDescription() string

func (*BaseSchema) GetExtensions

func (b *BaseSchema) GetExtensions() map[string]interface{}

func (*BaseSchema) GetPath

func (b *BaseSchema) GetPath() *Path

type CachingOpenAPIClient

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

func NewCachingOpenAPIClient

func NewCachingOpenAPIClient(client discovery.OpenAPISchemaInterface, version, cacheDir string) *CachingOpenAPIClient

NewCachingOpenAPIClient returns a new discovery.OpenAPISchemaInterface that will read the openapi spec from a local cache if it exists, and if not will then fetch an openapi spec using a client. client: used to fetch a new openapi spec if a local cache is not found version: the server version and used as part of the cache file location cacheDir: the directory under which the cache file will be written

func (*CachingOpenAPIClient) OpenAPIData

func (c *CachingOpenAPIClient) OpenAPIData() (Resources, error)

OpenAPIData returns an openapi spec. It will first attempt to read the spec from a local cache If it cannot read a local cache, it will read the file using the client and then write the cache.

type Definitions

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

Definitions is an implementation of `Resources`. It looks for resources in an openapi Schema.

func (*Definitions) LookupResource

func (d *Definitions) LookupResource(gvk schema.GroupVersionKind) Schema

LookupResource is public through the interface of Resources. It returns a visitable schema from the given group-version-kind.

func (*Definitions) ParseSchema

func (d *Definitions) ParseSchema(s *openapi_v2.Schema, path *Path) (Schema, error)

ParseSchema creates a walkable Schema from an openapi schema. While this function is public, it doesn't leak through the interface.

type Getter

type Getter interface {
	// OpenAPIData returns the parsed OpenAPIData
	Get() (Resources, error)
}

Getter is an interface for fetching openapi specs and parsing them into an Resources struct

func NewOpenAPIGetter

func NewOpenAPIGetter(cacheDir, serverVersion string, openAPIClient discovery.OpenAPISchemaInterface) Getter

NewOpenAPIGetter returns an object to return OpenAPIDatas which either read from a local file cache or read from a server, and then stored in memory for subsequent invocations

type Kind

type Kind struct {
	BaseSchema

	// Lists names of required fields.
	RequiredFields []string
	// Maps field names to types.
	Fields map[string]Schema
}

Kind is a complex object. It can have multiple different subtypes for each field, as defined in the `Fields` field. Mandatory fields are listed in `RequiredFields`. The key of the object is always of type `string`.

func (*Kind) Accept

func (k *Kind) Accept(v SchemaVisitor)

func (*Kind) GetName

func (k *Kind) GetName() string

type Map

type Map struct {
	BaseSchema

	SubType Schema
}

Map is an object who values must all be of the same `SubType`. The key of the object is always of type `string`.

func (*Map) Accept

func (m *Map) Accept(v SchemaVisitor)

func (*Map) GetName

func (m *Map) GetName() string

type Path

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

Path helps us keep track of type paths

func NewPath

func NewPath(key string) Path

func (*Path) ArrayPath

func (p *Path) ArrayPath(i int) Path

ArrayPath appends an array index and creates a new path

func (*Path) FieldPath

func (p *Path) FieldPath(field string) Path

FieldPath appends a field name and creates a new path

func (*Path) Get

func (p *Path) Get() []string

func (*Path) Len

func (p *Path) Len() int

func (*Path) String

func (p *Path) String() string

type Primitive

type Primitive struct {
	BaseSchema

	// Type of a primitive must be one of: integer, number, string, boolean.
	Type   string
	Format string
}

Primitive is a literal. There can be multiple types of primitives, and this subtype can be visited through the `subType` field.

func (*Primitive) Accept

func (p *Primitive) Accept(v SchemaVisitor)

func (*Primitive) GetName

func (p *Primitive) GetName() string

type Reference

type Reference struct {
	Reference string
	// contains filtered or unexported fields
}

SchemaReference doesn't match a specific type. It's mostly a pass-through type.

func (*Reference) Accept

func (r *Reference) Accept(s SchemaVisitor)

func (*Reference) GetDescription

func (r *Reference) GetDescription() string

func (*Reference) GetExtensions

func (r *Reference) GetExtensions() map[string]interface{}

func (*Reference) GetName

func (r *Reference) GetName() string

func (*Reference) GetPath

func (*Reference) GetPath() *Path

func (*Reference) GetSubSchema

func (r *Reference) GetSubSchema() Schema

type Resources

type Resources interface {
	LookupResource(gvk schema.GroupVersionKind) Schema
}

Resources interface describe a resources provider, that can give you resource based on group-version-kind.

func NewOpenAPIData

func NewOpenAPIData(doc *openapi_v2.Document) (Resources, error)

NewOpenAPIData creates a new `Resources` out of the openapi document.

type Schema

type Schema interface {
	// Giving a visitor here will let you visit the actual type.
	Accept(SchemaVisitor)

	// Pretty print the name of the type.
	GetName() string
	// Describes how to access this field.
	GetPath() *Path
	// Describes the field.
	GetDescription() string
	// Returns type extensions.
	GetExtensions() map[string]interface{}
}

Schema is the base definition of an openapi type.

type SchemaVisitor

type SchemaVisitor interface {
	VisitArray(*Array)
	VisitMap(*Map)
	VisitPrimitive(*Primitive)
	VisitKind(*Kind)
}

SchemaVisitor is an interface that you need to implement if you want to "visit" an openapi schema. A dispatch on the Schema type will call the appropriate function based on its actual type: - Array is a list of one and only one given subtype - Map is a map of string to one and only one given subtype - Primitive can be string, integer, number and boolean. - Kind is an object with specific fields mapping to specific types.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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