Documentation ¶
Overview ¶
Package goai 实现并提供了针对 OpenApi 规范的文档生成功能。
Index ¶
- Constants
- type AddInput
- type Callback
- type CallbackRef
- type Callbacks
- type Components
- type Config
- type Contact
- type Content
- type Discriminator
- type Encoding
- type Example
- type ExampleRef
- type Examples
- type ExternalDocs
- type Header
- type HeaderRef
- type Headers
- type Info
- type License
- type Link
- type LinkRef
- type Links
- type MediaType
- type OAuthFlow
- type OAuthFlows
- type OpenApiV3
- type Operation
- type Parameter
- type ParameterRef
- type Parameters
- type ParametersMap
- type Path
- type Paths
- type RequestBodies
- type RequestBody
- type RequestBodyRef
- type Response
- type ResponseRef
- type Responses
- type Schema
- type SchemaRef
- type SchemaRefs
- type Schemas
- func (s *Schemas) Clone() Schemas
- func (s *Schemas) Get(name string) *SchemaRef
- func (s *Schemas) Map() map[string]SchemaRef
- func (s Schemas) MarshalJSON() ([]byte, error)
- func (s *Schemas) Removes(names []interface{})
- func (s *Schemas) X设置值(name string, ref SchemaRef)
- func (s *Schemas) X遍历(f func(key string, ref SchemaRef) bool)
- type SecurityRequirement
- type SecurityRequirements
- type SecurityScheme
- type SecuritySchemeRef
- type SecuritySchemes
- type Server
- type ServerVariable
- type Servers
- type Tag
- type Tags
- type XExtensions
Constants ¶
const ( TypeInteger = `integer` TypeNumber = `number` TypeBoolean = `boolean` TypeArray = `array` TypeString = `string` TypeFile = `file` TypeObject = `object` FormatInt32 = `int32` FormatInt64 = `int64` FormatDouble = `double` FormatByte = `byte` FormatBinary = `binary` FormatDate = `date` FormatDateTime = `date-time` FormatPassword = `password` )
const ( ParameterInHeader = `header` ParameterInPath = `path` ParameterInQuery = `query` ParameterInCookie = `cookie` )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddInput ¶
type AddInput struct { Path string // Path 指定自定义路径,如果在结构体标签的 Meta 中未配置此路径,则使用该指定路径。 Prefix string // Prefix 指定自定义路由路径前缀,它将与结构体标签中 Meta 的 path 标签相结合。 Method string // Method 指定自定义的 HTTP 方法,如果在结构体标签的 Meta 中未配置该方法时使用。 Object interface{} // Object 可以是结构体实例或路由函数。 }
AddInput 是函数 OpenApiV3.Add 的结构化参数。
type CallbackRef ¶
func (CallbackRef) MarshalJSON ¶
func (r CallbackRef) MarshalJSON() ([]byte, error)
type Callbacks ¶
type Callbacks map[string]*CallbackRef
type Components ¶
type Components struct { Schemas Schemas `json:"schemas,omitempty"` Parameters ParametersMap `json:"parameters,omitempty"` Headers Headers `json:"headers,omitempty"` RequestBodies RequestBodies `json:"requestBodies,omitempty"` Responses Responses `json:"responses,omitempty"` SecuritySchemes SecuritySchemes `json:"securitySchemes,omitempty"` Examples Examples `json:"examples,omitempty"` Links Links `json:"links,omitempty"` Callbacks Callbacks `json:"callbacks,omitempty"` }
Components是按照OpenAPI/Swagger 3.0标准指定的。
type Config ¶
type Config struct { ReadContentTypes []string // ReadContentTypes 指定了在未配置 MIME 类型时默认用于消费的 MIME 类型。 WriteContentTypes []string // WriteContentTypes 指定在未配置 MIME 类型时生成内容时的默认 MIME 类型。 CommonRequest interface{} // 通用请求结构,适用于所有路径。 CommonRequestDataField string // 该注释描述了一个通用请求字段名称,它将在特定业务请求结构中被替换。例如:`Data`, `Request`。 // 翻译为: // 这是一个通用请求字段名,通常会在特定的业务请求结构中用相应的内容进行替换。例如:`Data`、`Request`。 CommonResponse interface{} // 通用响应结构,适用于所有路径。 CommonResponseDataField string // 常用的响应字段名称,将会被替换为特定业务响应结构。例如:`Data`、`Response`。 IgnorePkgPath bool // 忽略包名以获取模式名称。 }
Config 为 OpenApiV3 的实现提供了额外的配置功能。
type Contact ¶
type Contact struct { Name string `json:"name,omitempty"` URL string `json:"url,omitempty"` Email string `json:"email,omitempty"` }
Contact 是由 OpenAPI/Swagger 标准版本 3.0 规定的联系信息结构体。
type Discriminator ¶
type Discriminator struct { PropertyName string `json:"propertyName"` Mapping map[string]string `json:"mapping,omitempty"` }
Discriminator 是由 OpenAPI/Swagger 3.0 标准指定的。
type Encoding ¶
type Encoding struct { ContentType string `json:"contentType,omitempty"` Headers Headers `json:"headers,omitempty"` Style string `json:"style,omitempty"` Explode *bool `json:"explode,omitempty"` AllowReserved bool `json:"allowReserved,omitempty"` }
编码由 OpenAPI/Swagger 3.0 标准指定。
type Example ¶
type Example struct { Summary string `json:"summary,omitempty"` Description string `json:"description,omitempty"` Value interface{} `json:"value,omitempty"` ExternalValue string `json:"externalValue,omitempty"` }
示例由OpenAPI/Swagger 3.0标准指定。
type ExampleRef ¶
func (ExampleRef) MarshalJSON ¶
func (r ExampleRef) MarshalJSON() ([]byte, error)
type Examples ¶
type Examples map[string]*ExampleRef
type ExternalDocs ¶
type ExternalDocs struct { URL string `json:"url,omitempty"` Description string `json:"description,omitempty"` }
ExternalDocs 是由 OpenAPI/Swagger 标准 3.0 版本定义的。
func (*ExternalDocs) UnmarshalValue ¶
func (ed *ExternalDocs) UnmarshalValue(value interface{}) error
type Header ¶
type Header struct {
Parameter
}
Header 按照 OpenAPI/Swagger 3.0 标准进行指定。 详情请参阅 https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#headerObject
type HeaderRef ¶
func (HeaderRef) MarshalJSON ¶
type Info ¶
type Info struct { Title string `json:"title"` Description string `json:"description,omitempty"` TermsOfService string `json:"termsOfService,omitempty"` Contact *Contact `json:"contact,omitempty"` License *License `json:"license,omitempty"` Version string `json:"version"` }
Info 由 OpenAPI/Swagger 标准版本 3.0 规定。
type Link ¶
type Link struct { OperationID string `json:"operationId,omitempty"` OperationRef string `json:"operationRef,omitempty"` Description string `json:"description,omitempty"` Parameters map[string]interface{} `json:"parameters,omitempty"` Server *Server `json:"server,omitempty"` RequestBody interface{} `json:"requestBody,omitempty"` }
Link 是由 OpenAPI/Swagger 标准版本 3.0 规定的。
type LinkRef ¶
func (LinkRef) MarshalJSON ¶
type MediaType ¶
type MediaType struct { Schema *SchemaRef `json:"schema,omitempty"` Example interface{} `json:"example,omitempty"` Examples Examples `json:"examples,omitempty"` Encoding map[string]*Encoding `json:"encoding,omitempty"` }
MediaType 是由 OpenAPI/Swagger 3.0 标准指定的。
type OAuthFlows ¶
type OpenApiV3 ¶
type OpenApiV3 struct { Config Config `json:"-"` OpenAPI string `json:"openapi"` Components Components `json:"components,omitempty"` Info Info `json:"info"` Paths Paths `json:"paths"` Security *SecurityRequirements `json:"security,omitempty"` Servers *Servers `json:"servers,omitempty"` Tags *Tags `json:"tags,omitempty"` ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` }
OpenApiV3 是从以下网址定义的结构体: https://swagger.io/specification/ https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md (译:OpenApiV3 结构体是根据以下链接中定义的 OpenAPI 3.0 规范实现的:) (https://swagger.io/specification/,以及 OpenAPI 3.0 的具体版本规范:) (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md)
type Operation ¶
type Operation struct { Tags []string `json:"tags,omitempty"` Summary string `json:"summary,omitempty"` Description string `json:"description,omitempty"` OperationID string `json:"operationId,omitempty"` Parameters Parameters `json:"parameters,omitempty"` RequestBody *RequestBodyRef `json:"requestBody,omitempty"` Responses Responses `json:"responses"` Deprecated bool `json:"deprecated,omitempty"` Callbacks *Callbacks `json:"callbacks,omitempty"` Security *SecurityRequirements `json:"security,omitempty"` Servers *Servers `json:"servers,omitempty"` ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` XExtensions XExtensions `json:"-"` }
Operation 表示由 OpenAPI/Swagger 3.0 标准定义的 "操作"。
func (Operation) MarshalJSON ¶
type Parameter ¶
type Parameter struct { Name string `json:"name,omitempty"` In string `json:"in,omitempty"` Description string `json:"description,omitempty"` Style string `json:"style,omitempty"` Explode *bool `json:"explode,omitempty"` AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` AllowReserved bool `json:"allowReserved,omitempty"` Deprecated bool `json:"deprecated,omitempty"` Required bool `json:"required,omitempty"` Schema *SchemaRef `json:"schema,omitempty"` Example interface{} `json:"example,omitempty"` Examples *Examples `json:"examples,omitempty"` Content *Content `json:"content,omitempty"` XExtensions XExtensions `json:"-"` }
参数遵循OpenAPI/Swagger 3.0标准指定。 详情请参阅:https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#parameterObject
func (Parameter) MarshalJSON ¶
type ParameterRef ¶
func (ParameterRef) MarshalJSON ¶
func (r ParameterRef) MarshalJSON() ([]byte, error)
type ParametersMap ¶
type ParametersMap map[string]*ParameterRef
type Path ¶
type Path struct { Ref string `json:"$ref,omitempty"` Summary string `json:"summary,omitempty"` Description string `json:"description,omitempty"` Connect *Operation `json:"connect,omitempty"` Delete *Operation `json:"delete,omitempty"` Get *Operation `json:"get,omitempty"` Head *Operation `json:"head,omitempty"` Options *Operation `json:"options,omitempty"` Patch *Operation `json:"patch,omitempty"` Post *Operation `json:"post,omitempty"` Put *Operation `json:"put,omitempty"` Trace *Operation `json:"trace,omitempty"` Servers Servers `json:"servers,omitempty"` Parameters Parameters `json:"parameters,omitempty"` XExtensions XExtensions `json:"-"` }
Path 是由 OpenAPI/Swagger 标准版本 3.0 规定的。
func (Path) MarshalJSON ¶
MarshalJSON 实现了 json.Marshal 接口所需的 MarshalJSON 方法。
type RequestBodies ¶
type RequestBodies map[string]*RequestBodyRef
type RequestBody ¶
type RequestBody struct { Description string `json:"description,omitempty"` Required bool `json:"required,omitempty"` Content Content `json:"content,omitempty"` }
RequestBody 由 OpenAPI/Swagger 3.0 标准指定。
type RequestBodyRef ¶
type RequestBodyRef struct { Ref string Value *RequestBody }
func (RequestBodyRef) MarshalJSON ¶
func (r RequestBodyRef) MarshalJSON() ([]byte, error)
type Response ¶
type Response struct { Description string `json:"description"` Headers Headers `json:"headers,omitempty"` Content Content `json:"content,omitempty"` Links Links `json:"links,omitempty"` XExtensions XExtensions `json:"-"` }
Response 由 OpenAPI/Swagger 3.0 标准指定。
func (Response) MarshalJSON ¶
type ResponseRef ¶
func (ResponseRef) MarshalJSON ¶
func (r ResponseRef) MarshalJSON() ([]byte, error)
type Schema ¶
type Schema struct { OneOf SchemaRefs `json:"oneOf,omitempty"` AnyOf SchemaRefs `json:"anyOf,omitempty"` AllOf SchemaRefs `json:"allOf,omitempty"` Not *SchemaRef `json:"not,omitempty"` Type string `json:"type,omitempty"` Title string `json:"title,omitempty"` Format string `json:"format,omitempty"` Description string `json:"description,omitempty"` Enum []interface{} `json:"enum,omitempty"` Default interface{} `json:"default,omitempty"` Example interface{} `json:"example,omitempty"` ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` UniqueItems bool `json:"uniqueItems,omitempty"` ExclusiveMin bool `json:"exclusiveMinimum,omitempty"` ExclusiveMax bool `json:"exclusiveMaximum,omitempty"` Nullable bool `json:"nullable,omitempty"` ReadOnly bool `json:"readOnly,omitempty"` WriteOnly bool `json:"writeOnly,omitempty"` AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` XML interface{} `json:"xml,omitempty"` Deprecated bool `json:"deprecated,omitempty"` Min *float64 `json:"minimum,omitempty"` Max *float64 `json:"maximum,omitempty"` MultipleOf *float64 `json:"multipleOf,omitempty"` MinLength uint64 `json:"minLength,omitempty"` MaxLength *uint64 `json:"maxLength,omitempty"` Pattern string `json:"pattern,omitempty"` MinItems uint64 `json:"minItems,omitempty"` MaxItems *uint64 `json:"maxItems,omitempty"` Items *SchemaRef `json:"items,omitempty"` Required []string `json:"required,omitempty"` Properties Schemas `json:"properties,omitempty"` MinProps uint64 `json:"minProperties,omitempty"` MaxProps *uint64 `json:"maxProperties,omitempty"` AdditionalProperties *SchemaRef `json:"additionalProperties,omitempty"` Discriminator *Discriminator `json:"discriminator,omitempty"` XExtensions XExtensions `json:"-"` ValidationRules string `json:"-"` }
Schema遵循OpenAPI/Swagger 3.0标准进行定义。
func (Schema) MarshalJSON ¶
type SchemaRef ¶
func (SchemaRef) MarshalJSON ¶
type SchemaRefs ¶
type SchemaRefs []SchemaRef
type Schemas ¶
type Schemas struct {
// contains filtered or unexported fields
}
func (Schemas) MarshalJSON ¶
type SecurityRequirement ¶
type SecurityRequirements ¶
type SecurityRequirements []SecurityRequirement
type SecurityScheme ¶
type SecurityScheme struct { Type string `json:"type,omitempty"` Description string `json:"description,omitempty"` Name string `json:"name,omitempty"` In string `json:"in,omitempty"` Scheme string `json:"scheme,omitempty"` BearerFormat string `json:"bearerFormat,omitempty"` Flows *OAuthFlows `json:"flows,omitempty"` OpenIdConnectUrl string `json:"openIdConnectUrl,omitempty"` }
type SecuritySchemeRef ¶
type SecuritySchemeRef struct { Ref string Value *SecurityScheme }
func (SecuritySchemeRef) MarshalJSON ¶
func (r SecuritySchemeRef) MarshalJSON() ([]byte, error)
type SecuritySchemes ¶
type SecuritySchemes map[string]SecuritySchemeRef
type Server ¶
type Server struct { URL string `json:"url"` Description string `json:"description,omitempty"` Variables map[string]*ServerVariable `json:"variables,omitempty"` }
Server 按照 OpenAPI/Swagger 3.0 标准定义。
type ServerVariable ¶
type ServerVariable struct { Enum []string `json:"enum,omitempty"` Default string `json:"default,omitempty"` Description string `json:"description,omitempty"` }
ServerVariable 是由 OpenAPI/Swagger 3.0 标准指定的。
type Tag ¶
type Tag struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` ExternalDocs *ExternalDocs `json:"externalDocs,omitempty"` }
Tag 是由 OpenAPI/Swagger 3.0 标准指定的。
Source Files ¶
- goai.go
- goai_callback.go
- goai_components.go
- goai_config.go
- goai_example.go
- goai_external_docs.go
- goai_header.go
- goai_info.go
- goai_link.go
- goai_mediatype.go
- goai_operation.go
- goai_parameter.go
- goai_parameter_ref.go
- goai_path.go
- goai_requestbody.go
- goai_response.go
- goai_response_ref.go
- goai_security.go
- goai_server.go
- goai_shema.go
- goai_shema_ref.go
- goai_shemas.go
- goai_tags.go
- goai_xextensions.go