Home > Software engineering >  What Exactly Does "SwaggerGen" Do?
What Exactly Does "SwaggerGen" Do?

Time:01-05

I Recently Start for Work with Asp.net Web api and in the present of Methods in Program.cs :)

what Does AddSwaggerGen() Do ?

.

var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen();

.

in .net 7 the Startup.cs and Program.cs are Composition ...

CodePudding user response:

That line of code, adds the Swagger generator to the services collection. SwaggerUI shows the REST APIs in your project in a user-friendly UI, so that you can test them in the browser. For this UI to render, you need the JSON file that expresses the details of the APIs[name, input arguments, types, etc], that JSON is being generated by this Swagger Generator.

Note: Swagger was the name of the project that described the definition of REST APIs, since 2015 it has been known as OpenAPI.

CodePudding user response:

The configuration action passed to the AddSwaggerGen method adds information such as the author, license, and description. You can find more information here.

CodePudding user response:

AddSwaggerGen() method adds a service that generates Swagger documents for your APIs. When this method is called, it adds the service to the dependency injection container so that it can be used later in the application. When the service is used, it will generate a Swagger document that describes the available APIs and their operations. This can be useful for developers who are consuming the APIs, as it provides detailed information about how to use the APIs.

  • Related