2

Hi i am trying to send the Default values through body parameters but its Not taking while Submitting. can anybody please help me on this issue. Here is my code and i am trying to send the default name parameter through body

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
Jeevan
  • 756
  • 13
  • 39

2 Answers2

2

The default value should be handled in the server side as the server should not always assume the client sends HTTP requests that are 100% conforming to the spec.

William Cheng
  • 10,137
  • 5
  • 54
  • 79
1

I think this can help you, if you are trying to send default data with your schema:

definitions:
 Pet:
  type: object
  default:
    name: xxxx
    birthday: xxxx 
  properties:
    name:
      type: string
    birthday:
      type: integer
      format: int32
0_o
  • 487
  • 4
  • 14