question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to send the Default value through body in Swagger 2.0

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
webroncommented, Sep 28, 2016

@Alin-Barsan I’m not really sure what you mean by ‘web view’ - don’t know which project you’re referring to. However, by the sound of what you’re describing, again, this is not related to swagger-core. Please open a ticket on whichever project you experience the issue with.

0reactions
SafalTammewarcommented, May 31, 2019

@jeevanhr7 In swagger 2.0 for body parameters default value is set by “example” keyword

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send the Default value through body in Swagger 2.0
The default value should be handled in the server side as the server should not always assume the client sends HTTP requests that...
Read more >
Describing Request Body - Swagger
The POST, PUT and PATCH requests can have the request body (payload), such as JSON or XML data. In Swagger terms, the request...
Read more >
Describing Parameters - Swagger
A constant parameter is always sent by the client, whereas the default value is something that the server uses if the parameter is...
Read more >
OpenAPI Specification - Version 2.0 - Swagger
This is valid only for either query or formData parameters and allows you to send a parameter with a name only or an...
Read more >
Describing Parameters - Swagger
An API call may require that custom headers be sent with an HTTP request. Swagger lets you define custom request headers as in:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found