Documentation
¶
Index ¶
- Variables
- func RegisterHTTP(server *kratosHTTP.Server, registry *Registry, opts HTTPOptions) error
- type Document
- type HTTPOptions
- type OpenAPI
- func (o *OpenAPI) GetOperation(ctx context.Context, path, method string) (*dto.OpenAPIOperationDocument, error)
- func (o *OpenAPI) Service(ctx context.Context, path, method string) (dto.OpenAPIService, bool)
- func (o *OpenAPI) Services(ctx context.Context, serviceCode string) ([]dto.OpenAPIService, error)
- type Registry
- func (r *Registry) DocumentByOperationForLocale(locale, path, method string) (Document, bool)
- func (r *Registry) DocumentsByLocale(locale string) []Document
- func (r *Registry) DocumentsForLocale(locale string) []Document
- func (r *Registry) Locales() []string
- func (r *Registry) Register(documents ...Document) error
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 (*OpenAPI) GetOperation ¶
func (o *OpenAPI) GetOperation(ctx context.Context, path, method string) (*dto.OpenAPIOperationDocument, error)
GetOperation 按 HTTP 操作查询 OpenAPI 接口文档。
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry 保存 OpenAPI 文档及 HTTP 操作与文档的归属关系。
func NewRegistry ¶
NewRegistry 根据模块 OpenAPI 资源创建注册表。
func (*Registry) DocumentByOperationForLocale ¶
DocumentByOperationForLocale 按语言查询 HTTP 操作所属 OpenAPI 文档。
func (*Registry) DocumentsByLocale ¶
DocumentsByLocale 返回指定语言的精确 OpenAPI 文档,不执行默认语言回退。
func (*Registry) DocumentsForLocale ¶
DocumentsForLocale 返回指定语言的 OpenAPI 文档,并在缺少翻译时回退默认文档。
Click to show internal directories.
Click to hide internal directories.