goai

package
v2.0.7-feature-clickho... Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package goai implements and provides document generating for OpenApi specification.

https://editor.swagger.io/

Index

Constants

View Source
const (
	HttpMethodGet     = `GET`
	HttpMethodPut     = `PUT`
	HttpMethodPost    = `POST`
	HttpMethodDelete  = `DELETE`
	HttpMethodConnect = `CONNECT`
	HttpMethodHead    = `HEAD`
	HttpMethodOptions = `OPTIONS`
	HttpMethodPatch   = `PATCH`
	HttpMethodTrace   = `TRACE`
)
View Source
const (
	TypeInteger    = `integer`
	TypeNumber     = `number`
	TypeBoolean    = `boolean`
	TypeArray      = `array`
	TypeString     = `string`
	TypeObject     = `object`
	FormatInt32    = `int32`
	FormatInt64    = `int64`
	FormatDouble   = `double`
	FormatByte     = `byte`
	FormatBinary   = `binary`
	FormatDate     = `date`
	FormatDateTime = `date-time`
	FormatPassword = `password`
)
View Source
const (
	ParameterInHeader = `header`
	ParameterInPath   = `path`
	ParameterInQuery  = `query`
	ParameterInCookie = `cookie`
)
View Source
const (
	TagNamePath     = `path`
	TagNameMethod   = `method`
	TagNameMime     = `mime`
	TagNameConsumes = `consumes`
	TagNameType     = `type`
	TagNameDomain   = `domain`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddInput

type AddInput struct {
	Path   string      // Path specifies the custom path if this is not configured in Meta of struct tag.
	Prefix string      // Prefix specifies the custom route path prefix, which will be added with the path tag in Meta of struct tag.
	Method string      // Method specifies the custom HTTP method if this is not configured in Meta of struct tag.
	Object interface{} // Object can be an instance of struct or a route function.
}

AddInput is the structured parameter for function OpenApiV3.Add.

type Callback

type Callback map[string]*Path

Callback is specified by OpenAPI/Swagger standard version 3.0.

type CallbackRef

type CallbackRef struct {
	Ref   string
	Value *Callback
}

func (CallbackRef) MarshalJSON

func (r CallbackRef) MarshalJSON() ([]byte, error)

type Callbacks

type Callbacks map[string]*CallbackRef

type Components

type Components struct {
	Schemas         Schemas         `json:"schemas,omitempty"`
	Parameters      ParametersMap   `json:"parameters,omitempty"`
	Headers         Headers         `json:"headers,omitempty"`
	RequestBodies   RequestBodies   `json:"requestBodies,omitempty"`
	Responses       Responses       `json:"responses,omitempty"`
	SecuritySchemes SecuritySchemes `json:"securitySchemes,omitempty"`
	Examples        Examples        `json:"examples,omitempty"`
	Links           Links           `json:"links,omitempty"`
	Callbacks       Callbacks       `json:"callbacks,omitempty"`
}

Components is specified by OpenAPI/Swagger standard version 3.0.

type Config

type Config struct {
	ReadContentTypes        []string    // ReadContentTypes specifies the default MIME types for consuming if MIME types are not configured.
	WriteContentTypes       []string    // WriteContentTypes specifies the default MIME types for producing if MIME types are not configured.
	CommonRequest           interface{} // Common request structure for all paths.
	CommonRequestDataField  string      // Common request field name to be replaced with certain business request structure. Eg: `Data`, `Request.`.
	CommonResponse          interface{} // Common response structure for all paths.
	CommonResponseDataField string      // Common response field name to be replaced with certain business response structure. Eg: `Data`, `Response.`.
	IgnorePkgPath           bool        // Ignores package name for schema name.
}

Config provides extra configuration feature for OpenApiV3 implements.

type Contact

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

Contact is specified by OpenAPI/Swagger standard version 3.0.

type Content

type Content map[string]MediaType

Content is specified by OpenAPI/Swagger 3.0 standard.

type Discriminator

type Discriminator struct {
	PropertyName string            `json:"propertyName"`
	Mapping      map[string]string `json:"mapping,omitempty"`
}

Discriminator is specified by OpenAPI/Swagger standard version 3.0.

type Encoding

type Encoding struct {
	ContentType   string  `json:"contentType,omitempty"`
	Headers       Headers `json:"headers,omitempty"`
	Style         string  `json:"style,omitempty"`
	Explode       *bool   `json:"explode,omitempty"`
	AllowReserved bool    `json:"allowReserved,omitempty"`
}

Encoding is specified by OpenAPI/Swagger 3.0 standard.

type Example

type Example struct {
	Summary       string      `json:"summary,omitempty"`
	Description   string      `json:"description,omitempty"`
	Value         interface{} `json:"value,omitempty"`
	ExternalValue string      `json:"externalValue,omitempty"`
}

Example is specified by OpenAPI/Swagger 3.0 standard.

type ExampleRef

type ExampleRef struct {
	Ref   string
	Value *Example
}

func (ExampleRef) MarshalJSON

func (r ExampleRef) MarshalJSON() ([]byte, error)

type Examples

type Examples map[string]*ExampleRef

type ExternalDocs

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

ExternalDocs is specified by OpenAPI/Swagger standard version 3.0.

func (*ExternalDocs) UnmarshalValue added in v2.0.5

func (ed *ExternalDocs) UnmarshalValue(value interface{}) error
type Header struct {
	Parameter
}

Header is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#headerObject

type HeaderRef

type HeaderRef struct {
	Ref   string
	Value *Header
}

func (HeaderRef) MarshalJSON

func (r HeaderRef) MarshalJSON() ([]byte, error)

type Headers

type Headers map[string]HeaderRef

type Info

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

Info is specified by OpenAPI/Swagger standard version 3.0.

type License

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

License is specified by OpenAPI/Swagger standard version 3.0.

type Link struct {
	OperationID  string                 `json:"operationId,omitempty"`
	OperationRef string                 `json:"operationRef,omitempty"`
	Description  string                 `json:"description,omitempty"`
	Parameters   map[string]interface{} `json:"parameters,omitempty"`
	Server       *Server                `json:"server,omitempty"`
	RequestBody  interface{}            `json:"requestBody,omitempty"`
}

Link is specified by OpenAPI/Swagger standard version 3.0.

type LinkRef

type LinkRef struct {
	Ref   string
	Value *Link
}

func (LinkRef) MarshalJSON

func (r LinkRef) MarshalJSON() ([]byte, error)
type Links map[string]LinkRef

type MediaType

type MediaType struct {
	Schema   *SchemaRef           `json:"schema,omitempty"`
	Example  interface{}          `json:"example,omitempty"`
	Examples Examples             `json:"examples,omitempty"`
	Encoding map[string]*Encoding `json:"encoding,omitempty"`
}

MediaType is specified by OpenAPI/Swagger 3.0 standard.

type OAuthFlow

type OAuthFlow struct {
	AuthorizationURL string            `json:"authorizationUrl,omitempty"`
	TokenURL         string            `json:"tokenUrl,omitempty"`
	RefreshURL       string            `json:"refreshUrl,omitempty"`
	Scopes           map[string]string `json:"scopes"`
}

type OAuthFlows

type OAuthFlows struct {
	Implicit          *OAuthFlow `json:"implicit,omitempty"`
	Password          *OAuthFlow `json:"password,omitempty"`
	ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty"`
	AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty"`
}

type OpenApiV3

type OpenApiV3 struct {
	Config       Config                `json:"-"`
	OpenAPI      string                `json:"openapi"`
	Components   Components            `json:"components,omitempty"`
	Info         Info                  `json:"info"`
	Paths        Paths                 `json:"paths"`
	Security     *SecurityRequirements `json:"security,omitempty"`
	Servers      *Servers              `json:"servers,omitempty"`
	Tags         *Tags                 `json:"tags,omitempty"`
	ExternalDocs *ExternalDocs         `json:"externalDocs,omitempty"`
}

OpenApiV3 is the structure defined from: https://swagger.io/specification/ https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md

func New

func New() *OpenApiV3

New creates and returns a OpenApiV3 implements object.

func (*OpenApiV3) Add

func (oai *OpenApiV3) Add(in AddInput) error

Add adds an instance of struct or a route function to OpenApiV3 definition implements.

func (OpenApiV3) String

func (oai OpenApiV3) String() string

type Operation

type Operation struct {
	Tags         []string              `json:"tags,omitempty"`
	Summary      string                `json:"summary,omitempty"`
	Description  string                `json:"description,omitempty"`
	OperationID  string                `json:"operationId,omitempty"`
	Parameters   Parameters            `json:"parameters,omitempty"`
	RequestBody  *RequestBodyRef       `json:"requestBody,omitempty"`
	Responses    Responses             `json:"responses"`
	Deprecated   bool                  `json:"deprecated,omitempty"`
	Callbacks    *Callbacks            `json:"callbacks,omitempty"`
	Security     *SecurityRequirements `json:"security,omitempty"`
	Servers      *Servers              `json:"servers,omitempty"`
	ExternalDocs *ExternalDocs         `json:"externalDocs,omitempty"`
	XExtensions  XExtensions           `json:"-"`
}

Operation represents "operation" specified by OpenAPI/Swagger 3.0 standard.

func (Operation) MarshalJSON added in v2.0.5

func (o Operation) MarshalJSON() ([]byte, error)

type Parameter

type Parameter struct {
	Name            string      `json:"name,omitempty"`
	In              string      `json:"in,omitempty"`
	Description     string      `json:"description,omitempty"`
	Style           string      `json:"style,omitempty"`
	Explode         *bool       `json:"explode,omitempty"`
	AllowEmptyValue bool        `json:"allowEmptyValue,omitempty"`
	AllowReserved   bool        `json:"allowReserved,omitempty"`
	Deprecated      bool        `json:"deprecated,omitempty"`
	Required        bool        `json:"required,omitempty"`
	Schema          *SchemaRef  `json:"schema,omitempty"`
	Example         interface{} `json:"example,omitempty"`
	Examples        *Examples   `json:"examples,omitempty"`
	Content         *Content    `json:"content,omitempty"`
	XExtensions     XExtensions `json:"-"`
}

Parameter is specified by OpenAPI/Swagger 3.0 standard. See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#parameterObject

func (Parameter) MarshalJSON added in v2.0.5

func (p Parameter) MarshalJSON() ([]byte, error)

type ParameterRef

type ParameterRef struct {
	Ref   string
	Value *Parameter
}

func (ParameterRef) MarshalJSON

func (r ParameterRef) MarshalJSON() ([]byte, error)

type Parameters

type Parameters []ParameterRef

Parameters is specified by OpenAPI/Swagger 3.0 standard.

type ParametersMap

type ParametersMap map[string]*ParameterRef

type Path

type Path struct {
	Ref         string      `json:"$ref,omitempty"`
	Summary     string      `json:"summary,omitempty"`
	Description string      `json:"description,omitempty"`
	Connect     *Operation  `json:"connect,omitempty"`
	Delete      *Operation  `json:"delete,omitempty"`
	Get         *Operation  `json:"get,omitempty"`
	Head        *Operation  `json:"head,omitempty"`
	Options     *Operation  `json:"options,omitempty"`
	Patch       *Operation  `json:"patch,omitempty"`
	Post        *Operation  `json:"post,omitempty"`
	Put         *Operation  `json:"put,omitempty"`
	Trace       *Operation  `json:"trace,omitempty"`
	Servers     Servers     `json:"servers,omitempty"`
	Parameters  Parameters  `json:"parameters,omitempty"`
	XExtensions XExtensions `json:"-"`
}

func (Path) MarshalJSON added in v2.0.5

func (p Path) MarshalJSON() ([]byte, error)

type Paths

type Paths map[string]Path

Paths are specified by OpenAPI/Swagger standard version 3.0.

type RequestBodies

type RequestBodies map[string]*RequestBodyRef

type RequestBody

type RequestBody struct {
	Description string  `json:"description,omitempty"`
	Required    bool    `json:"required,omitempty"`
	Content     Content `json:"content,omitempty"`
}

RequestBody is specified by OpenAPI/Swagger 3.0 standard.

type RequestBodyRef

type RequestBodyRef struct {
	Ref   string
	Value *RequestBody
}

func (RequestBodyRef) MarshalJSON

func (r RequestBodyRef) MarshalJSON() ([]byte, error)

type Response

type Response struct {
	Description string      `json:"description"`
	Headers     Headers     `json:"headers,omitempty"`
	Content     Content     `json:"content,omitempty"`
	Links       Links       `json:"links,omitempty"`
	XExtensions XExtensions `json:"-"`
}

Response is specified by OpenAPI/Swagger 3.0 standard.

func (Response) MarshalJSON added in v2.0.5

func (r Response) MarshalJSON() ([]byte, error)

type ResponseRef

type ResponseRef struct {
	Ref   string
	Value *Response
}

func (ResponseRef) MarshalJSON

func (r ResponseRef) MarshalJSON() ([]byte, error)

type Responses

type Responses map[string]ResponseRef

Responses is specified by OpenAPI/Swagger 3.0 standard.

type Schema

type Schema struct {
	OneOf                SchemaRefs     `json:"oneOf,omitempty"`
	AnyOf                SchemaRefs     `json:"anyOf,omitempty"`
	AllOf                SchemaRefs     `json:"allOf,omitempty"`
	Not                  *SchemaRef     `json:"not,omitempty"`
	Type                 string         `json:"type,omitempty"`
	Title                string         `json:"title,omitempty"`
	Format               string         `json:"format,omitempty"`
	Description          string         `json:"description,omitempty"`
	Enum                 []interface{}  `json:"enum,omitempty"`
	Default              interface{}    `json:"default,omitempty"`
	Example              interface{}    `json:"example,omitempty"`
	ExternalDocs         *ExternalDocs  `json:"externalDocs,omitempty"`
	UniqueItems          bool           `json:"uniqueItems,omitempty"`
	ExclusiveMin         bool           `json:"exclusiveMinimum,omitempty"`
	ExclusiveMax         bool           `json:"exclusiveMaximum,omitempty"`
	Nullable             bool           `json:"nullable,omitempty"`
	ReadOnly             bool           `json:"readOnly,omitempty"`
	WriteOnly            bool           `json:"writeOnly,omitempty"`
	AllowEmptyValue      bool           `json:"allowEmptyValue,omitempty"`
	XML                  interface{}    `json:"xml,omitempty"`
	Deprecated           bool           `json:"deprecated,omitempty"`
	Min                  *float64       `json:"minimum,omitempty"`
	Max                  *float64       `json:"maximum,omitempty"`
	MultipleOf           *float64       `json:"multipleOf,omitempty"`
	MinLength            uint64         `json:"minLength,omitempty"`
	MaxLength            *uint64        `json:"maxLength,omitempty"`
	Pattern              string         `json:"pattern,omitempty"`
	MinItems             uint64         `json:"minItems,omitempty"`
	MaxItems             *uint64        `json:"maxItems,omitempty"`
	Items                *SchemaRef     `json:"items,omitempty"`
	Required             []string       `json:"required,omitempty"`
	Properties           Schemas        `json:"properties,omitempty"`
	MinProps             uint64         `json:"minProperties,omitempty"`
	MaxProps             *uint64        `json:"maxProperties,omitempty"`
	AdditionalProperties *SchemaRef     `json:"additionalProperties,omitempty"`
	Discriminator        *Discriminator `json:"discriminator,omitempty"`
	XExtensions          XExtensions    `json:"-"`
}

Schema is specified by OpenAPI/Swagger 3.0 standard.

func (Schema) MarshalJSON added in v2.0.5

func (s Schema) MarshalJSON() ([]byte, error)

type SchemaRef

type SchemaRef struct {
	Ref   string
	Value *Schema
}

func (SchemaRef) MarshalJSON

func (r SchemaRef) MarshalJSON() ([]byte, error)

type SchemaRefs

type SchemaRefs []SchemaRef

type Schemas

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

func (*Schemas) Get

func (s *Schemas) Get(name string) *SchemaRef

func (*Schemas) Iterator

func (s *Schemas) Iterator(f func(key string, ref SchemaRef) bool)

func (*Schemas) Map

func (s *Schemas) Map() map[string]SchemaRef

func (Schemas) MarshalJSON

func (s Schemas) MarshalJSON() ([]byte, error)

func (*Schemas) Set

func (s *Schemas) Set(name string, ref SchemaRef)

type SecurityRequirement

type SecurityRequirement map[string][]string

type SecurityRequirements

type SecurityRequirements []SecurityRequirement

type SecurityScheme

type SecurityScheme struct {
	Type             string      `json:"type,omitempty"`
	Description      string      `json:"description,omitempty"`
	Name             string      `json:"name,omitempty"`
	In               string      `json:"in,omitempty"`
	Scheme           string      `json:"scheme,omitempty"`
	BearerFormat     string      `json:"bearerFormat,omitempty"`
	Flows            *OAuthFlows `json:"flows,omitempty"`
	OpenIdConnectUrl string      `json:"openIdConnectUrl,omitempty"`
}

type SecuritySchemeRef

type SecuritySchemeRef struct {
	Ref   string
	Value *SecurityScheme
}

func (SecuritySchemeRef) MarshalJSON

func (r SecuritySchemeRef) MarshalJSON() ([]byte, error)

type SecuritySchemes

type SecuritySchemes map[string]SecuritySchemeRef

type Server

type Server struct {
	URL         string                     `json:"url"`
	Description string                     `json:"description,omitempty"`
	Variables   map[string]*ServerVariable `json:"variables,omitempty"`
}

Server is specified by OpenAPI/Swagger standard version 3.0.

type ServerVariable

type ServerVariable struct {
	Enum        []string `json:"enum,omitempty"`
	Default     string   `json:"default,omitempty"`
	Description string   `json:"description,omitempty"`
}

ServerVariable is specified by OpenAPI/Swagger standard version 3.0.

type Servers

type Servers []Server

Servers is specified by OpenAPI/Swagger standard version 3.0.

type Tag

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

Tag is specified by OpenAPI/Swagger 3.0 standard.

type Tags

type Tags []Tag

Tags is specified by OpenAPI/Swagger 3.0 standard.

type XExtensions added in v2.0.5

type XExtensions map[string]interface{}

XExtensions stores the `x-` custom extensions.

Jump to

Keyboard shortcuts

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