openapi

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const ApplicationJSON = "application/json"

ApplicationJSON is a media type

Variables

This section is empty.

Functions

func Endpoints

func Endpoints(schemas ...map[string]Path) map[string]Path

Endpoints combines path mappings

func RequiredFrom

func RequiredFrom(obj interface{}) []string

RequiredFrom retrievs every property where omitempty is not set

Types

type Components

type Components struct {
	Schemas   map[string]Schema   `json:"schemas"`
	Responses map[string]Response `json:"responses"`
	// Parameters      map[string]Parameter      `json:"parameters"`
	// Examples        map[string]Example        `json:"examples"`
	// RequestBodies   map[string]RequestBody    `json:"requestBodies"`
	// Headers         map[string]Headers        `json:"headers"`
	SecuritySchemes map[string]SecurityScheme `json:"securitySchemes"`
}

Components describe the components object

type Contact

type Contact struct {
	Name  string `json:"name"`
	URL   string `json:"url"`
	Email string `json:"email"`
}

Contact information

type FieldProperty

type FieldProperty map[string]interface{}

FieldProperty is a free form property

type Info

type Info struct {
	Title       string  `json:"title"`
	Version     string  `json:"version"`
	License     License `json:"license"`
	Description string  `json:"description"`
	Contact     Contact `json:"contact"`
}

Info about the API

type License

type License struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

License information

type MediaType

type MediaType struct {
	Schema      interface{} `json:"schema"`
	Description string      `json:"description,omitempty"`
}

MediaType is the body of a respones object, e.g. a JSON payload with a schema. All schemas here are referenced.

type Operation

type Operation struct {
	Description string       `json:"description"`
	Responses   ResponseRefs `json:"responses"`
	OperationID string       `json:"operationId"`
	Parameters  []Schema     `json:"parameters,omitempty"`
	RequestBody *Request     `json:"requestBody,omitempty"`
	Summary     string       `json:"summary,omitempty"`
	Tags        []string     `json:"tags,omitempty"`
}

An Operation describes an api endpoint in a mapping of HTTP verb to sdescription

type Path

type Path map[string]interface{}

Path is a mapping of http verb to response

type Properties

type Properties map[string]interface{}

Properties is a key value mapping from string to property

func PropertiesFrom

func PropertiesFrom(obj interface{}) Properties

PropertiesFrom produces schema properties

type Property

type Property struct {
	Type        string `json:"type"`
	Format      string `json:"format,omitempty"`
	Description string `json:"description"`
}

Property of an object

type Ref

type Ref struct {
	Ref string `json:"$ref"`
}

Ref is a reference within the openapi document

func ResponseRef

func ResponseRef(response string) Ref

ResponseRef is a reference to a response defined in components

func SchemaRef

func SchemaRef(schema string) Ref

SchemaRef creates a new ref to a schema

type Request

type Request struct {
	Content map[string]MediaType `json:"content"`
}

Request describes a request body

type Response

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

Response encode a mapping between a status code and a media type object

type ResponseRefs

type ResponseRefs map[string]Ref

ResponseRefs is a mapping from status code to a response reference

type Schema

type Schema map[string]interface{}

Schema defines an api object

func ArraySchema

func ArraySchema(description string, items interface{}) Schema

ArraySchema creates a schema for an array type

func ObjectSchema

func ObjectSchema(description string, obj interface{}) Schema

ObjectSchema creates a new schema from an object

func ParamID

func ParamID() Schema

ParamID creates an 'id' path parameter

func ParamQuery

func ParamQuery(name, description string) Schema

ParamQuery creates a query parameter

func (Schema) Nullable

func (s Schema) Nullable(props ...string) Schema

Nullable marks some props as nullable

func (Schema) Only

func (s Schema) Only(props ...string) Schema

Only creates a new object schema with properties filtered

func (Schema) Patch

func (s Schema) Patch(prop string) Schema

Patch rewrites a reference for a Patch operation

func (Schema) Require

func (s Schema) Require(props ...string) Schema

Require will mark properties as required

func (Schema) RequireFrom

func (s Schema) RequireFrom(obj interface{}) Schema

RequireFrom sets required field from an object

type Security

type Security []SecuritySpec

Security describes the auth methods of the API

type SecurityScheme

type SecurityScheme struct {
	Type        string `json:"type"`
	Description string `json:"description"`
	//	Name         string `json:"name"`
	// In           string `json:"in"`     // query, header cookie
	Scheme       string `json:"scheme"` // RFC7235
	BearerFormat string `json:"bearerFormat"`
}

SecurityScheme describes a security scheme

type SecuritySpec

type SecuritySpec map[string][]interface{}

SecuritySpec is a polymorphic type

type Server

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

Server is a description of an API server

type Spec

type Spec struct {
	OpenAPI    string          `json:"openapi"` // Version
	Info       Info            `json:"info"`
	Paths      map[string]Path `json:"paths"`
	Components Components      `json:"components"`
	Tags       []Tag           `json:"tags"`
	Servers    []Server        `json:"servers,omitempty"`
	Security   Security        `json:"security"`
}

Spec is the OpenAPI document describing the b3scale API

type Tag

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

Tag object for metadata

Jump to

Keyboard shortcuts

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