Documentation
¶
Index ¶
- type ApiInfo
- func (api *ApiInfo) GetEnable() *Enable
- func (api *ApiInfo) InitApis(filename string) error
- func (api *ApiInfo) InitEnable(filePath string) error
- func (api *ApiInfo) SendGETMethod(path string, parameters []Parameter) ([]byte, error)
- func (api *ApiInfo) SendPOSTMethod(path string, body RequestBody) ([]byte, error)
- func (api *ApiInfo) SendPOSTMethodEx(path, ct string, body []byte) ([]byte, error)
- type Enable
- type EnableParams
- type Info
- type MediaType
- type OpenAPICli
- type OpenApi
- type Operation
- type Parameter
- type PathItem
- type Property
- type RequestBody
- type Response
- type Schema
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApiInfo ¶
type ApiInfo struct {
OpenAPICli `json:"open_api_json"`
Enable `json:"enable"`
// contains filtered or unexported fields
}
func NewOpenApiCli ¶
func NewOpenApiCliEx ¶
func (*ApiInfo) InitEnable ¶
func (*ApiInfo) SendGETMethod ¶
func (*ApiInfo) SendPOSTMethod ¶
func (api *ApiInfo) SendPOSTMethod(path string, body RequestBody) ([]byte, error)
type Enable ¶
type Enable struct {
Get map[string][]Parameter `json:"get"`
Post map[string]*RequestBody `json:"post"`
Slot map[int]string `json:"slot"` // slot_id:method-path
}
func (*Enable) SlotGetEnable ¶
type EnableParams ¶
type EnableParams struct {
// 不需要考虑同时设置get和post参数的情况
GetParams map[string]string `json:"get_params"` // key is request param-name and value is param-value
PostParams *RequestBody `json:"post_params"`
Slot int `json:"slot"`
}
type MediaType ¶
type MediaType struct {
Schema interface{} `json:"schema"` // 使用interface{}来表示未知的内容
}
MediaType 定义了请求内容的结构
func (*MediaType) GetSchemaContent ¶
type OpenAPICli ¶
type OpenAPICli struct {
OpenAPI string `json:"openapi"`
Info Info `json:"info"`
Servers []Server `json:"servers,omitempty"`
Paths map[string]PathItem `json:"paths"`
}
定义OpenAPI文档的结构体
func (*OpenAPICli) GetApiInfo ¶
func (api *OpenAPICli) GetApiInfo() Info
func (*OpenAPICli) GetPaths ¶
func (api *OpenAPICli) GetPaths() map[string]PathItem
type OpenApi ¶
type OpenApi interface {
SendGETMethod(path string, parameters []Parameter) ([]byte, error)
SendPOSTMethod(path string, body RequestBody) ([]byte, error)
SendPOSTMethodEx(path, ct string, body []byte) ([]byte, error)
GetApiInfo() Info
GetPaths() map[string]PathItem
GetEnable() *Enable
}
type Operation ¶
type Operation struct {
Summary string `json:"summary"`
RequestBody *RequestBody `json:"requestBody,omitempty"` // POST
Parameters []Parameter `json:"parameters,omitempty"` // GET
Responses map[string]Response `json:"responses"` // 200, 400等
}
Operation 定义了操作的详细信息,包括请求和响应
func (*Operation) GetParameters ¶
func (*Operation) GetRequestBody ¶
func (api *Operation) GetRequestBody() *RequestBody
func (*Operation) GetResponses ¶
func (*Operation) GetSummary ¶
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"` // 通常是"query"、"header"等
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Schema Schema `json:"schema"`
}
Parameter 定义了GET请求的参数
type PathItem ¶
type PathItem struct {
Get *Operation `json:"get,omitempty"`
Post *Operation `json:"post,omitempty"`
}
PathItem 包含多个HTTP方法的操作
type RequestBody ¶
type RequestBody struct {
Description string `json:"description"`
Content map[string]MediaType `json:"content"`
}
RequestBody 定义了POST请求的body结构
func (*RequestBody) GetContent ¶
func (api *RequestBody) GetContent() map[string]MediaType
func (*RequestBody) GetDescription ¶
func (api *RequestBody) GetDescription() string
func (*RequestBody) SetBodyWithJson ¶
func (api *RequestBody) SetBodyWithJson(kv map[string]string)
type Response ¶
type Response struct {
Description string `json:"description"`
Content map[string]MediaType `json:"content"` //key: such as application/json
}
Response 定义了接口的响应
func (*Response) GetContent ¶
Click to show internal directories.
Click to hide internal directories.