Documentation
¶
Index ¶
- func IsSupportedMediaType(abbr string) (kind MediaTypeKind, title MediaTypeTitle, supportReq bool, supportResp bool)
- type Callback
- type CallbackR
- type Callbacks
- type Components
- type Contact
- type Content
- type Discriminator
- type Encoding
- type Example
- type ExampleR
- type Examples
- type ExternalDoc
- type Header
- type HeaderR
- type Headers
- type InWay
- type Info
- type License
- type Link
- type LinkR
- type Links
- type MediaType
- type MediaTypeKind
- type MediaTypeSupport
- type MediaTypeTitle
- type Openapi
- type Operation
- type Parameter
- type ParameterList
- type ParameterR
- type Parameters
- type Path
- type Paths
- type Ref
- type RequestBodies
- type RequestBody
- type RequestBodyR
- type Response
- type ResponseR
- type Responses
- type Schema
- type SchemaR
- type Schemas
- type SecurityRequirement
- type SecurityScheme
- type SecuritySchemeR
- type SecuritySchemes
- func (s *SecuritySchemes) AppendApiKeyAuth(name string, paramIn InWay, paramName string) *SecuritySchemes
- func (s *SecuritySchemes) AppendBasicAuth(name string) *SecuritySchemes
- func (s *SecuritySchemes) AppendBearerAuth(name string) *SecuritySchemes
- func (s *SecuritySchemes) AppendOpenId(name string, openIdConnectUrl string) *SecuritySchemes
- func (s *SecuritySchemes) AppendScheme(name string, scheme SecurityScheme) *SecuritySchemes
- type Server
- type ServerVariable
- type Tag
- type Tags
- type VariableKind
- type WithContent
- type WithSchemaAndStyle
- type Xml
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSupportedMediaType ¶
func IsSupportedMediaType(abbr string) (kind MediaTypeKind, title MediaTypeTitle, supportReq bool, supportResp bool)
IsSupportedMediaType gets media type information.
Types ¶
type Callback ¶
type Callback struct { }
Callback A map of possible out-of band callbacks related to the parent operation. Each value in the map is a Path Item Object that describes a set of requests that may be initiated by the API provider and the expected responses. The key value used to identify the path item object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.
Not implement yet, refer to https://swagger.io/specification/
type Components ¶
type Components struct { // An object to hold reusable Schema Objects. Schemas Schemas `json:"schemas,omitempty"` // An object to hold reusable Response Objects. Responses Responses `json:"responses,omitempty"` // An object to hold reusable Parameter Objects. Parameters Parameters `json:"parameters,omitempty"` // An object to hold reusable Example Objects. Examples Examples `json:"examples,omitempty"` // An object to hold reusable Request Body Objects. RequestBodies RequestBodies `json:"requestBodies,omitempty"` // An object to hold reusable Header Objects. Headers Headers `json:"headers,omitempty"` // An object to hold reusable Security Scheme Objects. SecuritySchemes SecuritySchemes `json:"securitySchemes,omitempty"` // An object to hold reusable Link Objects. Links Links `json:"links,omitempty"` // An object to hold reusable Callback Objects. Callbacks Callbacks `json:"callbacks,omitempty"` }
Components Holds a set of reusable objects for different aspects of the OAS. All objects defined within the components object will have no effect on the API unless they are explicitly referenced from properties outside the components object.
This object MAY be extended with Specification Extensions.
All the fixed fields declared below are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9\.\-_]+$.
"components": { "schemas": { "GeneralError": { "type": "object", "properties": { "code": { "type": "integer", "format": "int32" }, "message": { "type": "string" } } }, "Category": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } } }, "Tag": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } } } }, "parameters": { "skipParam": { "name": "skip", "in": "query", "description": "number of items to skip", "required": true, "schema": { "type": "integer", "format": "int32" } }, "limitParam": { "name": "limit", "in": "query", "description": "max records to return", "required": true, "schema" : { "type": "integer", "format": "int32" } } }, "responses": { "NotFound": { "description": "Entity not found." }, "IllegalInput": { "description": "Illegal input for operation." }, "GeneralError": { "description": "General Error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/GeneralError" } } } } }, "securitySchemes": { "api_key": { "type": "apiKey", "name": "api_key", "in": "header" }, "petstore_auth": { "type": "oauth2", "flows": { "implicit": { "authorizationUrl": "http://example.org/api/oauth/dialog", "scopes": { "write:pets": "modify pets in your account", "read:pets": "read your pets" } } } } } }
type Contact ¶
type Contact struct { // The identifying name of the contact person/organization. Name string `json:"name"` // The URL pointing to the contact information. MUST be in the format of a URL. Url string `json:"url"` // The email address of the contact person/organization. MUST be in the format of an email address. Email string `json:"email"` }
Contact information for the exposed API.
{ "name": "API Support", "url": "http://www.example.com/support", "email": "support@example.com" }
type Content ¶
type Content map[MediaTypeTitle]MediaType
func (*Content) SetMediaType ¶
func (c *Content) SetMediaType(coding MediaTypeTitle, mediaType MediaType)
type Discriminator ¶
type Discriminator struct { // REQUIRED. The name of the property in the payload that will hold the discriminator value. PropertyName string `json:"propertyName"` // An object to hold mappings between payload values and schema names or references. Mapping map[string]string `json:"mapping,omitempty"` }
Discriminator When request bodies or response payloads may be one of a number of different schemas, a discriminator object can be used to aid in serialization, deserialization, and validation. The discriminator is a specific object in a schema which is used to inform the consumer of the specification of an alternative schema based on the value associated with it.
When using the discriminator, inline schemas will not be considered. The discriminator object is legal only when using one of the composite keywords oneOf, anyOf, allOf.
需搭配xxxOf這種多schemas選擇使用。藉由discriminator來判斷是屬於多個schemas的哪一個。
type Encoding ¶
type Encoding struct { // The Content-Type for encoding a specific property. Default value depends on the property type: // // for string with format being binary – application/octet-stream; // // for other primitive types – text/plain; // // for object - application/json; // // for array – the default is defined based on the inner type. // // 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. ContentType string `json:"contentType,omitempty"` // 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. Headers map[string]HeaderR `json:"headers,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. Style string `json:"style,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. Explode bool `json:"explode,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. AllowReserved bool `json:"allowReserved,omitempty"` }
Encoding A single encoding definition applied to a single schema property.
type Example ¶
type Example struct { // Short description for the example. Summary string `json:"summary,omitempty"` // Long description for the example. CommonMark syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // Embedded literal example. The value field and externalValue field are mutually exclusive. // To represent examples of media types that cannot naturally be represented in JSON or YAML, // use a string value to contain the example, escaping where necessary. Value any `json:"value,omitempty"` // A URL 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. ExternalValue string `json:"externalValue,omitempty"` }
Example In all cases, the example value is expected to be compatible with the type schema of its associated value. Tooling implementations MAY choose to validate compatibility automatically, and reject the example value(s) if incompatible.
type ExternalDoc ¶
type ExternalDoc struct { // A short description of the target documentation. CommonMark syntax MAY be used for rich text representation. Description string `json:"description"` // REQUIRED. The URL for the target documentation. Value MUST be in the format of a URL. Url string `json:"url"` }
ExternalDoc allows referencing an external resource for extended documentation.
type Header ¶
type Header struct { // A brief description of the parameter. This could contain examples of use. CommonMark syntax MAY be used for rich text representation. Description string `json:"description,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. Required bool `json:"required,omitempty"` // Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is false. Deprecated bool `json:"deprecated,omitempty"` // Sets the ability to pass empty-valued parameters. This is valid only for query parameters and allows sending a parameter with an empty value. // Default value is false. If style is used, and if behavior is n/a (cannot be serialized), the value of allowEmptyValue SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision. AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` // WithSchemaAndStyle The rules for serialization of the parameter are specified in one of two ways. // For simpler scenarios, a schema and style can describe the structure and syntax of the parameter. WithSchemaAndStyle // For more complex scenarios, the content property can define the media type and schema of the parameter. // A parameter MUST contain either a schema property, or a content property, but not both. // When example or examples are provided in conjunction with the schema object, the example MUST follow the prescribed serialization strategy for the parameter. WithContent }
The Header Object follows the structure of the Parameter Object with the following changes:
- name MUST NOT be specified, it is given in the corresponding headers map.
- in MUST NOT be specified, it is implicitly in header.
- All traits that are affected by the location MUST be applicable to a location of header (for example, style).
A simple header of type integer:
{ "description": "The number of allowed requests in the current period", "schema": { "type": "integer" } }
type InWay ¶ added in v0.1.0
type InWay = string
const ( InHeaderWay InWay = "header" // one kind of way for parameter InCookieWay InWay = "cookie" // one kind of way for parameter InQueryWay InWay = "query" // one kind of way for parameter InPathWay InWay = "path" // one kind of way for parameter InBodyWay InWay = "body" // one kind of way for request body )
type Info ¶
type Info struct { // REQUIRED. The title of the API. Title string `json:"title"` // A short description of the API. CommonMark syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // A URL to the Terms of Service for the API. MUST be in the format of a URL. TermsOfService string `json:"termsOfService,omitempty"` // The contact information for the exposed API. Contact *Contact `json:"contact,omitempty"` // The license information for the exposed API. License *License `json:"license,omitempty"` // REQUIRED. The version of the OpenAPI document (which is distinct from the OpenAPI Specification version or the API implementation version). Version string `json:"version,omitempty"` }
Info The object provides metadata about the API. The metadata MAY be used by the clients if needed, and MAY be presented in editing or documentation generation tools for convenience.
{ "title": "Sample Pet Store App", "description": "This is a sample server for a pet store.", "termsOfService": "http://example.com/terms/", "contact": { "name": "API Support", "url": "http://www.example.com/support", "email": "support@example.com" }, "license": { "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, "version": "1.0.1" }
type License ¶
License information for the exposed API.
{ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }
type Link ¶
type Link struct { // A relative or absolute URI reference to an OAS operation. This field is mutually exclusive of the operationId field, // and MUST point to an Operation Object. Relative operationRef values MAY be used to locate an existing Operation Object in the OpenAPI definition. OperationRef string `json:"operationRef,omitempty"` // The name of an existing, resolvable OAS operation, as defined with a unique operationId. This field is mutually exclusive of the operationRef field. OperationId string `json:"operationId,omitempty"` // A map representing parameters to pass to an operation as specified with operationId or identified via operationRef. // The key is the parameter name to be used, whereas the value can be a constant or an expression to be evaluated and passed to the linked operation. // The parameter name can be qualified using the parameter location [{in}.]{name} for operations that use the same parameter name in different locations (e.g. path.id). Parameters map[string]any `json:"parameters,omitempty"` // A literal value or {expression} to use as a request body when calling the target operation. RequestBody map[string]any `json:"requestBody,omitempty"` // A description of the link. CommonMark syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // A server object to be used by the target operation. Server *Server `json:"server,omitempty"` }
The Link object represents a possible design-time link for a response. The presence of a link does not guarantee the caller's ability to successfully invoke it, rather it provides a known relationship and traversal mechanism between responses and other operations.
Unlike dynamic links (i.e. links provided in the response payload), the OAS linking mechanism does not require link information in the runtime response.
For computing links, and providing instructions to execute them, a runtime expression is used for accessing values in an operation and using them as parameters while invoking the linked operation.
A linked operation MUST be identified using either an operationRef or operationId. In the case of an operationId, it MUST be unique and resolved in the scope of the OAS document. Because of the potential for name clashes, the operationRef syntax is preferred for specifications with external references.
type MediaType ¶
type MediaType struct { // The schema defining the content of the request, response, or parameter. Schema *SchemaR `json:"schema,omitempty"` // Example of the media type. The example object SHOULD be in the correct format as specified by the media type. // The example field is mutually exclusive of the examples field. Furthermore, if referencing a schema which contains an example, // the example value SHALL override the example provided by the schema. Example any `json:"example,omitempty"` // 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. Examples map[string]ExampleR `json:"examples,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. Encoding map[string]Encoding `json:"encoding,omitempty"` }
MediaType Each Object provides schema and examples for the media type identified by its key.
{ "application/json": { "schema": { "$ref": "#/components/schemas/Pet" }, "examples": { "cat" : { "summary": "An example of a cat", "value": { "name": "Fluffy", "petType": "Cat", "color": "White", "gender": "male", "breed": "Persian" } }, "dog": { "summary": "An example of a dog with a cat's name", "value" : { "name": "Puma", "petType": "Dog", "color": "Black", "gender": "Female", "breed": "Mixed" }, "frog": { "$ref": "#/components/examples/frog-example" } } } } }
type MediaTypeKind ¶
type MediaTypeKind int
const ( UnsupportedMediaType MediaTypeKind = iota PlainMediaType ObjectiveMediaType StreamMediaType )
type MediaTypeSupport ¶
type MediaTypeSupport struct { Abbr []string Title MediaTypeTitle Kind MediaTypeKind Req bool // request supports this Title Resp bool // response supports this Title }
func GetSupportedMediaType ¶
func GetSupportedMediaType(abbr string) (support MediaTypeSupport, ok bool)
type MediaTypeTitle ¶
type MediaTypeTitle string
const ( UrlEncoded MediaTypeTitle = "application/x-www-form-urlencoded" MultipartForm MediaTypeTitle = "multipart/form-data" PlainText MediaTypeTitle = "text/plain" JsonObject MediaTypeTitle = "application/json" XmlObject MediaTypeTitle = "application/xml" HtmlPage MediaTypeTitle = "text/html" OctetStream MediaTypeTitle = "application/octet-stream" PngImage MediaTypeTitle = "image/png" JpegImage MediaTypeTitle = "image/jpeg" )
type Openapi ¶
type Openapi struct { // REQUIRED. This string MUST be the semantic version number of the OpenAPI Specification version that the OpenAPI document uses. // The openapi field SHOULD be used by tooling specifications and clients to interpret the OpenAPI document. This is not related to the API info.version string. Openapi string `json:"openapi"` // ex: openapi: "3.0.0" // REQUIRED. Provides metadata about the API. The metadata MAY be used by tooling as required. Info *Info `json:"info"` // 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 /. Servers []Server `json:"servers"` // REQUIRED. The available paths and operations for the API. Paths Paths `json:"paths,omitempty"` // ex: "/user":Path // An element to hold various schemas for the specification. Components *Components `json:"components,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. Security []SecurityRequirement `json:"securityDefinitions,omitempty"` // ex: {"api_key": SecurityDefinition} // A list of tags used by the specification 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. Tags Tags `json:"tags,omitempty"` // Additional external documentation. ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"` }
type Operation ¶
type Operation struct { // A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier. Tags []string `json:"tags,omitempty"` // A short summary of what the operation does. Summary string `json:"summary,omitempty"` // A verbose explanation of the operation behavior. CommonMark syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // Additional external documentation for this operation. ExternalDocs *ExternalDoc `json:"externalDocs,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. OperationID string `json:"operationId,omitempty"` // 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 Object // to link to parameters that are defined at the OpenAPI Object's components/parameters. Parameters ParameterList `json:"parameters,omitempty"` // The request body applicable for this operation. The requestBody is only 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, requestBody SHALL be ignored by consumers. RequestBody *RequestBodyR `json:"requestBody,omitempty"` // REQUIRED. The list of possible responses as they are returned from executing this operation. Responses Responses `json:"responses"` // ex: {"200":response}, {"default":{"description":"successful operation"}} // A map of possible out-of band callbacks related to the parent operation. The key is a unique identifier for the Callback Object. // Each value in the map is a Callback Object that describes a request that may be initiated by the API provider and the expected responses. Callbacks Callbacks `json:"callbacks,omitempty"` // Declares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. Default value is false. Deprecated bool `json:"deprecated,omitempty"` // A declaration of which security mechanisms can be used for this operation. // 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. // To make security optional, an empty security requirement ({}) can be included in the array. // This definition overrides any declared top-level security. To remove a top-level security declaration, an empty array can be used. Security []SecurityRequirement `json:"security,omitempty"` // An alternative server array to service this operation. // If an alternative server object is specified at the Path Item Object or Root level, // it will be overridden by this value. Servers []Server `json:"servers,omitempty"` }
Operation describes a single API operation on a path.
{ "tags": [ "pet" ], "summary": "Updates a pet in the store with form data", "operationId": "updatePetWithForm", "parameters": [ { "name": "petId", "in": "path", "description": "ID of pet that needs to be updated", "required": true, "schema": { "type": "string" } } ], "requestBody": { "content": { "application/x-www-form-urlencoded": { "schema": { "type": "object", "properties": { "name": { "description": "Updated name of the pet", "type": "string" }, "status": { "description": "Updated status of the pet", "type": "string" } }, "required": ["status"] } } } }, "responses": { "200": { "description": "Pet updated.", "content": { "application/json": {}, "application/xml": {} } }, "405": { "description": "Method Not Allowed", "content": { "application/json": {}, "application/xml": {} } } }, "security": [ { "petstore_auth": [ "write:pets", "read:pets" ] } ] }
type Parameter ¶
type Parameter struct { // REQUIRED. The name of the parameter. Parameter names are case-sensitive. // - If in is "path", the name field MUST correspond to a template expression occurring within the path field in the Paths Object. See Path Templating for further information. // - If in is "header" and the name field is "Accept", "Content-Type" or "Authorization", the parameter definition SHALL be ignored. // - For all other cases, the name corresponds to the parameter name used by the in property. Name string `json:"name"` // ex. "body" // REQUIRED. The location of the parameter. Possible values are "query", "header", "path" or "cookie". In InWay `json:"in"` // ex. "body" // A brief description of the parameter. This could contain examples of use. CommonMark syntax MAY be used for rich text representation. Description string `json:"description,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. Required bool `json:"required,omitempty"` // Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is false. Deprecated bool `json:"deprecated,omitempty"` // Sets the ability to pass empty-valued parameters. This is valid only for query parameters and allows sending a parameter with an empty value. // Default value is false. If style is used, and if behavior is n/a (cannot be serialized), the value of allowEmptyValue SHALL be ignored. Use of this property is NOT RECOMMENDED, as it is likely to be removed in a later revision. AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` // WithSchemaAndStyle The rules for serialization of the parameter are specified in one of two ways. // For simpler scenarios, a schema and style can describe the structure and syntax of the parameter. WithSchemaAndStyle // For more complex scenarios, the content property can define the media type and schema of the parameter. // A parameter MUST contain either a schema property, or a content property, but not both. // When example or examples are provided in conjunction with the schema object, the example MUST follow the prescribed serialization strategy for the parameter. WithContent }
Parameter Describes a single operation parameter.
A unique parameter is defined by a combination of a name and location.
Parameter Locations There are four possible parameter locations specified by the in field:
- path - Used together with Path Templating, where the parameter value is actually part of the operation's URL. This does not include the host or base path of the API. For example, in /items/{itemId}, the path parameter is itemId.
- query - Parameters that are appended to the URL. For example, in /items?id=###, the query parameter is id.
- header - Custom headers that are expected as part of the request. Note that RFC7230 states header names are case-insensitive.
- cookie - Used to pass a specific cookie value to the API.
A header parameter with an array of 64 bit integer numbers:
{ "name": "token", "in": "header", "description": "token to be passed as a header", "required": true, "schema": { "type": "array", "items": { "type": "integer", "format": "int64" } }, "style": "simple" }
A path parameter of a string value:
{ "name": "username", "in": "path", "description": "username to fetch", "required": true, "schema": { "type": "string" } }
An optional query parameter of a string value, allowing multiple values by repeating the query parameter:
{ "name": "id", "in": "query", "description": "ID of the object to fetch", "required": false, "schema": { "type": "array", "items": { "type": "string" } }, "style": "form", "explode": true }
A free-form query parameter, allowing undefined parameters of a specific type:
{ "in": "query", "name": "freeForm", "schema": { "type": "object", "additionalProperties": { "type": "integer" }, }, "style": "form" }
A complex parameter using content to define serialization:
{ "in": "query", "name": "coordinates", "content": { "application/json": { "schema": { "type": "object", "required": [ "lat", "long" ], "properties": { "lat": { "type": "number" }, "long": { "type": "number" } } } } } }
type ParameterList ¶
type ParameterList []ParameterR
ParameterList presents a list/slice of parameters.
func (ParameterList) AppendParam ¶
func (l ParameterList) AppendParam(param *Parameter) ParameterList
func (ParameterList) AppendRef ¶
func (l ParameterList) AppendRef(ref string) ParameterList
type ParameterR ¶
ParameterR presents Parameter or Ref combination
type Parameters ¶
type Parameters map[string]ParameterR
Parameters presents a map for key-parameter pairs.
type Path ¶
type Path struct { // Allows for an external definition of this path item. The referenced structure MUST be in the format 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. Ref string `json:"$ref,omitempty"` // An optional, string summary, intended to apply to all operations in this path. Summary string `json:"summary,omitempty"` // An optional, string description, intended to apply to all operations in this path. CommonMark syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // A definition of a GET operation on this path. Get *Operation `json:"get,omitempty"` // A definition of a PUT operation on this path. Put *Operation `json:"put,omitempty"` // A definition of a POST operation on this path. Post *Operation `json:"post,omitempty"` // A definition of a DELETE operation on this path. Delete *Operation `json:"delete,omitempty"` // A definition of a OPTIONS operation on this path. Options *Operation `json:"options,omitempty"` // A definition of a HEAD operation on this path. Head *Operation `json:"head,omitempty"` // A definition of a PATCH operation on this path. Patch *Operation `json:"patch,omitempty"` // A definition of a TRACE operation on this path. Trace *Operation `json:"trace,omitempty"` // An alternative server array to service all operations in this path. Servers []Server `json:"servers,omitempty"` // A list of parameters that are applicable for all the operations described under this path. // These parameters can be overridden at the operation level, but cannot be removed there. // 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 Object to link to parameters that are defined at the OpenAPI Object's components/parameters. Parameters ParameterList `json:"parameters,omitempty"` }
Path describes the operations available on a single path. A Path Item MAY be empty, due to ACL constraints. The path itself is still exposed to the documentation viewer but they will not know which operations and parameters are available.
{ "get": { "description": "Returns pets based on ID", "summary": "Find pets by ID", "operationId": "getPetsById", "responses": { "200": { "description": "pet response", "content": { "*/*": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Pet" } } } } }, "default": { "description": "error payload", "content": { "text/html": { "schema": { "$ref": "#/components/schemas/ErrorModel" } } } } } }, "parameters": [ { "name": "id", "in": "path", "description": "ID of pet to use", "required": true, "schema": { "type": "array", "items": { "type": "string" } }, "style": "simple" } ] }
type Paths ¶
Paths Holds the relative paths to the individual endpoints and their operations. The path is appended to the URL from the Server Object in order to construct the full URL. The Paths MAY be empty, due to ACL constraints.
A relative path to an individual endpoint. The field name MUST begin with a forward slash (/). The path is appended (no relative URL resolution) to the expanded URL from the Server Object's url field in order to construct the full URL. Path templating is allowed. When matching URLs, concrete (non-templated) paths would be matched before their templated counterparts. Templated paths with the same hierarchy but different templated names MUST NOT exist as they are identical. In case of ambiguous matching, it's up to the tooling to decide which one to use.
{ "/pets": { "get": { "description": "Returns all pets from the system that the user has access to", "responses": { "200": { "description": "A list of pets.", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/pet" } } } } } } } } }
type Ref ¶
type Ref struct { // REQUIRED. The reference string. Ref string `json:"$ref"` }
Ref A simple object to allow referencing other components in the specification, internally and externally.
The Reference Object is defined by JSON Reference and follows the same structure, behavior and rules.
For this specification, reference resolution is accomplished as defined by the JSON Reference specification and not by the JSON Schema specification.
Reference object example
{ "$ref": "#/components/schemas/Pet" }
Relative schema document example
{ "$ref": "Pet.json" }
Relative documents with embedded schema example
{ "$ref": "definitions.json#/Pet" }
This may not be really used.
type RequestBodies ¶
type RequestBodies map[string]RequestBodyR
type RequestBody ¶
type RequestBody struct { // A brief description of the request body. This could contain examples of use. CommonMark syntax MAY be used for rich text representation. Description string `json:"description,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/* Content Content `json:"content"` // Determines if the request body is required in the request. Defaults to false. Required bool `json:"required,omitempty"` }
RequestBody describes a single request body.
A request body with a referenced model definition.
{ "description": "user to add to the system", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/User" }, "examples": { "user" : { "summary": "User Example", "externalValue": "http://foo.bar/examples/user-example.json" } } }, "application/xml": { "schema": { "$ref": "#/components/schemas/User" }, "examples": { "user" : { "summary": "User example in XML", "externalValue": "http://foo.bar/examples/user-example.xml" } } }, "text/plain": { "examples": { "user" : { "summary": "User example in Plain text", "externalValue": "http://foo.bar/examples/user-example.txt" } } }, "*/*": { "examples": { "user" : { "summary": "User example in other format", "externalValue": "http://foo.bar/examples/user-example.whatever" } } } } }
A body parameter that is an array of string values:
{ "description": "user to add to the system", "content": { "text/plain": { "schema": { "type": "array", "items": { "type": "string" } } } } }
In contrast with the 2.0 specification, file input/output content in OpenAPI is described with the same semantics as any other schema type. Refer to https://swagger.io/specification/.
type RequestBodyR ¶
type RequestBodyR struct { *RequestBody `json:""` Ref string `json:"$ref,omitempty"` }
RequestBodyR presents RequestBody or Ref combination
func (*RequestBodyR) SetMediaType ¶
func (r *RequestBodyR) SetMediaType(coding MediaTypeTitle, mediaType MediaType)
type Response ¶
type Response struct { // REQUIRED. A short description of the response. CommonMark syntax MAY be used for rich text representation. Description string `json:"description"` // 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. Headers Headers `json:"headers,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/* Content Content `json:"content,omitempty"` // 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. Links Links `json:"links,omitempty"` }
Response describes a single response from an API Operation, including design-time, static links to operations based on the response.
Response of an array of a complex type:
{ "description": "A complex object array response", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/VeryComplexType" } } } } }
Response with a string type:
{ "description": "A simple string response", "content": { "text/plain": { "schema": { "type": "string" } } } }
Plain text response with headers:
{ "description": "A simple string response", "content": { "text/plain": { "schema": { "type": "string", "example": "whoa!" } } }, "headers": { "X-Rate-Limit-Limit": { "description": "The number of allowed requests in the current period", "schema": { "type": "integer" } }, "X-Rate-Limit-Remaining": { "description": "The number of remaining requests in the current period", "schema": { "type": "integer" } }, "X-Rate-Limit-Reset": { "description": "The number of seconds left in the current period", "schema": { "type": "integer" } } } }
Response with no return value:
{ "description": "object created" }
type Responses ¶
Responses A container for the expected responses of an operation. The container maps a HTTP response code to the expected response.
The documentation is not necessarily expected to cover all possible HTTP response codes because they may not be known in advance. However, documentation is expected to cover a successful operation response and any known errors.
The default MAY be used as a default response object for all HTTP codes that are not covered individually by the specification.
The Responses Object MUST contain at least one response code, and it SHOULD be the response for a successful operation call.
{ "200": { "description": "a pet to be returned", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Pet" } } } }, "default": { "description": "Unexpected error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorModel" } } } } }
type Schema ¶
type Schema struct { // **JSON** The value of both of these keywords MUST be a string. // Both of these keywords can be used to decorate a user interface with // information about the data produced by this user interface. A title // will preferrably be short, whereas a description will provide // explanation about the purpose of the instance described by this // schema. Title string `json:"title,omitempty"` // **JSON** The value of both of these keywords MUST be a string. // Both of these keywords can be used to decorate a user interface with // information about the data produced by this user interface. A title // will preferrably be short, whereas a description will provide // explanation about the purpose of the instance described by this // schema. // // CommonMark syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // **JSON** The value of this keyword MUST be either a string or an array. If it // is an array, elements of the array MUST be strings and MUST be unique. // String values MUST be one of the seven primitive types defined by the // core specification. // An instance matches successfully if its primitive type is one of the // types defined by keyword. Recall: "number" includes "integer". // // Value MUST be a string. Multiple types via an array are not supported. Type string `json:"type,omitempty"` // **JSON** Implementations MAY support the "format" keyword. Should they choose // to do so: // they SHOULD implement validation for attributes defined below; // they SHOULD offer an option to disable validation for this keyword, // Implementations MAY add custom format attributes. Save for agreement // between parties, schema authors SHALL NOT expect a peer // implementation to support this keyword and/or custom format // attributes. // // See Data Type Formats for further details. While relying on JSON Schema's defined formats, the OAS offers a few additional predefined formats. Format string `json:"format,omitempty"` // **JSON** The value of this keyword MUST be an array. This array SHOULD have // at least one element. Elements in the array SHOULD be unique. // Elements in the array MAY be of any type, including null. // An instance validates successfully against this keyword if its value // is equal to one of the elements in this keyword's array value. Enum string `json:"enum,omitempty"` // **JSON** The value of "properties" MUST be an object. Each value of this // object MUST be an object, and each object MUST be a valid JSON Schema. // If absent, it can be considered the same as an empty object. // Property definitions MUST be a Schema Object and not a standard JSON Schema (inline or referenced). Properties map[string]SchemaR `json:"properties,omitempty"` // **JSON** The value of "additionalProperties" MUST be a boolean or a schema. // If "additionalProperties" is absent, it may be considered present with an empty schema as a value. // If "additionalProperties" is true, validation always succeeds. // If "additionalProperties" is false, validation succeeds only if the instance is an object and // all properties on the instance were covered by "properties" and/or "patternProperties". // If "additionalProperties" is an object, validate the value as a schema to all the properties // that weren't validated by "properties" nor "patternProperties". // Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. // Consistent with JSON Schema, additionalProperties defaults to true. // // 所有不列在properties與patternProperties的屬性都要符合這additionProperties規範。 // 不存在表示任意物件、ture表示皆可、false表示不允許額外的屬性(都需要列在properties與patternProperties裏面)、Schema表示需要符合該定義。 AdditionalProperties *SchemaR `json:"additionalProperties,omitempty"` // **JSON** The value of this keyword MUST be an array. This array MUST have at // least one element. Elements of this array MUST be strings, and MUST be unique. // An object instance is valid against this keyword if its property set // contains all elements in this keyword's array value. Required []string `json:"required,omitempty"` // **JSON** The value of this keyword MUST be an integer. This integer MUST be greater than, or equal to, 0. // An object instance is valid against "maxProperties" if its number of // properties is less than, or equal to, the value of this keyword. MaxProperties any `json:"maxProperties,omitempty"` // **JSON** The value of this keyword MUST be an integer. This integer MUST be // greater than, or equal to, 0. // An object instance is valid against "minProperties" if its number of // properties is greater than, or equal to, the value of this keyword. // If this keyword is not present, it may be considered present with a // value of 0. MinProperties any `json:"minProperties,omitempty"` // **JSON** The value of "additionalItems" MUST be either a boolean or an object. // If it is an object, this object MUST be a valid JSON Schema. // The value of "items" MUST be either a schema or array of schemas. // Successful validation of an array instance in regard to these two // keywords is determined as follows: // if "items" is not present, or its value is an object, validation // of the instance always succeeds, regardless of the value of "additionalItems"; // if the value of "additionalItems" is boolean value true or an // object, validation of the instance always succeeds; // if the value of "additionalItems" is boolean value false and the // value of "items" is an array, the instance is valid if its size is // less than, or equal to, the size of "items". // If either keyword is absent, it may be considered present with an // empty schema. // Value MUST be an object and not an array. Inline or referenced schema MUST be of a Schema Object and not // a standard JSON Schema. items MUST be present if the type is array. Items *SchemaR `json:"items,omitempty"` // **JSON** The value of this keyword MUST be an integer. This integer MUST be greater than, or equal to, 0. // An array instance is valid against "maxItems" if its size is less // than, or equal to, the value of this keyword. MaxItems any `json:"maxItems,omitempty"` // **JSON** The value of this keyword MUST be an integer. This integer MUST be greater than, or equal to, 0. // An array instance is valid against "minItems" if its size is greater // than, or equal to, the value of this keyword. // If this keyword is not present, it may be considered present with a // value of 0. MinItems any `json:"minItems,omitempty"` // **JSON** The value of this keyword MUST be a boolean. // If this keyword has boolean value false, the instance validates // successfully. If it has boolean value true, the instance validates // successfully if all of its elements are unique. // If not present, this keyword may be considered present with boolean // value false. UniqueItems bool `json:"uniqueItems,omitempty"` // **JSON** There are no restrictions placed on the value of this keyword. // This keyword can be used to supply a default JSON value associated // with a particular schema. It is RECOMMENDED that a default value be // valid against the associated schema. // // The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. // Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. // For example, if type is string, then default can be "foo" but cannot be 1. Default any `json:"default,omitempty"` // **JSON** This keyword's value MUST be an array. This array MUST have at least one element. // Elements of the array MUST be objects. Each object MUST be a valid JSON Schema. // An instance validates successfully against this keyword if it validates successfully against // all schemas defined by this keyword's value. // Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. AllOf []SchemaR `json:"allOf,omitempty"` // **JSON** This keyword's value MUST be an array. This array MUST have at least one element. // Elements of the array MUST be objects. Each object MUST be a valid JSON Schema. // An instance validates successfully against this keyword if it validates successfully against // at least one schema defined by this keyword's value. // Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. AnyOf []SchemaR `json:"anyOf,omitempty"` // **JSON** This keyword's value MUST be an array. This array MUST have at least one element. // Elements of the array MUST be objects. Each object MUST be a valid JSON Schema. // An instance validates successfully against this keyword if it validates successfully against // exactly one schema defined by this keyword's value. // Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. OneOf []SchemaR `json:"oneOf,omitempty"` // **JSON** This keyword's value MUST be an object. This object MUST be a valid JSON Schema. // An instance is valid against this keyword if it fails to validate successfully against // the schema defined by this keyword. // Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. Not *SchemaR `json:"not,omitempty"` // **JSON** The value of "multipleOf" MUST be a number, strictly greater than 0. // A numeric instance is only valid if division by this keyword's value // results in an integer. MultipleOf any `json:"multipleOf,omitempty"` // **JSON** The value of "maximum" MUST be a number, representing an upper limit for a numeric instance. // If the instance is a number, then this keyword validates if // "exclusiveMaximum" is true and instance is less than the provided // value, or else if the instance is less than or exactly equal to the // provided value. Maximum any `json:"maximum,omitempty"` // **JSON** The value of "exclusiveMaximum" MUST be a boolean, representing // whether the limit in "maximum" is exclusive or not. An undefined // value is the same as false. // If "exclusiveMaximum" is true, then a numeric instance SHOULD NOT be // equal to the value specified in "maximum". If "exclusiveMaximum" is // false (or not specified), then a numeric instance MAY be equal to the // value of "maximum". ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"` // **JSON** The value of "minimum" MUST be a number, representing a lower limit for a numeric instance. // If the instance is a number, then this keyword validates if // "exclusiveMinimum" is true and instance is greater than the provided // value, or else if the instance is greater than or exactly equal to // the provided value. Minimum any `json:"minimum,omitempty"` // **JSON** The value of "exclusiveMinimum" MUST be a boolean, representing whether // the limit in "minimum" is exclusive or not. An undefined value is the same as false. // If "exclusiveMinimum" is true, then a numeric instance SHOULD NOT be // equal to the value specified in "minimum". If "exclusiveMinimum" is // false (or not specified), then a numeric instance MAY be equal to the // value of "minimum". ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"` // **JSON** The value of this keyword MUST be a non-negative integer. // The value of this keyword MUST be an integer. This integer MUST be greater than, or equal to, 0. // A string instance is valid against this keyword if its length is less // than, or equal to, the value of this keyword. // The length of a string instance is defined as the number of its // characters as defined by RFC 7159 [RFC7159]. MaxLength any `json:"maxLength,omitempty"` // **JSON** A string instance is valid against this keyword if its length is // greater than, or equal to, the value of this keyword. // The length of a string instance is defined as the number of its // characters as defined by RFC 7159 [RFC7159]. // The value of this keyword MUST be an integer. This integer MUST be // greater than, or equal to, 0. // "minLength", if absent, may be considered as being present with // integer value 0. MinLength any `json:"minLength,omitempty"` // **JSON** The value of this keyword MUST be a string. This string SHOULD be a // valid regular expression, according to the ECMA 262 regular expression dialect. // // A string instance is considered valid if the regular expression matches the instance successfully. // Recall: regular expressions are not implicitly anchored. // (This string SHOULD be a valid regular expression, according to the Ecma-262 Edition 5.1 regular expression dialect) Pattern string `json:"pattern,omitempty"` // A true value adds "null" to the allowed type specified by the type keyword, only if type is explicitly defined within the same Schema Object. // Other Schema Object constraints retain their defined behavior, and therefore may disallow the use of null as a value. // A false value leaves the specified or default type unmodified. The default value is false. Nullable bool `json:"nullable,omitempty"` // Adds support for polymorphism. The discriminator is an object name that is used to differentiate between other schemas which may satisfy the payload description. // See Composition and Inheritance for more details. Discriminator *Discriminator `json:"discriminator,omitempty"` // Relevant only for Schema "properties" definitions. Declares the property as "read only". // This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request. // If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false. ReadOnly bool `json:"readOnly,omitempty"` // Relevant only for Schema "properties" definitions. Declares the property as "write only". Therefore, it MAY be sent as part of a request but SHOULD NOT be sent as part of the response. If the property is marked as writeOnly being true and is in the required list, the required will take effect on the request only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false. WriteOnly bool `json:"writeOnly,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. Xml *Xml `json:"xml,omitempty"` // Additional external documentation for this schema. ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"` // A free-form property to include an example of an instance for this schema. // To represent examples that cannot be naturally represented in JSON or YAML, // a string value can be used to contain the example with escaping where necessary. Example any `json:"example,omitempty"` // Specifies that a schema is deprecated and SHOULD be transitioned out of usage. Default value is false. Deprecated bool `json:"deprecated,omitempty"` }
The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. This object is an extended subset of the JSON Schema Specification Wright Draft 00. Refer to: https://swagger.io/specification/.
For more information about the properties, see JSON Schema Core and JSON Schema Validation. Unless stated otherwise, the property definitions follow the JSON Schema. Refer to: https://datatracker.ietf.org/doc/html/draft-wright-json-schema-00 and https://datatracker.ietf.org/doc/html/draft-wright-json-schema-validation-00.
Properties The following properties are taken directly from the JSON Schema definition and follow the same specifications:
- title
- multipleOf
- maximum
- exclusiveMaximum
- minimum
- exclusiveMinimum
- maxLength
- minLength
- pattern (This string SHOULD be a valid regular expression, according to the Ecma-262 Edition 5.1 regular expression dialect)
- maxItems
- minItems
- uniqueItems
- maxProperties
- minProperties
- required
- enum
The following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification.
- type - Value MUST be a string. Multiple types via an array are not supported.
- allOf - Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
- oneOf - Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
- anyOf - Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
- not - Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
- items - Value MUST be an object and not an array. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. items MUST be present if the type is array.
- properties - Property definitions MUST be a Schema Object and not a standard JSON Schema (inline or referenced).
- additionalProperties - Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. Consistent with JSON Schema, additionalProperties defaults to true.
- description - CommonMark syntax MAY be used for rich text representation.
- format - See Data Type Formats for further details. While relying on JSON Schema's defined formats, the OAS offers a few additional predefined formats.
- default - The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, if type is string, then default can be "foo" but cannot be 1.
Alternatively, any time a Schema Object can be used, a Reference Object can be used in its place. This allows referencing definitions instead of defining them inline.
Additional properties defined by the JSON Schema specification that are not mentioned here are strictly unsupported.
Other than the JSON Schema subset fields, the following fields MAY be used for further schema documentation.
Primitive sample
{ "type": "string", "format": "email" }
Simple model
{ "type": "object", "required": [ "name" ], "properties": { "name": { "type": "string" }, "address": { "$ref": "#/components/schemas/Address" }, "age": { "type": "integer", "format": "int32", "minimum": 0 } } }
Model with map/dictionary properties - for a simple string to string mapping:
{ "type": "object", "additionalProperties": { "type": "string" } }
Model with map/dictionary properties - for a string to model mapping:
{ "type": "object", "additionalProperties": { "$ref": "#/components/schemas/ComplexModel" } }
Model with example
{ "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" } }, "required": [ "name" ], "example": { "name": "Puma", "id": 1 } }
Models with composition
{ "components": { "schemas": { "ErrorModel": { "type": "object", "required": [ "message", "code" ], "properties": { "message": { "type": "string" }, "code": { "type": "integer", "minimum": 100, "maximum": 600 } } }, "ExtendedErrorModel": { "allOf": [ { "$ref": "#/components/schemas/ErrorModel" }, { "type": "object", "required": [ "rootCause" ], "properties": { "rootCause": { "type": "string" } } } ] } } } }
Models with polymorphism support
{ "components": { "schemas": { "Pet": { "type": "object", "discriminator": { "propertyName": "petType" }, "properties": { "name": { "type": "string" }, "petType": { "type": "string" } }, "required": [ "name", "petType" ] }, "Cat": { "description": "A representation of a cat. Note that `Cat` will be used as the discriminator value.", "allOf": [ { "$ref": "#/components/schemas/Pet" }, { "type": "object", "properties": { "huntingSkill": { "type": "string", "description": "The measured skill for hunting", "default": "lazy", "enum": [ "clueless", "lazy", "adventurous", "aggressive" ] } }, "required": [ "huntingSkill" ] } ] }, "Dog": { "description": "A representation of a dog. Note that `Dog` will be used as the discriminator value.", "allOf": [ { "$ref": "#/components/schemas/Pet" }, { "type": "object", "properties": { "packSize": { "type": "integer", "format": "int32", "description": "the size of the pack the dog is from", "default": 0, "minimum": 0 } }, "required": [ "packSize" ] } ] } } } }
type SchemaR ¶
SchemaR presents Schema or Ref combination
func (*SchemaR) ApplyAdditionalProperties ¶
func (*SchemaR) ApplyAllOf ¶
func (*SchemaR) ApplyAnyOf ¶
func (*SchemaR) ApplyOneOf ¶
type SecurityRequirement ¶
SecurityRequirement Lists the required security schemes to execute this operation. The name used for each property MUST correspond to a security scheme declared in the Security Schemes under the Components Object.
Security Requirement Objects that contain multiple schemes require that all schemes MUST be satisfied for a request to be authorized. This enables support for scenarios where multiple query parameters or HTTP headers are required to convey security information.
When a list of Security Requirement Objects is defined on the OpenAPI Object or Operation Object, only one of the Security Requirement Objects in the list needs to be satisfied to authorize the request.
Each name MUST correspond to a security scheme which is declared in the Security Schemes under the Components Object. If the security scheme is of type "oauth2" or "openIdConnect", then the value is a list of scope names required for the execution, and the list MAY be empty if authorization does not require a specified scope. For other security scheme types, the array MUST be empty.
Non-OAuth2 Security Requirement
{ "api_key": [] }
OAuth2 Security Requirement
{ "petstore_auth": [ "write:pets", "read:pets" ] }
Optional OAuth2 security as would be defined in an OpenAPI Object or an Operation Object:
{ "security": [ {}, { "petstore_auth": [ "write:pets", "read:pets" ] } ] }
type SecurityScheme ¶
type SecurityScheme struct { Type string `json:"type"` Scheme string `json:"scheme,omitempty"` BearerFormat string `json:"bearerFormat,omitempty"` In InWay `json:"in,omitempty"` Name string `json:"name,omitempty"` OpenIdConnectUrl string `json:"openIdConnectUrl,omitempty"` }
SecurityScheme describes security scheme for OpenAPI document. https://swagger.io/docs/specification/authentication/
type SecuritySchemeR ¶
type SecuritySchemeR struct { *SecurityScheme `json:""` Ref string `json:"$ref,omitempty"` }
SecuritySchemeR presents SecurityScheme or Ref combination
type SecuritySchemes ¶
type SecuritySchemes map[string]SecuritySchemeR
func (*SecuritySchemes) AppendApiKeyAuth ¶ added in v0.1.0
func (s *SecuritySchemes) AppendApiKeyAuth(name string, paramIn InWay, paramName string) *SecuritySchemes
func (*SecuritySchemes) AppendBasicAuth ¶ added in v0.1.0
func (s *SecuritySchemes) AppendBasicAuth(name string) *SecuritySchemes
func (*SecuritySchemes) AppendBearerAuth ¶ added in v0.1.0
func (s *SecuritySchemes) AppendBearerAuth(name string) *SecuritySchemes
func (*SecuritySchemes) AppendOpenId ¶ added in v0.1.0
func (s *SecuritySchemes) AppendOpenId(name string, openIdConnectUrl string) *SecuritySchemes
func (*SecuritySchemes) AppendScheme ¶ added in v0.1.0
func (s *SecuritySchemes) AppendScheme(name string, scheme SecurityScheme) *SecuritySchemes
type Server ¶
type Server struct { // 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}. Url string `json:"url"` // ex. https://development.gigantic-server.com/v1 // An optional string describing the host designated by the URL. CommonMark syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` // A map between a variable name and its value. The value is used for substitution in the server's URL template. Variables map[string]ServerVariable `json:"variables,omitempty"` }
Server is an object representing a Server.
{ "url": "https://development.gigantic-server.com/v1", "description": "Development server" }
The following shows how multiple servers can be described, for example, at the OpenAPI Object's servers:
{ "servers": [ { "url": "https://development.gigantic-server.com/v1", "description": "Development server" }, { "url": "https://staging.gigantic-server.com/v1", "description": "Staging server" }, { "url": "https://api.gigantic-server.com/v1", "description": "Production server" } ] }
type ServerVariable ¶
type ServerVariable struct { // An enumeration of string values to be used if the substitution options are from a limited set. The array SHOULD NOT be empty. Enum []string `json:"enum,omitempty"` // REQUIRED. The default value to use for substitution, which SHALL be sent if an alternate value is not supplied. // Note this behavior is different from the Schema Object's treatment of default values, because in those cases parameter values are optional. // If the enum is defined, the value SHOULD exist in the enum's values. Default string `json:"default"` // An optional description for the server variable. CommonMark syntax MAY be used for rich text representation. Description string `json:"description,omitempty"` }
ServerVariable is an object representing a Server Variable for server URL template substitution.
{ "url": "https://{username}.gigantic-server.com:{port}/{basePath}", "description": "The production API server", "variables": { "username": { "default": "demo", "description": "this value is assigned by the service provider, in this example `gigantic-server.com`" }, "port": { "enum": [ "8443", "443" ], "default": "8443" }, "basePath": { "default": "v2" } } }
type Tag ¶
type Tag struct { // REQUIRED. The name of the tag. Name string `json:"name"` // A short description for the tag. CommonMark syntax MAY be used for rich text representation. Description string `json:"description"` // Additional external documentation for this tag. ExternalDocs *ExternalDoc `json:"externalDocs,omitempty"` }
Tag adds metadata to a single tag that is used by the Operation Object. It is not mandatory to have a Tag Object per tag defined in the Operation Object instances.
{ "name": "pet", "description": "Pets operations" }
type VariableKind ¶
type VariableKind int
const ( VarKindUnsupported VariableKind = iota VarKindBase VarKindObject VarKindArray )
func GetVariableKind ¶
func GetVariableKind(t reflect.Type) VariableKind
type WithContent ¶
type WithContent struct {
Content Content `json:"content,omitempty"`
}
WithContent For more complex scenarios, the content property can define the media type and schema of the parameter. A parameter MUST contain either a schema property, or a content property, but not both. When example or examples are provided in conjunction with the schema object, the example MUST follow the prescribed serialization strategy for the parameter.
type WithSchemaAndStyle ¶
type WithSchemaAndStyle struct { // Describes how the parameter value will be serialized depending on the type of the parameter value. // Default values (based on value of in): for query - form; for path - simple; for header - simple; for cookie - form. // In order to support common ways of serializing simple parameters, a set of style values are defined. // // | style |type |in |Comments // | ---------------------------------------------------------------------------------------------- // | matrix |primitive, array, object |path |Path-style parameters defined by RFC6570 // | label |primitive, array, object |path |Label style parameters defined by RFC6570 // | form |primitive, array, object |query,cookie|Form style parameters defined by RFC6570. This option replaces collectionFormat with a csv (when explode is false) or multi (when explode is true) value from OpenAPI 2.0. // | simple |array |path,header |Simple style parameters defined by RFC6570. This option replaces collectionFormat with a csv value from OpenAPI 2.0. // | spaceDelimited|array |query |Space separated array values. This option replaces collectionFormat equal to ssv from OpenAPI 2.0. // | pipeDelimited |array |query |Pipe separated array values. This option replaces collectionFormat equal to pipes from OpenAPI 2.0. // | deepObject |object |query |Provides a simple way of rendering nested objects using form parameters. Style string `json:"style,omitempty"` // When this is true, parameter 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 parameters this property has no effect. When style is form, the default value is true. For all other styles, the default value is false. Explode bool `json:"explode,omitempty"` // Determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986 :/?#[]@!$&'()*+,;= to be included without percent-encoding. // This property only applies to parameters with an in value of query. The default value is false. AllowReserved bool `json:"allowReserved,omitempty"` // The schema defining the type used for the parameter. Schema *SchemaR `json:"schema,omitempty"` // Example of the parameter's potential value. The example SHOULD match the specified schema and encoding properties if present. // The example field is mutually exclusive of the examples field. Furthermore, if referencing a schema that contains an example, // the example value SHALL override the example provided by the schema. To represent examples of media types // that cannot naturally be represented in JSON or YAML, a string value can contain the example with escaping where necessary. Example any `json:"example,omitempty"` // Examples of the parameter's potential value. Each example SHOULD contain a value in the correct // format as specified in the parameter encoding. The examples field is mutually exclusive of the example field. // Furthermore, if referencing a schema that contains an example, the examples value SHALL override the example provided by the schema. Examples map[string]ExampleR `json:"examples,omitempty"` }
WithSchemaAndStyle The rules for serialization of the parameter are specified in one of two ways. For simpler scenarios, a schema and style can describe the structure and syntax of the parameter.
Source Files
¶
- callback.go
- components.go
- contact.go
- discriminator.go
- encoding.go
- example.go
- external_doc.go
- header.go
- info.go
- license.go
- link.go
- media_type.go
- openapi.go
- operation.go
- parameter.go
- path.go
- ref.go
- request_body.go
- response.go
- schema.go
- security_requirement.go
- security_scheme.go
- server.go
- tag.go
- type_utils.go
- xml.go