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 に答える