Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example values(placeholder) for query parameters in Swagger (swashbuckle)

I'm using swashbuckle in net core to create a swagger documented API.

The function I have uses query parameters. I wanted to add a short description for each query parameter, next to the textbox where the parameter value is entered. I achieved this by using XML comments:

/// <param name="propertyId">The integration property ID. Events related to presentations related to this ID will be returned</param>
public ActionResult GetEvents([BindRequired] string propertyId){}

This works fine, but it also adds the description text in the textbox placeholder: enter image description here

I saw that the placeholder can be changed, if the generated JSON has an 'example' value for the query parameter. How do I add the example value, or change the placeholder in general using the XML comments or something similar?

like image 940
Filip5991 Avatar asked Oct 20 '25 10:10

Filip5991


1 Answers

You can try to add example="xxx" into <param></param> to add the example value and change the placeholder.

  /// <param name="propertyId" example="id">The integration property ID. Events related to presentations related to this ID will be returned</param>
        public IActionResult GetEvents([BindRequired] string propertyId) {
            ...
        }

result: enter image description here

like image 185
Yiyi You Avatar answered Oct 22 '25 03:10

Yiyi You



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!