Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add request schema to swagger description

I am using .Net core 3.1 and working on documenting API actions in Swagger and want to document request body so that it would show all details like data types, validations etc to the end users.

Currently, I am hard coding the schema in xml comments as follows-

    /// <summary>
    /// Order Details
    /// </summary>
    /// <remarks>
    /// Parameter's description:
    ///
    ///     {
    ///        "productName": string,                           -- Required
    ///        "isUsed: true,                                   
    ///        "orderDate": "2021-02-19T08:43:10.300Z",         -- Required
    ///        "discountDate": "2021-02-19T08:43:10.300Z"
    ///     }       
    /// </remarks>
    /// <returns>Returns Order results</returns>  
    /// <response code="200">Order Placed</response>           
    [HttpPost]
    [Route("Place Order")]
    public ActionResult<OrderPlacingResult> PlaceOrder(OrderPlaceParam orderPlaceParam)
    {
         ///
    }

This gives the desired result and is feasible for small request body. However, if the request contains lots of parameters, it would not be advisable to hard code it in the description section.

Can anyone suggest a better way to document parameters such that it will give all the details that it provides in the schema.
Please note the request has no actual parameters, I want to document request body.

like image 769
Soft_API_Dev Avatar asked Apr 27 '26 10:04

Soft_API_Dev


1 Answers

Instead of describing parameters itself in remarks section of the method/function, request/response models should be documented itself (apply summary tag). Later on it can be found in swagger documentation. Check all screenshots bellow please to see how it works in action.

P.S. I attached screenshots instead of classes on purpose as code from production, sorry.

XML tags applied to controller Example of request model Example of method in UI Schema of request model Schema of response model

like image 168
Serge P Avatar answered Apr 30 '26 16:04

Serge P



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!