Generating XML File for the Project and add it to swagger it will help you generating swagger Documentation. Follow below steeps
Step:1 Suppose your Project is TestAPI
add below lines to TestAPI.csproj
file
<PropertyGroup>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<DocumentationFile>TestAPI.xml</DocumentationFile>
</PropertyGroup>
After saving you will get TestAPI.xml
file in your project directory.
Step:2 configure builder.Services.AddSwaggerGen()
as below. it will add TestAPI.xml
file to your swagger documentation
builder.Services.AddSwaggerGen(c =>
{
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
if (File.Exists(xmlFile))
{
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
}
});
what ever written in summary
will give you as shown in below
/// <summary>
/// Test Service is used To
/// </summary>
/// <param name="id"> key of The Record </param>
/// <response code="200">On Successfull Request</response>
[HttpGet("TestServe")]
public IActionResult TestServe(string id)
{
return Ok();
}

step:3 decorate property with example as shown in below it modify the json value with example value.
/// <summary>
/// To Create Test
/// </summary>
/// <param name="Inp">Sample Request</param>
/// <response code="200">On Successfull Create</response>
[HttpPost("TestCreate")]
public IActionResult TestCreate(MyTestClass Inp)
{
return Ok();
}
public class MyTestClass
{
/// <example>1</example>
public int Id { get; set; }
/// <example>Upender</example>
public string? Name { get; set; }
}

follow SampleProject