Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send the Default value through body in Swagger 2.0 #1844

Closed
jeevanhr7 opened this issue Jul 3, 2016 · 11 comments
Closed

How to send the Default value through body in Swagger 2.0 #1844

jeevanhr7 opened this issue Jul 3, 2016 · 11 comments

Comments

@jeevanhr7
Copy link

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
@webron
Copy link
Contributor

webron commented Jul 5, 2016

How is this issue related to swagger-core?

Also, I think you're missing the point of the default value. The default value is one that's assumed by the receiving end (either the server or the client) if the sender does not provide a value for it - it's not what automatically should be filled.

@marcellodesales
Copy link

Is this related to springfox/springfox#1345 (comment)? The authors of SpringFox claim that the reason why their Swagger UI integration does not take default body is that your API is not taking the default body.

@jeevanhr7 Is this related to your issue?

@webron Can you please confirm that? For the case of Swagger UI, wouldn't we need to have the support for default values?

@webron
Copy link
Contributor

webron commented Sep 13, 2016

There's nothing in this ticket to even suggest it's related to java, let alone swagger-core specifically.

Regarding the general question - body parameters can have default values. The Schema Object has a default field in it.

@dilipkrish
Copy link
Contributor

@webron I think the problem is that BodyParameter doesn't support setting the default value.

@webron
Copy link
Contributor

webron commented Sep 19, 2016

@dilipkrish the BodyParameter has a default under the schema, as the spec describes - https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-models/src/main/java/io/swagger/models/ModelImpl.java#L31, it's not supposed to be directly under the parameter itself. Let me know if you think something is missing. Right now, it looks like potentially accessors are missing from Model.

@marcellodesales
Copy link

@webron thanks for checking this...

@dilipkrish Could you verify what @webron was referring to about the Model? The body to our API is a complex type that it is very hard to produce... That's why I need to get an instance of the payload built and injected through SpringFox...

Thank you guys!

@Alin-Barsan
Copy link

I'm also having somewhat of an issue using the "default" value for a Body Parameter. I have editor.swagger.io confirming that the setup is valid, and I included the "default" value under "schema" like @webron recommended.

However, the "default" field does not seem to be populated in the text field in the web view of the API. Every other "default" value properly populates for non-body parameters. @webron is this issue what you were referring to when you mentioned "potentially accessors are missing from Model."?

@webron
Copy link
Contributor

webron commented 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.

@Alin-Barsan
Copy link

@webron Hi Ron, thanks for the response! By 'web view' I meant the Swagger UI, I'll go ahead and search for a relevant ticket (or open a new one if none exists) on that project.

@webron
Copy link
Contributor

webron commented Sep 28, 2016

@Alin-Barsan - thanks.

@marcellodesales - I'm afraid I don't see the source of confusion.

@SafalTammewar
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants