Help us shape the future of Go! Take the 2026 Go Developer Survey

openapi

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package openapi reads the OpenAPI document meshStack publishes, and picks the operations of a request path, a method and a version out of it. It does not know where the document comes from.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiVersion

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

func MustParseApiVersion

func MustParseApiVersion(s string) ApiVersion

func ParseApiVersion

func ParseApiVersion(s string) (ApiVersion, error)

func (ApiVersion) Compare

func (v ApiVersion) Compare(other ApiVersion) int

func (ApiVersion) IsZero

func (v ApiVersion) IsZero() bool

func (ApiVersion) String

func (v ApiVersion) String() string

String is empty for the zero version.

type ApiVersions

type ApiVersions []ApiVersion

func (ApiVersions) SortedUnique

func (vs ApiVersions) SortedUnique() ApiVersions

SortedUnique sorts in place, oldest first.

func (ApiVersions) String

func (vs ApiVersions) String() string

type Body

type Body struct {
	MediaType string
	Fields    []Field
}

Body is the content of one media type.

type Field

type Field struct {
	Path        string
	Type        string
	Required    bool
	Description string
}

Field is a property anywhere in a body. Its Path joins the property names from the top with dots, and writes the items of an array as [], as in spec.parentBuildingBlockRefs[].uuid, and the values of a map as the name *, as the API docs do.

func (Field) Depth

func (f Field) Depth() int

func (Field) Name

func (f Field) Name() string

type MediaType

type MediaType struct {
	Name string
	// Kind is empty for a type of no meshObject.
	Kind string
	// ApiVersion is zero for a type of no version, such as application/json.
	ApiVersion ApiVersion
}

func ParseMediaType

func ParseMediaType(name string) MediaType

ParseMediaType reads a media type such as an Accept header carries. Its Kind is in lower case, as the media type writes it.

func (MediaType) WithKindAndApiVersion

func (m MediaType) WithKindAndApiVersion(body jsontext.Value) (jsontext.Value, error)

WithKindAndApiVersion adds the kind and apiVersion a meshObject body lacks, in front, as the meshObject API writes them.

type Operation

type Operation struct {
	Method       string
	PathTemplate PathTemplate
	// Kind is the meshObject kind below whose path the operation is, such as meshBuildingBlock, or
	// empty outside the path of a kind.
	Kind string
	// Action names the operation within its kind, as a command of the CLI would: list, show,
	// create, update, delete, or the path below the kind's object, such as trigger-run.
	Action string
	// MediaTypes are those of the request body and of every response, each once.
	MediaTypes []MediaType
	// contains filtered or unexported fields
}

func (Operation) ApiVersions

func (o Operation) ApiVersions() ApiVersions

ApiVersions are oldest first.

func (Operation) LatestApiVersion

func (o Operation) LatestApiVersion() ApiVersion

LatestApiVersion is zero for an operation of no version.

func (Operation) LatestMediaType

func (o Operation) LatestMediaType() (MediaType, bool)

LatestMediaType is the one of the latest version, or for an operation of no version the first, such as application/json. It is the one to accept, and to send a body in.

func (Operation) MediaType

func (o Operation) MediaType(version ApiVersion) (MediaType, bool)

type OperationDoc

type OperationDoc struct {
	Summary       string
	Description   string
	Parameters    []Parameter
	RequestBodies []Body
	Responses     []Response
}

OperationDoc is what the API docs say about an operation, for a person to read.

type Parameter

type Parameter struct {
	Name, In    string
	Required    bool
	Type        string
	Description string
	// PathKey names the metadata field that fills a path parameter, such as metadata.uuid, or a
	// template of several in braces, such as {metadata.ownedByWorkspace}.{metadata.name}.
	PathKey string
}

type PathTemplate

type PathTemplate string

type Response

type Response struct {
	Status, Description string
	Bodies              []Body
}

type Selector

type Selector struct {
	// Kind and Action select by Operation.Kind and Operation.Action. Kind is matched in any case.
	Kind   string
	Action string
	// Method is empty for every method.
	Method string
	// Path is a request path such as /api/meshobjects/meshtenants/<uuid>, or empty for every path.
	Path string
	// ApiVersion is zero for the latest version each operation offers.
	ApiVersion ApiVersion
}

func (Selector) IsZero

func (s Selector) IsZero() bool

type Spec

type Spec struct {
	Operations []Operation
	// contains filtered or unexported fields
}

Spec is an OpenAPI document. After Select, it marshals to the selected operations and the components they reference.

func Parse

func Parse(r io.Reader) (Spec, error)

func (Spec) Actions

func (s Spec) Actions(kind string) []string

Actions are those of the operations of one kind, in the order of the document.

func (Spec) Doc

func (s Spec) Doc(operation Operation) (OperationDoc, error)

Doc reads the operation of a Spec, or of a selection of it, which keeps every component.

func (Spec) Kinds

func (s Spec) Kinds() []string

Kinds are the meshObject kinds of the operations, such as meshBuildingBlock, sorted.

func (Spec) MarshalJSONTo

func (s Spec) MarshalJSONTo(enc *jsontext.Encoder) error

func (Spec) Select

func (s Spec) Select(selector Selector) (Spec, error)

Select keeps the operations the selector matches, and of their media types those of one version.

Jump to

Keyboard shortcuts

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