openapi

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProviderSet = wire.NewSet(
	NewRegistry,
	NewOpenAPI,
)

ProviderSet 合并模块 OpenAPI 文档,并创建注册表和查询入口。

Functions

func RegisterHTTP

func RegisterHTTP(server *kratosHTTP.Server, registry *Registry, opts HTTPOptions) error

RegisterHTTP 为注册表中的每份文档挂载原文接口和独立 Swagger UI。

Types

type Document

type Document struct {
	// Key 是文档的稳定唯一标识。
	Key string
	// Name 是文档的展示名称。
	Name string
	// Locale 是文档语言,空字符串表示默认文档。
	Locale string
	// Data 是未经合并的 OpenAPI 文档内容。
	Data []byte
}

Document 描述一份可独立访问的 OpenAPI 文档。

type HTTPOptions

type HTTPOptions struct {
	// DocumentPath 是原始 OpenAPI 文档的路由前缀。
	DocumentPath string
	// SwaggerPath 是 Swagger UI 的路由前缀。
	SwaggerPath string
	// Authorizer 校验原始文档请求,nil 表示允许访问。
	Authorizer func(*http.Request) bool
}

HTTPOptions 配置 OpenAPI 原文和 Swagger UI 路由。

type OpenAPI

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

OpenAPI 实现 Core 的 OpenAPI 查询能力。

func NewOpenAPI

func NewOpenAPI(registry *Registry) *OpenAPI

NewOpenAPI 创建 OpenAPI 查询服务。

func (*OpenAPI) GetOperation

func (o *OpenAPI) GetOperation(ctx context.Context, path, method string) (*dto.OpenAPIOperationDocument, error)

GetOperation 按 HTTP 操作查询 OpenAPI 接口文档。

func (*OpenAPI) Service

func (o *OpenAPI) Service(ctx context.Context, path, method string) (dto.OpenAPIService, bool)

Service 按 HTTP 操作查询所属 OpenAPI 服务。

func (*OpenAPI) Services

func (o *OpenAPI) Services(ctx context.Context, serviceCode string) ([]dto.OpenAPIService, error)

Services 查询 Core 保存的 OpenAPI 服务。

type Registry

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

Registry 保存 OpenAPI 文档及 HTTP 操作与文档的归属关系。

func NewRegistry

func NewRegistry(resources module.OpenAPI) (*Registry, error)

NewRegistry 根据模块 OpenAPI 资源创建注册表。

func (*Registry) DocumentByOperationForLocale

func (r *Registry) DocumentByOperationForLocale(locale, path, method string) (Document, bool)

DocumentByOperationForLocale 按语言查询 HTTP 操作所属 OpenAPI 文档。

func (*Registry) DocumentsByLocale

func (r *Registry) DocumentsByLocale(locale string) []Document

DocumentsByLocale 返回指定语言的精确 OpenAPI 文档,不执行默认语言回退。

func (*Registry) DocumentsForLocale

func (r *Registry) DocumentsForLocale(locale string) []Document

DocumentsForLocale 返回指定语言的 OpenAPI 文档,并在缺少翻译时回退默认文档。

func (*Registry) Locales

func (r *Registry) Locales() []string

Locales 返回已注册的非默认 OpenAPI 语言列表。

func (*Registry) Register

func (r *Registry) Register(documents ...Document) error

Register 注册 OpenAPI 文档,重复 key 仅允许名称和内容完全一致。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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