swagger例子

Data Types

Primitive data types in the Swagger Specification are based on the types supported by the JSON-Schema Draft 4. Models are described using the Schema Object which is a subset of JSON Schema Draft 4.

An additional primitive data type "file" is used by the Parameter Object and the Response Object to set the parameter type or the response as being a file.

Primitives have an optional modifier property format. Swagger uses several known formats to more finely define the data type being used. However, the format property is an open string-valued property, and can have any value to support documentation needs. Formats such as "email""uuid", etc., can be used even though they are not defined by this specification. Types that are not accompanied by a format property follow their definition from the JSON Schema (except for file type which is defined above). The formats defined by the Swagger Specification are:

Common NametypeformatComments
integerintegerint32signed 32 bits
longintegerint64signed 64 bits
floatnumberfloat 
doublenumberdouble 
stringstring  
bytestringbytebase64 encoded characters
binarystringbinaryany sequence of octets
booleanboolean  
datestringdateAs defined by full-date - RFC3339
dateTimestringdate-timeAs defined by date-time - RFC3339
passwordstringpasswordUsed to hint UIs the input needs to be obscured.
  /login:
    post:
      parameters:
        - in: formData
          name: account
          description: phone num
          type: string
          default: "13800138000"
        - in: formData
          name: password
          type: string
          format: password
          required: true
      responses:
        200:
          description: Echo test-path
          schema:
            $ref: "#/definitions/response"
          examples:
            application/json:
              {
                code: 404,
                message: 接口不存在,
                result:
                {
                  request: null,
                  code: 123456
                }
              }
definitions:
  response:
    type: object
    properties:
      code:
        type: integer
        description: 错误码
      message:
        type: string
        description: 错误信息
      result: 
        type: object
        properties:
          request:
            type: object

 

Parameter Types

Swagger distinguishes between the following parameter types based on the parameter location. The location is determined by the parameter’s in key, for example, in: query or in: path.

  • query parameters, such as /users?role=admin            in: query
  • path parameters, such as /users/{id}            in: path
  • header parameters, such as X-MyHeader: Value           in: header
  • body parameters that describe the body of POST, PUT and PATCH requests (see Describing Request Body)      in: body
  • form parameters – a variety of body parameters used to describe the payload of requests with Content-Type of application/x-www-form-urlencoded and multipart/form-data (the latter is typically used for file uploads)           in: formData

Required and Optional Parameters

Default Parameter Values

 

Enum Parameters

The enum keyword allows you to restrict a parameter value to a fixed set of values. The enum values must be of the same type as the parameter type.

        - in: query
          name: status
          type: string
          enum: [available, pending, sold]

More info: Defining an Enum.

转载于:https://www.cnblogs.com/cdyboke/p/7093827.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值