swagger

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHost

func GetHost() string

GetHost 获取host

func GetKvType

func GetKvType(k string, isArray, isType bool) string

GetKvType 获取类型转换

func SetBasePath

func SetBasePath(b string)

SetBasePath set basePath

func SetExternalDocs

func SetExternalDocs(e ExternalDocs)

SetExternalDocs 设置外部doc链接

func SetHost

func SetHost(h string)

SetHost 设置host

func SetInfo

func SetInfo(i Info)

SetInfo 设置信息

func SetReqCtxType

func SetReqCtxType(isJSON, isXML bool)

SetReqCtxType 设置请求数据传输方式

func SetRespCtxType

func SetRespCtxType(isJSON, isXML bool)

SetRespCtxType 设置响应(返回)求数据传输方式

func SetSchemes

func SetSchemes(isHTTP, isHTTPS bool)

SetSchemes 设置 http头

func SetVersion

func SetVersion(v string)

SetVersion 设置版本号

Types

type APIBody

type APIBody struct {
	Head
	Info               Info                        `json:"info"`
	Host               string                      `json:"host"`     // http host
	BasePath           string                      `json:"basePath"` // 根级别
	Tags               []Tag                       `json:"tags"`
	Schemes            []string                    `json:"schemes"`                       // http/https
	Paths              map[string]map[string]Param `json:"paths"`                         // API 路径
	SecurityDefinition SecurityDefinition          `json:"securityDefinitions,omitempty"` // 安全验证
	Definitions        map[string]Definition       `json:"definitions"`                   // 通用结构体定义
	ExternalDocs       ExternalDocs                `json:"externalDocs"`                  // 外部链接
}

APIBody swagger api body info

type Definition

type Definition struct {
	Type       string              `json:"type"`       // 类型 object
	Properties map[string]Property `json:"properties"` // 属性列表
	XML        XML                 `json:"xml"`
}

Definition 通用结构体定义

type DocSwagger

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

DocSwagger ...

func NewDoc

func NewDoc() *DocSwagger

NewDoc 新建一个swagger doc

func (*DocSwagger) AddDefinitions

func (doc *DocSwagger) AddDefinitions(key string, def Definition)

AddDefinitions 添加 通用结构体定义

func (*DocSwagger) AddPatch

func (doc *DocSwagger) AddPatch(url string, p Param, metheds ...string)

AddPatch ... API 路径 paths 和操作在 API 规范的全局部分定义

func (*DocSwagger) AddTag

func (doc *DocSwagger) AddTag(tag Tag)

AddTag add tag (排他)

func (*DocSwagger) GetAPIString

func (doc *DocSwagger) GetAPIString() string

GetAPIString 获取返回数据

type Element

type Element struct {
	In          string `json:"in"`             // 入参
	Name        string `json:"name"`           // 参数名字
	Description string `json:"description"`    // 描述
	Required    bool   `json:"required"`       // 是否必须
	Type        string `json:"type,omitempty"` // 类型
	Schema      Schema `json:"schema"`         // 引用
}

Element 元素定义

type ExternalDocs

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

ExternalDocs tags of group

type Head struct {
	Swagger string `json:"swagger"`
}

Head Swagger 版本

type Info

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

Info 指定 API 的 info-title

type Param

type Param struct {
	Tags        []string                     `json:"tags"`                  // 分组标记
	Summary     string                       `json:"summary"`               // 摘要
	Description string                       `json:"description"`           // 描述
	OperationID string                       `json:"operationId,omitempty"` // 操作id
	Consumes    []string                     `json:"consumes"`              // Parameter content type
	Produces    []string                     `json:"produces"`              // Response content type
	Parameters  []Element                    `json:"parameters"`            // 请求参数
	Responses   map[string]map[string]string `json:"responses"`             // 返回参数
	Security    interface{}                  `json:"security,omitempty"`    // 认证信息
}

Param API 路径 paths 和操作在 API 规范的全局部分定义

type Property

type Property struct {
	Type        string      `json:"type,omitempty"` // 类型
	Format      string      `json:"format"`         // format 类型
	Description string      `json:"description"`    // 描述
	Enum        interface{} `json:"enum,omitempty"` // enum
	Ref         string      `json:"$ref,omitempty"` // 主体模式和响应主体模式中引用
}

Property 属性

type Schema

type Schema struct {
	Ref string `json:"$ref"` // 主体模式和响应主体模式中引用
}

Schema 引用

type SecurityDefinition

type SecurityDefinition struct {
	PetstoreAuth interface{} `json:"petstore_auth,omitempty"` // 安全验证定义
	AIPKey       interface{} `json:"api_key,omitempty"`       // api key
}

SecurityDefinition 安全验证

type Tag

type Tag struct {
	Name         string        `json:"name"`                   // tags name
	Description  string        `json:"description"`            // 描述
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` // doc group of tags
}

Tag group of tags

type XML

type XML struct {
	Name    string `json:"name"`
	Wrapped bool   `json:"wrapped"`
}

XML xml

Jump to

Keyboard shortcuts

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