openapi

package
v0.0.0-...-dbf91d7 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBaseType

func IsBaseType(t string) (is bool, openApiType string)

all type of openapi: array, boolean, integer, number , object, string

Types

type AllOfSchema

type AllOfSchema struct {
	AllOf []Schema `json:"allOf"`

	// AllOf 也有Properties字段, 这是为了在js中使用此字段转为params数组
	Properties jsonordered.MapSlice `json:"x-properties"`
	IsSchema   bool                 `json:"x-schema"`
}

type AnySchema

type AnySchema struct {
	IsSchema    bool          `json:"x-schema,omitempty"`
	IsAny       bool          `json:"x-any,omitempty"`
	Description string        `json:"description,omitempty"`
	OneOf       []interface{} `json:"oneOf"`
}

type ArraySchema

type ArraySchema struct {
	Ref         string `json:"$ref,omitempty"`
	Type        string `json:"type"`
	Description string `json:"description,omitempty"`
	Items       Schema `json:"items"`
	IsSchema    bool   `json:"x-schema"`
}

type ErrSchema

type ErrSchema struct {
	IsSchema bool `json:"x-schema,omitempty"`
	// 用于强提示,此字段在editor中会报错。
	Error string `json:"error,omitempty"`
	// 用于弱提示,此字段在editor中不会报错。
	XError string `json:"x-error,omitempty"`
	Ref    string `json:"$ref,omitempty"`
}

type GoAstToSchema

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

type GoExprWithPath

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

func (*GoExprWithPath) GetMember

func (g *GoExprWithPath) GetMember(k string) (interface{}, error)

如果类型是 结构体, 则还需要查询到子方法或者子成员

func (*GoExprWithPath) Key

func (expr *GoExprWithPath) Key() (string, error)

Key 返回某表达式的唯一标识. 用于判断是否重复, 如 ref的生成, 递归判断. 返回key格式如 pkgname.Ident, e.g. github.com/gopenapi/gopenapi/internal/delivery/http/handler.PetHandler 例:

  • *model.Pet, 返回 xxx/model.Pet
  • model.Pet , 返回 xxx/model.Pet
  • Pet , 返回 {当前包}.Pet
  • 其他情况下则认为没有唯一标识.

func (*GoExprWithPath) MarshalJSON

func (g *GoExprWithPath) MarshalJSON() ([]byte, error)

在解析成json时(在js脚本中使用), 需要解析成js脚本能使用的格式, 即 GoStruct

type GoStruct

type GoStruct struct {
	// FullDoc 是整个注释(除去变量部分)
	FullDoc string `json:"doc"`

	// FullDoc的第一句
	Summary string `json:"summary"`
	// FullDoc除了第一个的剩下注释
	Description string `json:"description"`

	// Meta 是变量部分, 应该使用json序列化后(给js脚本)使用
	Meta jsonordered.MapSlice `json:"meta"`

	Schema    Schema `json:"schema,omitempty"`
	XGoStruct bool   `json:"x-gostruct"`
}

处理 go 注释为元数据 这个值是js脚本的参数, 故需要正确的被json序列化.

type IdentSchema

type IdentSchema struct {
	Ref string `json:"$ref,omitempty"`

	Type        string        `json:"type"`
	Description string        `json:"description,omitempty"`
	Default     interface{}   `json:"default,omitempty"`
	Enum        []interface{} `json:"enum,omitempty"`
	IsSchema    bool          `json:"x-schema,omitempty"`

	Example interface{} `json:"example,omitempty"`
}

基础类型, string / int

type Modify

type Modify struct {
	Key  string
	Args []interface{}
}

type NotFoundGoExpr

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

NotFoundGoExpr 用于表示没有找到Go表达式

如 schema(apkg.xxx), 如果apkg中没有找到xxx, 则会返回 NotFoundGoExpr
不返回nil的原因是需要有更多的信息用于友好提示

type ObjectProp

type ObjectProp struct {
	Schema Schema               `json:"schema"`
	Meta   jsonordered.MapSlice `json:"meta,omitempty"`
	Tag    map[string]string    `json:"tag,omitempty"`
}

ObjectProp 对象的成员

type ObjectSchema

type ObjectSchema struct {
	Ref         string               `json:"$ref,omitempty"`
	Type        string               `json:"type"`
	Description string               `json:"description,omitempty"`
	Properties  jsonordered.MapSlice `json:"properties"`
	Example     interface{}          `json:"example,omitempty"`

	Modify   []Modify `json:"modify,omitempty"`
	IsSchema bool     `json:"x-schema,omitempty"`
}

func (*ObjectSchema) GetMember

func (o *ObjectSchema) GetMember(k string) (interface{}, error)

实现装饰器语法 schema(model.x).require('id','name', any)

type OpenApi

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

func NewOpenApi

func NewOpenApi(gomodFile string, jsFile string) (*OpenApi, error)

func (*OpenApi) CompleteYaml

func (o *OpenApi) CompleteYaml(inYaml string, typ OutPutFormat) (dest string, err error)

完成openapi, 入口

type OutPutFormat

type OutPutFormat int
const Json OutPutFormat = 2
const Yaml OutPutFormat = 1

type ParamsItem

type ParamsItem struct {
	// From 表示此item来至那, 如 go
	From        string               `json:"_from"`
	Name        string               `json:"name"`
	Tag         map[string]string    `json:"tag"`
	Description string               `json:"description"`
	Meta        jsonordered.MapSlice `json:"meta,omitempty"`
	Schema      Schema               `json:"schema"`
	// Error 存储错误,用于友好提示
	Error string `json:"error,omitempty"`
}

从go结构体能读出的数据, 用于parameters

func (*ParamsItem) ToYaml

func (t *ParamsItem) ToYaml(useTag string) []yaml.MapItem

type ParamsList

type ParamsList []ParamsItem

openapi.params格式

func (ParamsList) ToYaml

func (p ParamsList) ToYaml(useTag string) interface{}

type PkgGetter

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

PkgGetter 实现了 GetMember 接口, 用来给js解析器执行 member 语法. 对应的语法如下 model.X

func (PkgGetter) GetMember

func (p PkgGetter) GetMember(k string) (interface{}, error)

GetMember 返回某个包中的定义, 返回 NotFoundGoExpr or GoExprWithPath

func (PkgGetter) GetStruct

func (p PkgGetter) GetStruct(k string) (def *goast.Def, exist bool, err error)

type Schema

type Schema interface {
	// contains filtered or unexported methods
}

type XData

type XData struct {
	Summary     string
	Description string

	Meta map[string]interface{}
}

Jump to

Keyboard shortcuts

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