Swagger Schema

Schema

Swagger Object

This is the root document object for the API specification. It combines what previously was the Resource Listing and API Declaration (version 1.2 and earlier) together into one document.html

这是API规范的根文档对象。它把此前的资源列表(Resource Listing)和API声明(Declaration)(1.2 及更早版本) 放到了一个文档里。git

Fixed Fields
Field Name Type Description
swagger string Required. Specifies the Swagger Specification version being used. It can be used by the Swagger UI and other clients to interpret the API listing. The value MUST be "2.0". 必须 定义了所使用的Swagger定义的版本。能够被Swagger UI和其余客户端解释API列表。这个必须是"2.0"`.
info Info Object Required. Provides metadata about the API. The metadata can be used by the clients if needed.必须字段提供了API的元数据信息。元数据必要的时候能够被客户端所使用。
host string The host (name or ip) serving the API. This MUST be the host only and does not include the scheme nor sub-paths. It MAY include a port. If the host is not included, the host serving the documentation is to be used (including the port). The host does not support path templating. 提供API服务的主机名称或者IP。这个字段必须只能是主机名,而不是包好阔scheme和子路径。该字段能够包括一个端口号。若是未指定host字段,提供当前文档自己的host将会被使用(包括端口)。host 字段不支持path templating.
basePath string The base path on which the API is served, which is relative to the host. If it is not included, the API is served directly under the host. The value MUST start with a leading slash (/). The basePath does not support path templating. 定义了提供API服务端的基础路径,这个路径是相对于host的。该字段的值必须开始于(/)。basePath 不支持path templating
schemes [string] The transfer protocol of the API. Values MUST be from the list: "http", "https", "ws", "wss". If the schemes is not included, the default scheme to be used is the one used to access the Swagger definition itself. 定义了API的传输协议。取值必须为如下值之一: "http", "https", "ws", "wss"。若是没有指定schemes 字段,访问当前Swagger定义文件的默认scheme将会被使用。
consumes [string] A list of MIME types the APIs can consume. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under Mime Types.一个API可接受的MIME类型列表。这是对全部API的全局设置,可是能够被特定的API调用设置覆盖。取值必须是下面Mime Types所描述的。
produces [string] A list of MIME types the APIs can produce. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under Mime Types.一个API可能会返回的MIME类型列表。这是对全部API的全局设置,可是能够被特定的API调用设置覆盖。取值必须是下面Mime Types所描述的。
paths Paths Object Required. The available paths and operations for the API. 必须字段 定义了API中可用的路径以及操做。
definitions Definitions Object An object to hold data types produced and consumed by operations. 操做可能会接收或者返回的保存各类类型数据的对象。
parameters Parameters Definitions Object An object to hold parameters that can be used across operations. This property does not define global parameters for all operations. 能够跨操做传递参数的一个对象。这个属性不会为全部的操做定义参数。
responses Responses Definitions Object An object to hold responses that can be used across operations. This property does not define global responses for all operations. 能够被各个操做使用的持有应答信息的对象。这个属性不会为全部的操做定义全局的应答。
securityDefinitions Security Definitions Object Security scheme definitions that can be used across the specification. 被整个规范所使用的安全scheme定义。
security [Security Requirement Object] A declaration of which security schemes are applied for the API as a whole. The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). Individual operations can override this definition. 一个定义了哪一种安全sheme总体应用到API的声明。值中列出了备选的安全scheme(也就是说安全要求之间是个逻辑OR的关系)。单个操做能够覆盖这个定义。
tags [Tag Object] 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. 被规范所使用的一组tag列表,带有附加的元数据。标签的属性努能够用来被解析工具用来反射他们的顺序。不是全部被Operation Object 所使用的标签都必定要声明。未声明的标签能够被随机的组织,或者按照工具的逻辑组织。列表中的每一个标签必须是惟一的。
externalDocs External Documentation Object Additional external documentation. 附加的外部文档。
Patterned Objects
Field Pattern Type Description
^x- Any Allows extensions to the Swagger Schema. The field name MUST begin with x-, for example, x-internal-id. The value can be null, a primitive, an array or an object. See Vendor Extensions for further details. 容许对Swagger Schema进行扩展。这种字段名必须以x-为前缀,例如,x-internal-id。这个值能够设为null,一个原生类型,一个数组或者一个对象。参阅Vendor Extensions以得到进一步的细节。

Info Object

The object provides metadata about the API. The metadata can be used by the clients if needed, and can be presented in the Swagger-UI for convenience.github

Fixed Fields
Field Name Type Description
title string Required. The title of the application. 必须字段 定义了应用的标题。
description string A short description of the application. [GFM syntax] (https://help.github.com/articles/github-flavored-markdown) can be used for rich text representation. 一个对应用的简短描述。[GFM 语法] (https://help.github.com/articles/github-flavored-markdown) ,可被用来表现为富文本。
termsOfService string The Terms of Service for the API. API的服务条款。
contact Contact Object The contact information for the exposed API. 所导出的API的联系人信息。
license License Object The license information for the exposed API. 暴露的API的受权信息。
version string Required Provides the version of the application API (not to be confused with the specification version). 必须字段 提供了应用API的版本号(不要与Swagger规范的版本号搞混了)
Patterned Objects
Field Pattern Type Description
^x- Any Allows extensions to the Swagger Schema. The field name MUST begin with x-, for example, x-internal-id. The value can be null, a primitive, an array or an object. See Vendor Extensions for further details.
Info Object Example:
{
  "title": "Swagger Sample App",
  "description": "This is a sample server Petstore server.",
  "termsOfService": "http://swagger.io/terms/",
  "contact": {
    "name": "API Support",
    "url": "http://www.swagger.io/support",
    "email": "support@swagger.io"
  },
  "license": {
    "name": "Apache 2.0",
    "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
  },
  "version": "1.0.1"
}
title: Swagger Sample App
description: This is a sample server Petstore server.
termsOfService: http://swagger.io/terms/
contact:
  name: API Support
  url: http://www.swagger.io/support
  email: support@swagger.io
license:
  name: Apache 2.0
  url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.1
相关文章
相关标签/搜索