openapi

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2019 License: Apache-2.0 Imports: 14 Imported by: 31

Documentation

Overview

Package openapi provides functionality for mapping CUE to and from OpenAPI v3.0.0.

It currently handles OpenAPI Schema components only.

See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Gen

func Gen(inst *cue.Instance, c *Config) ([]byte, error)

Gen generates the set OpenAPI schema for all top-level types of the given instance.

Types

type Config

type Config = Generator

Config is now Generator

type Generator added in v0.0.4

type Generator struct {
	// Info specifies the info section of the OpenAPI document. To be a valid
	// OpenAPI document, it must include at least the title and version fields.
	Info OrderedMap

	// ReferenceFunc allows users to specify an alternative representation
	// for references. An empty string tells the generator to expand the type
	// in place and, if applicable, not generate a schema for that entity.
	ReferenceFunc func(inst *cue.Instance, path []string) string

	// DescriptionFunc allows rewriting a description associated with a certain
	// field. A typical implementation compiles the description from the
	// comments obtains from the Doc method. No description field is added if
	// the empty string is returned.
	DescriptionFunc func(v cue.Value) string

	// SelfContained causes all non-expanded external references to be included
	// in this document.
	SelfContained bool

	// FieldFilter defines a regular expression of all fields to omit from the
	// output. It is only allowed to filter fields that add additional
	// constraints. Fields that indicate basic types cannot be removed. It is
	// an error for such fields to be excluded by this filter.
	// Fields are qualified by their Object type. For instance, the
	// minimum field of the schema object is qualified as Schema/minimum.
	FieldFilter string

	// ExpandReferences replaces references with actual objects when generating
	// OpenAPI Schema. It is an error for an CUE value to refer to itself
	// if this option is used.
	ExpandReferences bool
}

A Generator converts CUE to OpenAPI.

func (*Generator) All added in v0.0.4

func (g *Generator) All(inst *cue.Instance) (*OrderedMap, error)

All generates an OpenAPI definition from the given instance.

Note: only a limited number of top-level types are supported so far.

func (*Generator) Schemas added in v0.0.4

func (g *Generator) Schemas(inst *cue.Instance) (*OrderedMap, error)

Schemas extracts component/schemas from the CUE top-level types.

type KeyValue added in v0.0.4

type KeyValue struct {
	Key   string
	Value interface{}
}

KeyValue associates a value with a key.

type OrderedMap added in v0.0.4

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

An OrderedMap is a set of key-value pairs that preserves the order in which items were added. It marshals to JSON as an object.

func (*OrderedMap) MarshalJSON added in v0.0.4

func (m *OrderedMap) MarshalJSON() (b []byte, err error)

MarshalJSON implements json.Marshaler.

func (*OrderedMap) Pairs added in v0.0.4

func (m *OrderedMap) Pairs() []KeyValue

Pairs returns the KeyValue pairs associated with m.

func (*OrderedMap) Set added in v0.0.4

func (m *OrderedMap) Set(key string, value interface{})

Set sets a key value pair. If a pair with the same key already existed, it will be replaced with the new value. Otherwise, the new value is added to the end.

func (*OrderedMap) SetAll added in v0.0.4

func (m *OrderedMap) SetAll(kvs []KeyValue)

SetAll replaces existing key-value pairs with the given ones. The keys must be unique.

Jump to

Keyboard shortcuts

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