2016-07-03 2 views
2

Привет, я пытаюсь отправить значения по умолчанию через параметры тела, но не принимает его при отправке. кто-нибудь может помочь мне по этому вопросу. Вот мой код, и я пытаюсь отправить по умолчанию имени параметра в через телоКак отправить значение по умолчанию через тело в Swagger 2.0

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 

ответ

2

Значение по умолчанию должно быть обработано на стороне сервера в качестве сервера не всегда должно взять на себя клиент посылает запросы HTTP, которые 100 % соответствует спецификации.

+0

ок я могу Обращаться в стороне сервера, но, что использование по умолчанию в Swagger. – Jeevan

+0

Вы также можете использовать спецификацию swagger для создания заглушки сервера, которая должным образом должна обрабатывать значение по умолчанию, указанное в спецификации. –

1

Я думаю, что это может помочь вам, если вы пытаетесь отправить данные по умолчанию с вашей схемой:

definitions: 
Pet: 
    type: object 
    default: 
    name: xxxx 
    birthday: xxxx 
    properties: 
    name: 
     type: string 
    birthday: 
     type: integer 
     format: int32 
Смежные вопросы