mazury
mazury

Reputation: 187

How to override description 'No parameters' in Swagger for .Net Core Web Api?

In .Net Core Web Api project I have Get which doesn't need request data to be passed on. By default SwaggerUi generates 'No parameters' description under Parameters tab. See below.

enter image description here

My aim is to replace 'No parameters' string with something else. I'd like to add additional information why there is no need for parameters. If it's possible, then please share a knowledge.

Upvotes: 1

Views: 1936

Answers (1)

Tupac
Tupac

Reputation: 2910

I haven’t found a way to modify the custom content of parameters after searching for a long time, but you can add the remarks you need on the url, like this:

For enabling XML comments, we need to do the following steps:

1.In the Build tab of the project properties, check the box labeled XML documentation file. Let’s keep the auto-generated file path.

2.Suppress warning 1591, which will now give warnings about any method, class, or field that doesn’t have triple-slash comments.

enter image description here

In the ConfigureServices() method, configure Swagger to use the XML file that’s generated in the above step:

public void ConfigureServices(IServiceCollection services)
{
    // Register the Swagger generator, defining 1 or more Swagger documents
    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new OpenApiInfo
       //......TODO

// Set the comments path for the Swagger JSON and UI.
        var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
        var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
        c.IncludeXmlComments(xmlPath);
    });

Now, adding triple-slash comments to the action method enhances the Swagger UI by adding a description to the section header.

 /// <summary>
        /// This is test    
        /// </summary>
        /// 
        /// 
       [Route("test")]
       [HttpGet]
        public string Test()
        {
            return "v1 test";
        }

Result:

enter image description here

Upvotes: 2

Related Questions