How to add API description in Swashbuckle?

I am new to Swashbuckl or Swagger, but I created a web API for which I need to create documentation using Swagger from my client. I have already created it, but they require that the version information of the API is displayed in the Swageer user interface, which I am not sure about how to achieve.

Here is my code:

public class SwaggerConfig
{
    public static void Register()
    {
        var thisAssembly = typeof(SwaggerConfig).Assembly;

        GlobalConfiguration.Configuration
            .EnableSwagger(c =>
                {
                    c.SingleApiVersion("v1", "Demo Api");
                    c.IncludeXmlComments(string.Format(@"{0}\bin\WebApi.XML",
                                         System.AppDomain.CurrentDomain.BaseDirectory));
                })
        .EnableSwaggerUi();

    }
}

Controller example:

     /// <summary>
    /// Get the Next IdKey
    /// </summary>
    /// <remarks>Get the Next IdKey from Dettagli Table</remarks>
    /// <response code="404">Not found</response>
    /// <response code="500">Internal Server Error</response>
    [HttpGet]
    public int GetNextIdDettagli()
    {
        try
        {
            DettagliRepo repo = new DettagliRepo();
            return repo.GetNextIdDettagli();
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }

This is how all the controller actions were performed.

Here is the result of my Swagger interface:

enter image description here

This is the expected result from my client, marked 1,2 and 3:

enter image description here

I can understand from the screen that they want to show the API description, name and other information, but I don’t know how to show them. please help me or suggest me how to achieve this part. Thanks in advance.

Update

I reached 1 and 2 of the following link

with the following code:

                   .EnableSwagger(c =>
    {
        c.RootUrl(req => GetRootUrlFromAppConfig());

        c.Schemes(new[] { "http", "https" });

        c.SingleApiVersion("v1", "Swashbuckle.Dummy")
            .Description("A sample API for testing and prototyping Swashbuckle features")
            .TermsOfService("Some terms")
            .Contact(cc => cc
                .Name("Some contact")
                .Url("http://tempuri.org/contact")
                .Email("some.contact@tempuri.org"))
            .License(lc => lc
                .Name("Some License")
                .Url("http://tempuri.org/license"));
    });

3. .

+4
1

node swagger .

. :

public class DocumentFilter : IDocumentFilter
{
    /// <summary>
    /// This method is for applying the filter
    /// </summary>
    /// <param name="swaggerDoc">Swagger Document</param>
    /// <param name="schemaRegistry">Schema Registry</param>
    /// <param name="apiExplorer">API Explorer</param>
    public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
    {
        var methods = swaggerDoc.paths.Select(i => i.Value);
        List<string> tags = new List<string>();
        foreach (var method in methods)
        {
            if (method.delete != null)
            {
                tags.AddRange(method.delete.tags);
            }

            if (method.get != null)
            {
                tags.AddRange(method.get.tags);
            }

            if (method.put != null)
            {
                tags.AddRange(method.put.tags);
            }

            if (method.post != null)
            {
                tags.AddRange(method.post.tags);
            }

            if (method.patch != null)
            {
                tags.AddRange(method.patch.tags);
            }                
        }

        swaggerDoc.tags = new List<Tag>();
        foreach (var tag in tags)
        {
            swaggerDoc.tags.Add(new Tag() { name = tag, description = "This is a group of methods for " + tag });
        }
    }
}
+5

Source: https://habr.com/ru/post/1660260/


All Articles