From 2f4e6851f333ffa1b978b35d8b2bec38026f4d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 6 Jan 2026 11:11:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90openapi=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openapi/generate.go | 94 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/openapi/generate.go b/openapi/generate.go index 2bf5a7d..ce5edb9 100644 --- a/openapi/generate.go +++ b/openapi/generate.go @@ -7,12 +7,102 @@ // Date : 2026-01-05 17:20 package openapi +import ( + "git.zhangdeman.cn/zhangdeman/consts" + "github.com/getkin/kin-openapi/openapi3" +) + +// NewGenerate 生成文档实例 func NewGenerate() *Generate { - return &Generate{} + return &Generate{ + doc: &openapi3.T{ + Extensions: map[string]any{}, + OpenAPI: "openapi", + Components: &openapi3.Components{ + Extensions: map[string]any{}, + Origin: &openapi3.Origin{ + Key: &openapi3.Location{ + Line: 0, + Column: 0, + }, + Fields: make(map[string]openapi3.Location), + }, + Schemas: map[string]*openapi3.SchemaRef{}, + Parameters: map[string]*openapi3.ParameterRef{}, + Headers: map[string]*openapi3.HeaderRef{}, + RequestBodies: map[string]*openapi3.RequestBodyRef{}, + Responses: map[string]*openapi3.ResponseRef{}, + SecuritySchemes: map[string]*openapi3.SecuritySchemeRef{}, + Examples: map[string]*openapi3.ExampleRef{}, + Links: map[string]*openapi3.LinkRef{}, + Callbacks: map[string]*openapi3.CallbackRef{}, + }, + Info: &openapi3.Info{ + Extensions: map[string]any{}, + Origin: &openapi3.Origin{ + Key: &openapi3.Location{ + Line: 0, + Column: 0, + }, + Fields: make(map[string]openapi3.Location), + }, + Title: "服务 API接口 文档", + Description: "服务 API接口 文档", + TermsOfService: "", + Contact: &openapi3.Contact{ + Extensions: map[string]any{}, + Origin: &openapi3.Origin{ + Key: &openapi3.Location{ + Line: 0, + Column: 0, + }, + Fields: make(map[string]openapi3.Location), + }, + Name: "developer", + URL: "", + Email: "developer@test.com", + }, + License: &openapi3.License{ + Extensions: map[string]any{}, + Origin: &openapi3.Origin{ + Key: &openapi3.Location{ + Line: 0, + Column: 0, + }, + Fields: make(map[string]openapi3.Location), + }, + Name: consts.LicenseApache20, + URL: consts.LicenseUrlTable[consts.LicenseApache20], + }, + Version: "0.0.1", + }, + Paths: &openapi3.Paths{ + Extensions: map[string]any{}, + Origin: &openapi3.Origin{ + Key: &openapi3.Location{ + Line: 0, + Column: 0, + }, + Fields: make(map[string]openapi3.Location), + }, + }, + Security: []openapi3.SecurityRequirement{}, + Servers: []*openapi3.Server{}, + Tags: []*openapi3.Tag{}, + ExternalDocs: &openapi3.ExternalDocs{ + Extensions: map[string]any{}, + Origin: nil, + Description: "", + URL: "", + }, + }, + } } // Generate 生成 OpenApi 标准规范的文档 -type Generate struct{} +type Generate struct { + doc *openapi3.T +} // AddApiDoc 添加接口文档 func (g *Generate) AddApiDoc(request any, response any) error {