Skip to content

How to set example in swagger by xml documentation? #22

Description

@marcialwushu
services.AddSwaggerGen(c =>
            {
                // Set Title and version from config
                c.SwaggerDoc("v1", new Info { Title = "My Title", Version = "1.0", Description = "My Description" });
                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                // pick comments from classes, include controller comments: another tip from StackOverflow
                c.IncludeXmlComments(xmlPath, includeControllerXmlComments: true);
                // enable the annotations on Controller classes [SwaggerTag]
                c.EnableAnnotations();
                // to allow for a header parameter
                c.OperationFilter<AddRequiredHeaderParameter>();
            });

Update for Swashbuckle 4.x, which does support the use of the tag. (see https://github.com/domaindrivendev/Swashbuckle.AspNetCore )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions