openapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component struct {
	SecurityScheme sync.Map[string, *SecurityScheme] `json:"securitySchemes"`
	Parameters     map[string]*Parameter             `json:"parameters,omitempty"`
	Schemas        map[string]*Schema                `json:"schemas,omitempty"`
}

func (*Component) AddSecurityScheme

func (this *Component) AddSecurityScheme(name string) *SecurityScheme

type Content

type Content struct {
	Schema *Schema `json:"schema"`
}

type MediaType

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

type Parameter

type Parameter struct {
	Name        string  `json:"name"`
	In          string  `json:"in"` // header, query, path, cookie
	Description string  `json:"description,omitempty"`
	Required    bool    `json:"required,omitempty"`
	Deprecated  bool    `json:"deprecated,omitempty"`
	Schema      *Schema `json:"schema,omitempty"`
}

type Path

type Path struct {
	Post    *PathItem `json:"post,omitempty"`
	Get     *PathItem `json:"get,omitempty"`
	Upgrade *PathItem `json:"upgrade,omitempty"`
}

type PathItem

type PathItem struct {
	Summary     string              `json:"summary"`     // this is more like a Name
	Description string              `json:"description"` // displayed on the right
	RequestBody *RequestBody        `json:"requestBody,omitempty"`
	Servers     []Server            `json:"servers,omitempty"`
	Responses   map[string]Response `json:"responses"` // "default", "200", ...
	Security    Securities          `json:"security,omitempty"`
	Deprecated  bool                `json:"deprecated,omitempty"`
	Parameters  []Parameter         `json:"parameters,omitempty"`
}

func (*PathItem) SetJWT

func (this *PathItem) SetJWT(required bool)

add a jwt security, and optionally an empty security unless required is true

type RequestBody

type RequestBody struct {
	Content  map[string]MediaType `json:"content"`
	Required bool                 `json:"required"`
}

type Response

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

type Schema

type Schema struct {
	Type            string             `json:"type,omitempty"`                 // object/string/integer
	Format          string             `json:"format,omitempty"`               // int64
	Required        []string           `json:"required,omitempty"`             // list of required fields names
	Properties      map[string]*Schema `json:"properties,omitempty"`           // for structs
	AdditionalProps *Schema            `json:"additionalProperties,omitempty"` // for maps
	Description     string             `json:"description,omitempty"`
	Example         string             `json:"example,omitempty"`
	Items           *Schema            `json:"items,omitempty"` // for arrays/slices
	Default         string             `json:"default,omitempty"`
	Enum            []string           `json:"enum,omitempty"`

	// Mutually exclusive (if you have a $ref, it will overwrite anything else)
	// See https://swagger.io/docs/specification/using-ref/
	Reference string `json:"$ref,omitempty"`
}

type Securities

type Securities []Security

func (*Securities) Append

func (this *Securities) Append(s Security)

type Security

type Security map[string]any

type SecurityScheme

type SecurityScheme struct {
	Type        string `json:"type"` // apiKey, http, mutualTLS, oauth2, openIdConnect
	Description string `json:"description"`

	// http
	Scheme       string `json:"scheme,omitempty"`       // Bearer (https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml)
	BearerFormat string `json:"bearerFormat,omitempty"` // likely JWT

	// apiKey
	In   string `json:"in,omitempty"` // query, header, cookie
	Name string `json:"name,omitempty"`
}

func (*SecurityScheme) SetJWT

func (this *SecurityScheme) SetJWT()

type Server

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

type Service

type Service struct {
	OpenAPI string `json:"openapi"` // should be 3.0.0
	Info    struct {
		Version string `json:"version,omitempty"`
		Title   string `json:"title,omitempty"`
		License struct {
			Name string `json:"name,omitempty"`
		} `json:"license,omitempty"`
	} `json:"info"`

	Paths      map[string]*Path `json:"paths"`
	Components Component        `json:"components"`
}

func NewService

func NewService(title string) *Service

func (*Service) SchemaFromType

func (this *Service) SchemaFromType(c ctx.C, t reflect.Type, tags *reflect.StructTag) (*Schema, error)

Jump to

Keyboard shortcuts

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