Documentation ¶
Index ¶
- Constants
- type APIKey
- type APIKeyIn
- type Components
- type Contact
- type Discriminator
- type Encoding
- type Example
- type ExternalDocumentation
- type HTTPBase
- type HTTPBearer
- type Header
- type IOpenapiStruct
- type IReference
- type Info
- type License
- type Link
- type MediaType
- type OAuth2
- type OAuthFlowAuthorizationCode
- type OAuthFlowClientCredentials
- type OAuthFlowImplicit
- type OAuthFlowPassword
- type OAuthFlows
- type OpenAPI
- type OpenIdConnect
- type Operation
- type Parameter
- type PathItem
- type Reference
- type RequestBody
- type Response
- type Schema
- type SecurityBase
- type SecurityRequirementObject
- type SecuritySchemeType
- type Server
- type ServerVariable
- type Tag
- type XML
Constants ¶
View Source
const ( APIKeyInQuery = "query" APIKeyInHeader = "header" APIKeyInCookie = "cookie" )
View Source
const ( REF_PREFIX = "#/components/schemas/" TagName = "openapi" Description = "openapi_desc" //把description单独写 Extras = "openapi_extras" //额外的字段,和tagname一致 )
View Source
const ( ApiKey = "apiKey" Http = "http" Oauth2 = "oauth2" Openidconnect = "openIdConnect" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKey ¶
type APIKey struct { Type SecuritySchemeType `json:"type"` //默认值为APIKeyInQuery In APIKeyIn `json:"in"` Name string `json:"name"` Description string `json:"description"` }
type Components ¶
type Components struct { Schemas map[string]*Schema `json:"schemas,omitempty"` Responses map[string]*Response `json:"responses,omitempty"` // An object to hold reusable Response Objects. Parameters map[string]*Parameter `json:"parameters,omitempty"` // An object to hold reusable Parameter Objects. Examples map[string]*Example `json:"examples,omitempty"` // An object to hold reusable Example Objects. RequestBodies map[string]*RequestBody `json:"requestBodies,omitempty"` // An object to hold reusable Request Body Objects. Headers map[string]*Header `json:"headers,omitempty"` // An object to hold reusable Header Objects. SecuritySchemes map[string]interface{} `json:"securitySchemes,omitempty"` // An object to hold reusable Security Scheme Objects. Links map[string]*Link `json:"links,omitempty"` // An object to hold reusable Link Objects. Callbacks map[string]*PathItem `json:"callbacks,omitempty"` //An object to hold reusable Callback Objects. PathItems map[string]*PathItem `json:"pathItems,omitempty"` // An object to hold reusable Path Item Object. }
func (*Components) SetSecuritySchemes ¶
func (n *Components) SetSecuritySchemes(key string, value interface{})
type Contact ¶
type Contact struct { Name string `json:"name,omitempty"` //The identifying name of the contact person/organization. Url string `json:"url,omitempty"` //The URL pointing to the contact information. This MUST be in the form of a URL. Email string `json:"email,omitempty"` //The email address of the contact person/organization. This MUST be in the form of an email address. }
type Discriminator ¶
type Discriminator struct { PropertyName string `json:"propertyName,omitempty"` // REQUIRED. The name of the property in the payload that will hold the discriminator value. Mapping map[string]string `json:"mapping,omitempty"` //An object to hold mappings between payload values and schema names or references. }
type Encoding ¶
type Encoding struct { ContentType string `json:"contentType,omitempty"` //The Content-Type for encoding a specific property. Default value depends on the property type: for object - application/json; for array – the default is defined based on the inner type; for all other cases the default is application/octet-stream. The value can be a specific media type (e.g. application/json), a wildcard media type (e.g. image/*), or a comma-separated list of the two types. Headers map[string]*Header `json:"headers,omitempty"` //[HeaderObject | Reference] A map allowing additional information to be provided as headers, for example Content-Disposition.Content-Type is described separately and SHALL be ignored in this section.This property SHALL be ignored if the request body media type is not a multipart. Style string `json:"style,omitempty"` //Describes how a specific property value will be serialized depending on its type.See Parameter Object for details on the style property.The behavior follows the same values as query parameters, including default values.This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded or multipart/form-data.If a value is explicitly defined, then the value of contentType (implicit or explicit) SHALL be ignored. Explode bool `json:"explode,omitempty"` // When this is true, property values of type array or object generate separate parameters for each value of the array, or key-value-pair of the map.For other types of properties this property has no effect.When style is form, the default value is true.For all other styles, the default value is false.This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded or multipart/form-data.If a value is explicitly defined, then the value of contentType (implicit or explicit) SHALL be ignored. AllowReserved bool `json:"allowReserved,omitempty"` // Determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986:/?#[]@!$&'()*+,;= to be included without percent-encoding. The default value is false. This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded or multipart/form-data. If a value is explicitly defined, then the value of contentType (implicit or explicit) SHALL be ignored. }
type Example ¶
type Example struct { Summary string `json:"summary,omitempty"` //Short description for the example. Description string `json:"description,omitempty"` // Long description for the example. CommonMark syntax MAY be used for rich text representation. Value interface{} `json:"value,omitempty"` // string Embedded literal example.The value field and externalValue field are mutually exclusive.To represent examples of media types that cannot naturally represented in JSON or YAML, use a string value to contain the example, escaping where necessary. ExternalValue string `json:"externalValue,omitempty"` // A URI that points to the literal example.This provides the capability to reference examples that cannot easily be included in JSON or YAML documents.The value field and externalValue field are mutually exclusive.See the rules for resolving Relative References. Ref string `json:"$ref,omitempty"` }
type ExternalDocumentation ¶
type HTTPBase ¶
type HTTPBase struct { Type SecuritySchemeType `json:"type"` Description string `json:"description"` Schema string `json:"schema"` }
type HTTPBearer ¶
type HTTPBearer struct { Type SecuritySchemeType `json:"type"` Description string `json:"description"` Schema string `json:"schema"` BearerFormat string `json:"bearerFormat"` }
func NewHTTPBearer ¶
func NewHTTPBearer() HTTPBearer
type Header ¶
type Header struct { Description string `json:"description"` //A brief description of the parameter. This could contain examples of use. CommonMark syntax MAY be used for rich text representation. Required bool `json:"required"` //Determines whether this parameter is mandatory. If the parameter location is "path", this property is REQUIRED and its value MUST be true. Otherwise, the property MAY be included and its default value is false. Deprecated bool `json:"deprecated"` //Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is false. Style string `json:"style"` Explode bool `json:"explode"` AllowReserved bool `json:"allowReserved"` Schema *Schema `json:"schema"` Example interface{} `json:"example"` Examples map[string]Example `json:"examples"` Content map[string]MediaType `json:"content"` *Reference }
type IOpenapiStruct ¶
type IOpenapiStruct interface {
Map() map[string]interface{}
}
type IReference ¶
type IReference interface {
GetRef() struct{}
}
type Info ¶
type Info struct { Title string `json:"title,omitempty"` //REQUIRED. The title of the API. Summary string `json:"summary,omitempty"` //A short summary of the API. Description string `json:"description,omitempty"` //A description of the API. CommonMark syntax MAY be used for rich text representation. TermsOfService string `json:"termsOfService,omitempty"` //A URL to the Terms of Service for the API. This MUST be in the form of a URL. Contact *Contact `json:"contact,omitempty"` //The contact information for the exposed API. License *License `json:"license,omitempty"` //The license information for the exposed API. Version string `json:"version,omitempty"` //REQUIRED. The version of the OpenAPI document (which is distinct from the OpenAPI Specification version or the API implementation version). }
type Link ¶
type Link struct { OperationRef string `json:"operationRef,omitempty"` OperationId string `json:"operationId,omitempty"` Parameters map[string]*Parameter `json:"parameters,omitempty"` RequestBody *RequestBody `json:"requestBody,omitempty"` Description string `json:"description,omitempty"` Server *Server `json:"server,omitempty"` Ref string `json:"$ref,omitempty"` //REQUIRED. The reference identifier. This MUST be in the form of a URI. }
type MediaType ¶
type MediaType struct { Schema *Schema `json:"schema,omitempty"` //The schema defining the content of the request, response, or parameter. Example interface{} `json:"example,omitempty"` Examples map[string]interface{} `json:"examples,omitempty"` //[Example | Reference]Examples of the media type. Each example object SHOULD match the media type and specified schema if present. The examples field is mutually exclusive of the example field. Furthermore, if referencing a schema which contains an example, the examples value SHALL override the example provided by the schema. Encoding map[string]*Encoding `json:"encoding,omitempty"` //A map between a property name and its encoding information. The key, being the property name, MUST exist in the schema as a property. The encoding object SHALL only apply to requestBody objects when the media type is multipart or application/x-www-form-urlencoded. }
func (*MediaType) SetExamples ¶
type OAuth2 ¶
type OAuth2 struct { Type SecuritySchemeType `json:"type"` Description string `json:"description"` Flows OAuthFlows `json:"flows"` }
func NewOpenIdConnect ¶
func NewOpenIdConnect() OAuth2
type OAuthFlowImplicit ¶
type OAuthFlowPassword ¶
type OAuthFlows ¶
type OAuthFlows struct { Implicit *OAuthFlowImplicit `json:"implicit"` Password *OAuthFlowPassword `json:"password"` ClientCredentials *OAuthFlowClientCredentials `json:"clientCredentials"` AuthorizationCode *OAuthFlowAuthorizationCode `json:"authorizationCode"` }
type OpenAPI ¶
type OpenAPI struct { Openapi string `json:"openapi,omitempty"` //REQUIRED. This string MUST be the version number of the OpenAPI Specification that the OpenAPI document uses. The openapi field SHOULD be used by tooling to interpret the OpenAPI document. This is not related to the API info.version string. Info *Info `json:"info,omitempty"` //REQUIRED. Provides metadata about the API. The metadata MAY be used by tooling as required. Servers []*Server `json:"servers,omitempty"` //An array of Server Objects, which provide connectivity information to a target server. If the servers property is not provided, or is an empty array, the default value would be a Server Object with a url value of /. Paths map[string]*PathItem `json:"paths,omitempty"` //The available paths and operations for the API. Components *Components `json:"components,omitempty"` //An element to hold various schemas for the document. Security []*SecurityRequirementObject `json:"security,omitempty"` //A declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement ({}) can be included in the array. Tags []*Tag `json:"tags,omitempty"` //A list of tags used by the document with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the Operation Object must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique. ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"` //Additional external documentation. }
type OpenIdConnect ¶
type OpenIdConnect struct { Type SecuritySchemeType `json:"type"` Description string `json:"description"` Flows OAuthFlows `json:"flows"` }
type Operation ¶
type Operation struct { Tags []string `json:"tags,omitempty"` //A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier. Summary string `json:"summary,omitempty"` //A short summary of what the operation does. Description string `json:"description,omitempty"` //A verbose explanation of the operation behavior. CommonMark syntax MAY be used for rich text representation. ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"` //Additional external documentation for this operation. OperationId string `json:"operationId,omitempty"` //Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions. Parameters []*Parameter `json:"parameters,omitempty"` //Parameter or Reference //A list of parameters that are applicable for this operation. If a parameter is already defined at the Path Item, the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a name and location. The list can use the Reference to link to parameters that are defined at the OpenAPI Object's components/parameters. RequestBody *RequestBody `json:"requestBody,omitempty"` //The request body applicable for this operation. The requestBody is fully supported in HTTP methods where the HTTP 1.1 specification RFC7231 has explicitly defined semantics for request bodies. In other cases where the HTTP spec is vague (such as GET, HEAD and DELETE), requestBody is permitted but does not have well-defined semantics and SHOULD be avoided if possible. Responses map[string]*Response `json:"responses,omitempty"` Callbacks map[string]*PathItem `json:"callbacks,omitempty"` //str? Deprecated bool `json:"deprecated,omitempty"` //Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is false. Security []map[string][]string `json:"security,omitempty"` Servers []*Server `json:"servers,omitempty"` }
type Parameter ¶
type Parameter struct { // Parameter Name string `json:"name,omitempty"` In string `json:"in,omitempty"` //REQUIRED. The location of the parameter. Possible values are "query", "header", "path" or "cookie". Description string `json:"description,omitempty"` //A brief description of the parameter. This could contain examples of use. CommonMark syntax MAY be used for rich text representation. Required bool `json:"required,omitempty"` //Determines whether this parameter is mandatory. If the parameter location is "path", this property is REQUIRED and its value MUST be true. Otherwise, the property MAY be included and its default value is false. Deprecated bool `json:"deprecated,omitempty"` //Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is false. Style string `json:"style,omitempty"` Explode bool `json:"explode,omitempty"` AllowReserved bool `json:"allowReserved,omitempty"` Schema *Schema `json:"schema,omitempty,omitempty"` Example interface{} `json:"example,omitempty"` Examples map[string]*Example `json:"examples,omitempty"` //暂不支持 Content map[string]*MediaType `json:"content,omitempty"` Ref string `json:"$ref,omitempty"` //REQUIRED. The reference identifier. This MUST be in the form of a URI. }
type PathItem ¶
type PathItem struct { Ref string `json:"$ref,omitempty"` //Allows for a referenced definition of this path item. The referenced structure MUST be in the form of a Path Item Object. In case a Path Item Object field appears both in the defined object and the referenced object, the behavior is undefined. See the rules for resolving Relative References. Summary string `json:"summary,omitempty"` //An optional, string summary, intended to apply to all operations in this path. Description string `json:"description,omitempty"` //An optional, string description, intended to apply to all operations in this path. CommonMark syntax MAY be used for rich text representation. Get *Operation `json:"get,omitempty"` Put *Operation `json:"put,omitempty"` Post *Operation `json:"post,omitempty"` Delete *Operation `json:"delete,omitempty"` Options *Operation `json:"options,omitempty"` Head *Operation `json:"head,omitempty"` Patch *Operation `json:"patch,omitempty"` Trace *Operation `json:"trace,omitempty"` Servers []*Server `json:"servers,omitempty"` Parameters *Parameter `json:"parameters,omitempty"` }
type Reference ¶
type Reference struct {
Ref string `json:"$ref,omitempty"` //REQUIRED. The reference identifier. This MUST be in the form of a URI.
}
type RequestBody ¶
type RequestBody struct { Description string `json:"description,omitempty"` //A brief description of the request body. This could contain examples of use. CommonMark syntax MAY be used for rich text representation. Content map[string]*MediaType `json:"content,omitempty"` //REQUIRED. The content of the request body. The key is a media type or media type range and the value describes it. For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/* Required bool `json:"required,omitempty"` //Determines if the request body is required in the request. Defaults to false. Ref string `json:"$ref,omitempty"` }
type Response ¶
type Response struct { Description string `json:"description,omitempty"` //REQUIRED. A description of the response. CommonMark syntax MAY be used for rich text representation. Headers map[string]*Header `json:"headers,omitempty"` //[HeaderObject | Reference Object] Maps a header name to its definition. RFC7230 states header names are case insensitive. If a response header is defined with the name "Content-Type", it SHALL be ignored. Content map[string]*MediaType `json:"content,omitempty"` // A map containing descriptions of potential response payloads. The key is a media type or media type range and the value describes it. For responses that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/* Links map[string]*Link `json:"links,omitempty"` //[LinkObject | Reference Object] A map of operations links that can be followed from the response. The key of the map is a short name for the link, following the naming constraints of the names for Component Objects. Ref string `json:"$ref,omitempty"` //REQUIRED. The reference identifier. This MUST be in the form of a URI. }
type Schema ¶
type Schema struct { Version string `json:"$schema,omitempty"` // section 6.1 Ref string `json:"$ref,omitempty"` Enum []interface{} `json:"enum,omitempty"` //枚举值:必须是一个数组。这个数组应该 .至少有一个元素。数组中的元素应该是唯一的。如果实例的值等于此关键字数组值中的元素之一,则该实例成功验证此关键字。 Type string `json:"type,omitempty"` //必须是null boolean,object,array,number,string,integer // integer number MultipleOf float64 `json:"multipleOf,omitempty"` //几的倍数 Maximum *float64 `json:"maximum,omitempty"` //数字小于等于 ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"` //数字小于 Minimum *float64 `json:"minimum,omitempty"` //数字大于等于 ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"` //string MaxLength int `json:"maxLength,omitempty"` //字符串最长值 MinLength int `json:"minLength,omitempty"` // 字符串最短值 Pattern string `json:"pattern,omitempty"` // 正则表达式,注意 // slice(array) MaxItems uint64 `json:"maxItems,omitempty"` //数组长度小于等于 MinItems uint64 `json:"minItems,omitempty"` //数组长度大于等于 UniqueItems bool `json:"uniqueItems,omitempty"` //是否slice值不能重复 Items *Schema `json:"items,omitempty"` // 验证切片是否属于这个类型 //object MaxProperties uint64 `json:"maxProperties,omitempty"` //object实例属性数量最大值 MinProperties uint64 `json:"minProperties,omitempty"` // 同上 Required []string `json:"required,omitempty"` //必须具备的属性 Properties *orderedmap.OrderedMap `json:"properties,omitempty"` //直接定义属性 AdditionalProperties json.RawMessage `json:"additionalProperties,omitempty"` //true : json串可以出现除schema定义之外属性 false :json串不可以出现除schema定义之外属性 PatternProperties map[string]*Schema `json:"patternProperties,omitempty"` //对字段名称进行正则表达式验证 //go 结构体可不支持动态结构,所以这几个字段没意义 AllOf []*Schema `json:"allOf,omitempty"` //必须对所有子模式有效 OneOf []*Schema `json:"oneOf,omitempty"` //必须仅对其中一个子模式有效 AnyOf []*Schema `json:"anyOf,omitempty"` //组合类型,只要复合这里面的其中一个验证就行 Not *Schema `json:"not,omitempty"` //元数据,所有对象都有的默认值 Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` Default interface{} `json:"default,omitempty"` Format string `json:"format,omitempty"` // 一些固定类型的匹配,比如email,ip,uuid,datetime等 Example *Example `json:"example,omitempty"` Examples []interface{} `json:"examples,omitempty,omitempty"` // 例子 //openapi需要的字段 Xml *XML `json:"xml,omitempty"` // This MAY be used only on properties schemas.It has no effect on root schemas.Adds additional metadata to describe the XML representation of this property. ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"` // Additional external documentation for this schema. // 以json编码的非json数据(比如base64:{ // "type": "string", // "media": "base64", // "contentMediaType": "image/png" //}) Media *Schema `json:"media,omitempty"` // BinaryEncoding string `json:"binaryEncoding,omitempty"` // Extras map[string]interface{} `json:"-"` // 额外增加的字段,主要解决decode和encode共用一个结构体的时候字段问题 Nullable bool `json:"nullable,omitempty"` ReadOnly bool `json:"readOnly,omitempty"` WriteOnly bool `json:"writeOnly,omitempty"` //重用的时候只写, Deprecated bool `json:"deprecated,omitempty"` //是否为废弃状态 FieldName string `json:"-"` //字段名称 }
func (*Schema) MarshalJSON ¶
func (*Schema) StructKeywordsFromTags ¶
func (t *Schema) StructKeywordsFromTags(f reflect.StructField, parentType *Schema, propertyName string)
StructKeywordsFromTags 解析结构体字段的tag
type SecurityBase ¶
type SecurityBase struct { Type SecuritySchemeType `json:"type"` Description string `json:"description"` }
type SecurityRequirementObject ¶
type SecurityRequirementObject struct {
// contains filtered or unexported fields
}
type SecuritySchemeType ¶
type SecuritySchemeType string
type Server ¶
type Server struct { Url string `json:"url"` //REQUIRED. A URL to the target host. This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where the OpenAPI document is being served. Variable substitutions will be made when a variable is named in {brackets}. Description string `json:"description"` //An optional string describing the host designated by the URL. CommonMark syntax MAY be used for rich text representation. Variables map[string]ServerVariable `json:"variables"` //A map between a variable name and its value. The value is used for substitution in the server's URL template. }
type ServerVariable ¶
type ServerVariable struct { Enum []string `json:"enum"` //An enumeration of string values to be used if the substitution options are from a limited set. The array MUST NOT be empty. Default string `json:"default"` //REQUIRED. The default value to use for substitution, which SHALL be sent if an alternate value is not supplied. Note this behavior is different than the Schema Object's treatment of default values, because in those cases parameter values are optional. If the enum is defined, the value MUST exist in the enum's values. Description string `json:"description"` //An optional description for the server variable. CommonMark syntax MAY be used for rich text representation. }
type Tag ¶
type Tag struct { Name string `json:"name"` // REQUIRED. The name of the tag. Description string `json:"description"` // A description for the tag. CommonMark syntax MAY be used for rich text representation. ExternalDocs ExternalDocumentation `json:"externalDocs"` // Additional external documentation for this tag. }
type XML ¶
type XML struct { Name string `json:"name,omitempty"` // Replaces the name of the element/attribute used for the described schema property. When defined within items, it will affect the name of the individual XML elements within the list. When defined alongside type being array (outside the items), it will affect the wrapping element and only if wrapped is true. If wrapped is false, it will be ignored. Namespace string `json:"namespace,omitempty"` // The URI of the namespace definition. This MUST be in the form of an absolute URI. Prefix string `json:"prefix,omitempty"` // The prefix to be used for the name. Attribute bool `json:"attribute,omitempty"` // Declares whether the property definition translates to an attribute instead of an element. Default value is false. Wrapped bool `json:"wrapped,omitempty"` // MAY be used only for an array definition. Signifies whether the array is wrapped (for example, <books><book/><book/></books>) or unwrapped (<book/><book/>). Default value is false. The definition takes effect only when defined alongside type being array (outside the items). }
Click to show internal directories.
Click to hide internal directories.