1

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.

3
  • Does this help? stackoverflow.com/questions/52775462 Commented Oct 26, 2021 at 14:22
  • What you mean is that you want to customize the content you need to modify in the Parameters module in the request API without passing parameters? Commented Oct 27, 2021 at 2:46
  • The API doesn't contain any FromQuery or FromRoute parameters. It's parameter-less, therefore swagger shows up 'No Parameters' message on UI. Yes, I want to customize that message. Commented Oct 27, 2021 at 18:00

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.