2

嗨,我正在尝试通过正文参数发送默认值,但在提交时未使用。任何人都可以在这个问题上帮助我。这是我的代码,我正在尝试通过正文发送默认名称参数

swagger: '2.0'
info:
  version: 1.0.0
  title: PetStore on Heroku
  description: |
    **This example has a working backend hosted in Heroku**

    You can try all HTTP operation described in this Swagger spec.

    Find source code of this API [here](https://github.com/mohsen1/petstore-api)
host: petstore-api.herokuapp.com
basePath: /pet
schemes:
  - http
  - https
consumes:
  - application/json
  - text/xml
produces:
  - application/json
  - text/html
paths:
  /:
    get:
      parameters:
        - name: limit
          in: query
          description: number of pets to return
          type: integer
          default: 0
      responses:
        200:
          description:  List all pets
          schema:
            title: Pets
            type: array
            items:
              $ref: '#/definitions/Pet'
    post:
      parameters:
        - name: pet
          in: body
          description: The pet JSON you want to post
          schema:
            $ref: '#/definitions/Pet'
          required: true
      responses:
        200:
          description: Make a new pet
    put:
      parameters:
        - name: pet
          in: body
          description: The pet JSON you want to post
          schema:
            $ref: '#/definitions/Pet'
          required: true
      responses:
        200:
          description: Updates the pet
  /{petId}:
    get:
      parameters:
        - name: petId
          in: path
          type: string
          description: ID of the pet
          required: true
      responses:
        200:
          description: Sends the pet with pet Id

definitions:
  Pet:
    type: object
    properties:
      name:
        type: string
        default : "xxxxxxx"
      birthday:
        type: integer
        format: int32
4

2 回答 2

2

默认值应在服务器端处理,因为服务器不应总是假定客户端发送 100% 符合规范的 HTTP 请求。

于 2016-07-03T14:13:05.253 回答
1

如果您尝试使用架构发送默认数据,我认为这可以帮助您:

definitions:
 Pet:
  type: object
  default:
    name: xxxx
    birthday: xxxx 
  properties:
    name:
      type: string
    birthday:
      type: integer
      format: int32
于 2016-11-15T22:52:22.860 回答