openapi

package
v0.0.0-...-69a0400 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package openapi 对 openapi 的再处理

Index

Constants

View Source
const ComponentSchemaPrefix = "#/components/schemas/"

Variables

This section is empty.

Functions

func NewArraySchemaRef

func NewArraySchemaRef(ref *openapi3.SchemaRef) *openapi3.SchemaRef

NewArraySchemaRef 将 ref 包装成数组

func NewAttrSchemaRef

func NewAttrSchemaRef(ref *openapi3.SchemaRef, title, desc string, xml *openapi3.XML, nullable bool) *openapi3.SchemaRef

func NewDocSchemaRef

func NewDocSchemaRef(ref *openapi3.SchemaRef, title, desc string) *openapi3.SchemaRef

NewDocSchemaRef 将 ref 附带上文档信息

这会以 AllOf 的形式形成一个新 openapi3.SchemaRef 对象,原有的 ref 不会被破坏。

func NewNullableSchemaRef

func NewNullableSchemaRef(ref *openapi3.SchemaRef) *openapi3.SchemaRef

NewNullableSchemaRef 将 ref 包装为一个允许为空的对象

func NewSchemaRef

func NewSchemaRef(ref string, s *openapi3.Schema) *openapi3.SchemaRef

NewSchemaRef 声明 openapi3.SchemaRef

在 ref 不为空且没有 ComponentSchemaPrefix 作为前缀时会自动添加前缀,其它情况下则不改变 ref 的值。

func RefEqual

func RefEqual(r1, r2 string) bool

RefEqual 判断两个 SchemaRef.Ref 是否相等

Types

type OpenAPI

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

OpenAPI 协程安全的 OpenAPI 对象

func New

func New(ver string) *OpenAPI

func (*OpenAPI) AddAPI

func (doc *OpenAPI) AddAPI(path string, o *openapi3.Operation, method string)

AddAPI 添加一个 API

这会自动将路径参数向 PathItem 元素移动。

func (*OpenAPI) AddSchema

func (doc *OpenAPI) AddSchema(schema *openapi3.SchemaRef)

AddSchema 尝试添加一个 Schema 至 Components 中

NOTE: 仅在 schema.Ref 不为空 或是 schema.Value 不为空时才会保存,且会对不规则的 schema.Ref 进行修正。

func (*OpenAPI) Doc

func (doc *OpenAPI) Doc() *openapi3.T

func (*OpenAPI) GetSchema

func (doc *OpenAPI) GetSchema(ref string) (*openapi3.SchemaRef, bool)

GetSchema 从 Components 中查找 ref 引用的 Schema 定义

func (*OpenAPI) Merge

func (doc *OpenAPI) Merge(d *openapi3.T)

func (*OpenAPI) SaveAs

func (doc *OpenAPI) SaveAs(path string) error

SaveAs 保存为 yaml 或 json 文件

根据后缀名名确定保存的文件类型,目前仅支持 json 和 yaml。

Jump to

Keyboard shortcuts

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