schema

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package schema defines basic OpenAPI schema for RPC

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expose

func Expose(schema *Schema) http.Handler

Expose schema as pre-generated, cached JSON.

func Handler

func Handler(index map[string]*rpc.ExposedMethod, options ...Option) http.Handler

Handler exposes OpenAPI 3.1 cached pre-generated spec. See OpenAPI. This is just an alias to Expose(OpenAPI()).

Types

type ContentType

type ContentType struct {
	Schema *Type `json:"schema,omitempty" yaml:"schema,omitempty"`
}

type Endpoint

type Endpoint struct {
	Summary     string  `json:"summary,omitempty" yaml:"summary,omitempty"`
	OperationID string  `json:"operationId" yaml:"operationId"`
	RequestBody Payload `json:"requestBody" yaml:"requestBody"`
	Responses   struct {
		OK            Payload  `json:"200" yaml:"200"`
		BadRequest    *Payload `json:"400" yaml:"400"`
		InternalError *Payload `json:"500" yaml:"500"`
	} `json:"responses" yaml:"responses"`
}

type Option

type Option func(builder *schemaBuilder)

Option configures schema creation.

func Define

func Define(pkg, name string, definition *Type) Option

Define specific type as OpenAPI definition.

func Title

func Title(title string) Option

Title for schema.

func URL

func URL(urls ...string) Option

URL for OpenAPI server.

func Version

func Version(version string) Option

Version of API.

type Path

type Path struct {
	Post Endpoint `json:"post" yaml:"post"`
}

type Payload

type Payload struct {
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	Content     struct {
		JSON  *ContentType `json:"application/json,omitempty" yaml:"application/json,omitempty"`
		Plain *ContentType `json:"text/plain,omitempty" yaml:"text/plain,omitempty"`
	} `json:"content,omitempty" yaml:"content,omitempty"`
}

type Schema

type Schema struct {
	OpenAPI string   `json:"openapi" yaml:"openapi"`
	Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty"`
	Info    struct {
		Title   string `json:"title" yaml:"title"`
		Version string `json:"version" yaml:"version"`
	} `json:"info" yaml:"info"`
	Paths      map[string]Path `json:"paths,omitempty" yaml:"paths,omitempty"`
	Components struct {
		Schemas map[string]*Type `json:"schemas,omitempty" yaml:"schemas,omitempty"`
	} `json:"components,omitempty" yaml:"components,omitempty"`
}

Schema represents OpenAPI definition of endpoints.

func OpenAPI

func OpenAPI(index map[string]*rpc.ExposedMethod, options ...Option) *Schema

OpenAPI generates Open-API 3.1 schema based on pre-indexed server object (see rpc.Index). It's recommend to cache result.

type Server

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

Server represents reference to API server.

type Type

type Type struct {
	Type        string           `json:"type,omitempty" yaml:"type,omitempty"`
	Format      string           `json:"format,omitempty" yaml:"format,omitempty"`
	Ref         string           `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Items       *Type            `json:"items,omitempty" yaml:"items,omitempty"`
	Properties  map[string]*Type `json:"properties,omitempty" yaml:"properties,omitempty"`
	Required    []string         `json:"required,omitempty" yaml:"required,omitempty"`
	Minimum     *int64           `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	Maximum     int64            `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	PrefixItems []*Type          `json:"prefixItems,omitempty" yaml:"prefixItems,omitempty"`
	MinItems    int              `json:"minItems,omitempty" yaml:"minItems,omitempty"`
	MaxItems    int              `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
	Description string           `json:"description,omitempty" yaml:"description,omitempty"`
	Name        string           `json:"-" yaml:"-"`
}

Jump to

Keyboard shortcuts

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