Home > database >  Example values(placeholder) for query parameters in Swagger (swashbuckle)
Example values(placeholder) for query parameters in Swagger (swashbuckle)

Time:12-16

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?

CodePudding user response:

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

  • Related