openapi

package
v3.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package openapi describes a reva deployment's HTTP surface as an OpenAPI document, built from the routes its services declared.

The routes alone already carry most of what a reader wants: which paths exist, which methods they answer, which parameters their patterns name, and which of them need credentials. A route that was given a router.Doc adds the rest - what it accepts, what it returns, and what it is for.

WebDAV is the one part that does not fit. OpenAPI names its operations in a fixed set of fields, and PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, REPORT, LOCK and UNLOCK are not among them, so those are reported on the path item as an extension rather than silently dropped. A route that matches every method cannot say which of them it serves, so its path item says that it matches every method instead.

Index

Constants

View Source
const Version = "3.1.0"

Version of the OpenAPI specification the document conforms to. 3.1 embeds JSON Schema as-is, which is what the reflected schemas already are.

Variables

This section is empty.

Functions

This section is empty.

Types

type Components

type Components struct {
	Schemas         map[string]*Schema         `json:"schemas,omitempty"`
	SecuritySchemes map[string]*SecurityScheme `json:"securitySchemes,omitempty"`
}

type Document

type Document struct {
	OpenAPI    string               `json:"openapi"`
	Info       Info                 `json:"info"`
	Servers    []Server             `json:"servers,omitempty"`
	Tags       []Tag                `json:"tags,omitempty"`
	Paths      map[string]*PathItem `json:"paths"`
	Components Components           `json:"components"`
}

Document is an OpenAPI document.

func From

func From(routes []router.Route, info Info, servers []Server, schemes []auth.Scheme) *Document

From builds the document describing the given routes, authenticated by the given schemes.

The schemes are the deployment's own, resolved from how its authentication is configured, so that what the document tells a client to send is what the server reads. Passing none leaves the document silent about authentication rather than guessing at it.

type Info

type Info struct {
	Title       string `json:"title"`
	Version     string `json:"version"`
	Description string `json:"description,omitempty"`
}

type MediaType

type MediaType struct {
	Schema *Schema `json:"schema,omitempty"`
}

type Operation

type Operation struct {
	OperationID string                `json:"operationId,omitempty"`
	Tags        []string              `json:"tags,omitempty"`
	Summary     string                `json:"summary,omitempty"`
	Description string                `json:"description,omitempty"`
	Parameters  []*Parameter          `json:"parameters,omitempty"`
	RequestBody *RequestBody          `json:"requestBody,omitempty"`
	Responses   map[string]*Response  `json:"responses,omitempty"`
	Security    []map[string][]string `json:"security,omitempty"`
}

type Parameter

type Parameter struct {
	Name        string  `json:"name"`
	In          string  `json:"in"`
	Description string  `json:"description,omitempty"`
	Required    bool    `json:"required,omitempty"`
	Schema      *Schema `json:"schema,omitempty"`
	Example     string  `json:"example,omitempty"`
}

type PathItem

type PathItem struct {
	Get     *Operation `json:"get,omitempty"`
	Put     *Operation `json:"put,omitempty"`
	Post    *Operation `json:"post,omitempty"`
	Delete  *Operation `json:"delete,omitempty"`
	Options *Operation `json:"options,omitempty"`
	Head    *Operation `json:"head,omitempty"`
	Patch   *Operation `json:"patch,omitempty"`
	Trace   *Operation `json:"trace,omitempty"`
	// Parameters shared by every operation of the path.
	Parameters []*Parameter `json:"parameters,omitempty"`
	// WebDAVMethods are the methods the path answers that OpenAPI has no field
	// for. They are reported so that no method a service named is lost.
	WebDAVMethods []string `json:"x-webdav-methods,omitempty"`
	// AnyMethod is set when a route at the path matches every method. Its
	// operations are then the usual ones OpenAPI names, and the path may
	// answer others, WebDAV's among them, that are listed nowhere.
	AnyMethod bool `json:"x-any-method,omitempty"`
}

PathItem holds the operations of one path.

type RequestBody

type RequestBody struct {
	Description string                `json:"description,omitempty"`
	Required    bool                  `json:"required,omitempty"`
	Content     map[string]*MediaType `json:"content,omitempty"`
}

type Response

type Response struct {
	Description string                `json:"description"`
	Content     map[string]*MediaType `json:"content,omitempty"`
}

type Schema

type Schema = jsonschema.Schema

Schema is a JSON Schema. OpenAPI 3.1 embeds JSON Schema as it is, so the schemas reflected out of Go types need no translation.

type SecurityScheme

type SecurityScheme struct {
	Type        string `json:"type"`
	Scheme      string `json:"scheme,omitempty"`
	In          string `json:"in,omitempty"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
}

type Server

type Server struct {
	URL         string `json:"url"`
	Description string `json:"description,omitempty"`
}

type Tag

type Tag struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

Jump to

Keyboard shortcuts

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