openapi

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package openapi 管理当前进程启用的 OpenAPI 文档。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHTTP

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

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

Types

type Document

type Document struct {
	// Key 是文档的稳定唯一标识。
	Key string
	// Name 是文档的展示名称。
	Name 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(*stdhttp.Request) bool
}

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

type Registry

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

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

func NewRegistry

func NewRegistry(documents ...Document) (*Registry, error)

NewRegistry 创建 OpenAPI 文档注册表。

func (*Registry) DocumentByOperation

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

DocumentByOperation 根据 HTTP 路径和方法查询所属 OpenAPI 文档。

func (*Registry) Documents

func (r *Registry) Documents() []Document

Documents 返回按注册顺序排列的 OpenAPI 文档快照。

func (*Registry) Register

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

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

Jump to

Keyboard shortcuts

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