cancel
Showing results for 
Search instead for 
Did you mean: 

How to set default values into Swagger form

New Contributor

How to set default values into Swagger form

Hi,

I have a Swagger ui and a C# Controller with a GET.

Tha GET need's a json File as atribute.
Each time I will test my Api I have to write surtain values into the form (json).
Because it is allways the same value, I would like to have a prefilled field.

How can I set default values into this Swagger form?
Thanks for help.
Frank

2 REPLIES 2
New Contributor

Re: How to set default values into Swagger form

Hi Frank.

 

I think you need to use the example property. 

parameters:
  - in: query
    name: status
    schema:
      type: string
      enum: [approved, pending, closed, new]
      example: approved  

 

You can find more information in this link:

https://swagger.io/docs/specification/adding-examples/

 

Have a nice day. 

New Contributor

Re: How to set default values into Swagger form

Thanks for your Reply!
But I'm not looking for examples, I'm looking for default values.
This I find here: https://swagger.io/docs/specification/describing-parameters/
And also I have no idea how to implement this (also this linked example with exaples) in the C# Rest Api controller.

Frank

 

This code don't work:

        [HttpGet()]
        [Get /MetaDataRequest?ResourceID='123'] // That's wrong. But I do it right?
        public IActionResult Get(MetaDataRequest json)
        { ...
New Here?
Join us and watch the welcome video:
Watch the new interview
Top Kudoed Authors