openapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: MIT Imports: 31 Imported by: 1

Documentation

Index

Constants

View Source
const (
	InputType_AsStandard = iota
	InputType_AsRawMap
	InputType_AsWholeRaw
)

Variables

View Source
var NullValue = errors.New("null value")

Functions

func AddMethod

func AddMethod(def *openapi3.T, path, method string) (*openapi3.Operation, string)

func CallByMethodAndReturnBody

func CallByMethodAndReturnBody(method *openapi3.Operation, nameOfPath, nameOfMethod string, server *openapi3.Server, args *CallConfig, fn DefHandler) (hasChange bool, body io.ReadCloser, extraInfos *TestResult, mSel *OperationSelection, statuscode int, err error)

CallByMethod 根据方法进行调用

func EncodingParToString

func EncodingParToString(def *openapi3.Schema, style string, value interface{}) string

将参数按风格转换为可用于参数设置等的字符串,用在query、path、header、cookie等参数的设置

func GetBaseUrlFromServer

func GetBaseUrlFromServer(serv *openapi3.Server, args map[string]string) string

func GetMethod

func GetMethod(t *openapi3.T, args *CallConfig) (method *openapi3.Operation, nameOfPath string, nameOfMethod string, err error)

GetMethod 按调用参数从配置中选择合适的method

func GetValue

func GetValue(p *ParameterSelection, name string, typ string,
	others map[string]map[string]*ParameterSelection,
	inputs map[string]interface{},
	handled map[string]interface{},
	schemas openapi3.Schemas,
	encodings map[string]*openapi3.Encoding,
) (interface{}, error)

GetValue 返回对应的参数的计算值,name 待计算参数的名称,用于比较和过滤 typ 用于标注其他来源的参数 others 传入的其他参数, inputs 用户传入的输入 handled 用于在迭代过程中标注已经处理过的参数 def 传入的整体消息定义(注意:是整体的定义,以便在迭代过程中获取其他参数的定义) 返回: 1、具体处理后的值,使用interface{}以便兼容array、object、number和string等不同类型

func TestResponse

func TestResponse(method *openapi3.Operation, body io.ReadCloser, extraInfos *TestResult,
	mSel *OperationSelection,
	statuscode int,
	fn DefHandler) (bool, error)

func TestSchemaInResponse

func TestSchemaInResponse(typ string, schema *openapi3.Schema, bts []byte, contentTester DefHandler) (hasChange bool, obj interface{}, err error)

对返回结果进行测试

Types

type AscOrderedMap

type AscOrderedMap map[string]interface{}

func (AscOrderedMap) Strings

func (a AscOrderedMap) Strings() []string

type CallConfig

type CallConfig struct {
	Def               json.RawMessage
	Selection         CallingArgs
	Session           *SignedCookieSession
	EmulatedUrl       string //不经过server选择,直接使用某个baseURL
	Input             map[string]interface{}
	NameOfPath        string
	NameOfMethod      string
	DisableSslCheck   bool        //不验证服务器证书
	ShowCertification bool        //将证书内容返回
	Origin            string      //请求的原始地址
	InputType         int         //input模式
	Header            http.Header //用于非标模式下Header数据的存储
	Query             url.Values  //用于非标模式下Query数据的存储
	PathVars          url.Values  //解析url中的变量
	RequestBody       interface{} //用于非标模式下Body数据的存储
	RequestType       string      //用于非标模式下Body数据的存储

}

func (*CallConfig) GetServer

func (args *CallConfig) GetServer(def *openapi3.T) (server *openapi3.Server, err error)

type CallingArgs

type CallingArgs interface {
	GetServerId() int
	GetServerVariables() map[string]string
	GetPathArgs(nameOfPath string) (*PathSelection, bool)
}

type CallingPathArgs

type CallingPathArgs interface {
	GetByMethod(method string) *OperationSelection
}

type DataResult

type DataResult struct {
	Name   string
	Values map[string]interface{}
}

用于表示返回结果的内置结构体

func (*DataResult) MarshalJSON

func (s *DataResult) MarshalJSON() ([]byte, error)

func (*DataResult) MarshalXML

func (s *DataResult) MarshalXML(e *xml.Encoder, start xml.StartElement) error

StringMap marshals into XML.

func (*DataResult) UnmarshalJSON

func (s *DataResult) UnmarshalJSON(data []byte) error

func (*DataResult) UnmarshalXML

func (s *DataResult) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type DefHandler

type DefHandler interface {
	TransformValue(def *openapi3.Schema, value interface{}) (bool, interface{}, error)
	TransformValueVersa(def *openapi3.Schema, value interface{}) (bool, interface{}, error)
	CreateResponseIfNotDefined() bool
}

type DescOrderedMap

type DescOrderedMap map[string]interface{}

func (DescOrderedMap) Strings

func (a DescOrderedMap) Strings() []string

type Item

type Item struct {
	Key   string
	Value interface{}
	Desc  bool
}

func (Item) String

func (it Item) String() string

type Items

type Items []Item

func (Items) Len

func (i Items) Len() int

func (Items) Less

func (i Items) Less(first, second int) bool

func (Items) Swap

func (i Items) Swap(first, second int)

type OperationSelection

type OperationSelection struct {
	Response    *ResponseSelection      `goblet:"response" json:"response,omitempty"`
	Security    *SecuritySelection      `goblet:"security" json:"security,omitempty"`
	Opened      bool                    `goblet:"opened" json:"opened,omitempty"`
	Parameters  ParameterSelectionArray `goblet:"parameters" json:"parameters,omitempty"`
	RequestBody *RequestBodySelection   `goblet:"requestBody" json:"requestBody,omitempty"`
	InputMode   string                  `goblet:"input_mode" json:"input_mode"`
}

type ParameterSelection

type ParameterSelection struct {
	Fixed      bool   `goblet:"fixed" json:"fixed"`
	Value      string `goblet:"value" json:"value"`
	Calculated bool   `goblet:"calculated" json:"calculated"`
}

type ParameterSelectionArray

type ParameterSelectionArray []*ParameterSelection

func (*ParameterSelectionArray) ToMap

type PathSelection

type PathSelection struct {
	Connect *OperationSelection `goblet:"connect" json:"connect,omitempty" yaml:"connect,omitempty"`
	Delete  *OperationSelection `goblet:"delete" json:"delete,omitempty" yaml:"delete,omitempty"`
	Get     *OperationSelection `goblet:"get" json:"get,omitempty" yaml:"get,omitempty"`
	Head    *OperationSelection `goblet:"head" json:"head,omitempty" yaml:"head,omitempty"`
	Options *OperationSelection `goblet:"options" json:"options,omitempty" yaml:"options,omitempty"`
	Patch   *OperationSelection `goblet:"patch" json:"patch,omitempty" yaml:"patch,omitempty"`
	Post    *OperationSelection `goblet:"post" json:"post,omitempty" yaml:"post,omitempty"`
	Put     *OperationSelection `goblet:"put" json:"put,omitempty" yaml:"put,omitempty"`
	Trace   *OperationSelection `goblet:"trace" json:"trace,omitempty" yaml:"trace,omitempty"`
}

func (*PathSelection) AddByMethod

func (p *PathSelection) AddByMethod(name string, selection ...*OperationSelection) *OperationSelection

func (*PathSelection) GetByMethod

func (p *PathSelection) GetByMethod(name string) *OperationSelection

type RequestBodySelection

type RequestBodySelection struct {
	Default string                         `goblet:"default" json:"default,omitempty"`
	Inputs  map[string]*ParameterSelection `goblet:"inputs" json:"inputs,omitempty"`
	Order   []string                       `goblet:"order" json:"order,omitempty"` //参数的渲染顺序,可调
}

type ResponseSelection

type ResponseSelection struct {
	Default string `goblet:"default" json:"default"`
}

type SecuritySelection

type SecuritySelection struct {
	Variables map[string]string `goblet:"variables" json:"variables"`
	Default   int               `goblet:"default" json:"default"`
}

type SignedCookieSession

type SignedCookieSession struct {
	Source     string
	SourceSign string
}

type TestResult

type TestResult struct {
	Raw      string            `json:"raw"` //原始的返回值
	Url      string            `json:"url"`
	Header   http.Header       `json:"Header"`
	Request  interface{}       `json:"request"`
	Response json.RawMessage   `json:"response"`
	Def      string            `json:"def"`
	Parsed   interface{}       `json:"parsed"`
	X509     *x509.Certificate `json:"x509"`
	Type     string            `json:"type"`
}

Jump to

Keyboard shortcuts

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