Documentation
¶
Index ¶
- func ExtractAllModuleNames(openapi *OpenAPI3) ([]string, error)
- func GenerateFieldName(name string) string
- func GenerateGoType(schema *Schema, openapi *OpenAPI3) string
- func GenerateGoTypeFromParam(param Parameter) string
- func GenerateGoTypeFromSchema(schema *Schema) string
- func GenerateHandlerName(op APIOperation) string
- func GenerateJSONTag(fieldName string) string
- func GenerateMethodName(op APIOperation) string
- func GenerateRoute(op APIOperation, baseRoute string) string
- func GenerateValidationRules(schema *Schema) string
- func ToSnakeCase(str string) string
- type APIModule
- type APIOperation
- type Components
- type ErrorCategory
- type ErrorCode
- type ErrorCodeMeta
- type ErrorService
- type Field
- type Info
- type MediaType
- type OpenAPI3
- type Operation
- type Parameter
- type PathItem
- type RequestBody
- type Response
- type ResponseData
- type Schema
- type Server
- type Tag
- type XErrorCodes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractAllModuleNames ¶
ExtractAllModuleNames 从OpenAPI文档中提取所有模块名
func GenerateGoType ¶
GenerateGoType 生成Go类型
func GenerateGoTypeFromParam ¶
GenerateGoTypeFromParam 从参数生成Go类型
func GenerateGoTypeFromSchema ¶
GenerateGoTypeFromSchema 从Schema生成Go类型
func GenerateHandlerName ¶
func GenerateHandlerName(op APIOperation) string
GenerateHandlerName 生成处理器名
func GenerateRoute ¶
func GenerateRoute(op APIOperation, baseRoute string) string
GenerateRoute 生成路由
func GenerateValidationRules ¶
GenerateValidationRules 生成验证规则
Types ¶
type APIModule ¶
type APIModule struct {
Name string
Tag string
Operations []APIOperation
Schemas map[string]*Schema
Parameters map[string]*Parameter
RequestBodies map[string]*RequestBody
}
API模块信息
type APIOperation ¶
type APIOperation struct {
Method string
Path string
Summary string
Description string
OperationID string
Parameters []Parameter
RequestBody *RequestBody
Responses map[string]Response
Tag string
XErrorCodes []ErrorCode
// 生成相关字段
MethodName string
ResponseData *ResponseData
HasRequestBodyOrQuery bool
HasPathParams bool
QueryParameters []Parameter
}
type Components ¶
type Components struct {
Schemas map[string]*Schema `yaml:"schemas,omitempty" json:"schemas,omitempty"`
Parameters map[string]*Parameter `yaml:"parameters,omitempty" json:"parameters,omitempty"`
Responses map[string]*Response `yaml:"responses,omitempty" json:"responses,omitempty"`
RequestBodies map[string]*RequestBody `yaml:"requestBodies,omitempty" json:"requestBodies,omitempty"`
}
type ErrorCategory ¶
type ErrorCategory struct {
Key string `yaml:"key" json:"key"`
Name string `yaml:"name" json:"name"`
HTTPStatus int `yaml:"http_status" json:"http_status"`
}
ErrorCategory 错误类别
type ErrorCode ¶
type ErrorCode struct {
Code int `yaml:"code" json:"code"`
Message string `yaml:"message" json:"message"`
HTTPStatus int `yaml:"http_status,omitempty" json:"http_status,omitempty"`
}
ErrorCode 错误码
type ErrorCodeMeta ¶
type ErrorCodeMeta struct {
Name string `yaml:"name" json:"name"`
Version string `yaml:"version" json:"version"`
UpdatedAt string `yaml:"updated_at" json:"updated_at"`
Pattern string `yaml:"pattern" json:"pattern"`
PatternDesc string `yaml:"pattern_desc" json:"pattern_desc"`
HTTPStatusPolicy string `yaml:"http_status_policy" json:"http_status_policy"`
}
ErrorCodeMeta 错误码元信息
type ErrorService ¶
type ErrorService struct {
Key string `yaml:"key" json:"key"`
Name string `yaml:"name" json:"name"`
}
ErrorService 错误服务
type Field ¶
type MediaType ¶
type MediaType struct {
Schema *Schema `yaml:"schema,omitempty" json:"schema,omitempty"`
}
type OpenAPI3 ¶
type OpenAPI3 struct {
OpenAPI string `yaml:"openapi" json:"openapi"`
Info Info `yaml:"info" json:"info"`
Servers []Server `yaml:"servers,omitempty" json:"servers,omitempty"`
Paths map[string]PathItem `yaml:"paths" json:"paths"`
Components Components `yaml:"components,omitempty" json:"components,omitempty"`
Tags []Tag `yaml:"tags,omitempty" json:"tags,omitempty"`
XErrorCodes *XErrorCodes `yaml:"x-error-codes,omitempty" json:"x-error-codes,omitempty"`
}
OpenAPI3 结构定义
func ParseOpenAPI3 ¶
ParseOpenAPI3 解析OpenAPI3文档
type Operation ¶
type Operation struct {
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
Summary string `yaml:"summary,omitempty" json:"summary,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
OperationID string `yaml:"operationId,omitempty" json:"operationId,omitempty"`
Parameters []Parameter `yaml:"parameters,omitempty" json:"parameters,omitempty"`
RequestBody *RequestBody `yaml:"requestBody,omitempty" json:"requestBody,omitempty"`
Responses map[string]Response `yaml:"responses" json:"responses"`
XErrorCodes []ErrorCode `yaml:"x-error-codes,omitempty" json:"x-error-codes,omitempty"`
}
type Parameter ¶
type Parameter struct {
Name string `yaml:"name" json:"name"`
In string `yaml:"in" json:"in"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Required bool `yaml:"required,omitempty" json:"required,omitempty"`
Schema *Schema `yaml:"schema,omitempty" json:"schema,omitempty"`
Ref string `yaml:"$ref,omitempty" json:"$ref,omitempty"`
// 生成相关字段
GoType string `yaml:"-" json:"-"`
FieldName string `yaml:"-" json:"-"`
ValidationRules string `yaml:"-" json:"-"`
}
type PathItem ¶
type PathItem struct {
Get *Operation `yaml:"get,omitempty" json:"get,omitempty"`
Post *Operation `yaml:"post,omitempty" json:"post,omitempty"`
Put *Operation `yaml:"put,omitempty" json:"put,omitempty"`
Delete *Operation `yaml:"delete,omitempty" json:"delete,omitempty"`
Patch *Operation `yaml:"patch,omitempty" json:"patch,omitempty"`
}
type RequestBody ¶
type RequestBody struct {
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Required bool `yaml:"required,omitempty" json:"required,omitempty"`
Content map[string]MediaType `yaml:"content" json:"content"`
Ref string `yaml:"$ref,omitempty" json:"$ref,omitempty"`
// 生成相关字段
Fields []Field `yaml:"-" json:"-"`
}
type ResponseData ¶
type Schema ¶
type Schema struct {
Type string `yaml:"type,omitempty" json:"type,omitempty"`
Format string `yaml:"format,omitempty" json:"format,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Properties map[string]*Schema `yaml:"properties,omitempty" json:"properties,omitempty"`
Items *Schema `yaml:"items,omitempty" json:"items,omitempty"`
Required []string `yaml:"required,omitempty" json:"required,omitempty"`
Ref string `yaml:"$ref,omitempty" json:"$ref,omitempty"`
Default interface{} `yaml:"default,omitempty" json:"default,omitempty"`
// OpenAPI 3.1 组合模式支持
AllOf []*Schema `yaml:"allOf,omitempty" json:"allOf,omitempty"`
OneOf []*Schema `yaml:"oneOf,omitempty" json:"oneOf,omitempty"`
AnyOf []*Schema `yaml:"anyOf,omitempty" json:"anyOf,omitempty"`
Not *Schema `yaml:"not,omitempty" json:"not,omitempty"`
// OpenAPI 3.1 新增字段
Nullable *bool `yaml:"nullable,omitempty" json:"nullable,omitempty"`
Enum []string `yaml:"enum,omitempty" json:"enum,omitempty"`
Const string `yaml:"const,omitempty" json:"const,omitempty"`
Examples []string `yaml:"examples,omitempty" json:"examples,omitempty"`
// 验证相关字段
MinLength *int `yaml:"minLength,omitempty" json:"minLength,omitempty"`
MaxLength *int `yaml:"maxLength,omitempty" json:"maxLength,omitempty"`
Pattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"`
Minimum *float64 `yaml:"minimum,omitempty" json:"minimum,omitempty"`
Maximum *float64 `yaml:"maximum,omitempty" json:"maximum,omitempty"`
MinItems *int `yaml:"minItems,omitempty" json:"minItems,omitempty"`
MaxItems *int `yaml:"maxItems,omitempty" json:"maxItems,omitempty"`
}
func ResolveSchemaRef ¶
ResolveSchemaRef 解析Schema引用
type XErrorCodes ¶
type XErrorCodes struct {
Meta ErrorCodeMeta `yaml:"meta" json:"meta"`
Categories map[string]ErrorCategory `yaml:"categories" json:"categories"`
Services map[string]ErrorService `yaml:"services" json:"services"`
}
XErrorCodes 错误码注册表
Click to show internal directories.
Click to hide internal directories.