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

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