I want to integrate swagger codegen into my web API project to explore the swagger codegen feature, host the codegen and pass the JSON/raml form specs to generate client in .net core. Can somebody help with how to do it?
Question
Share
Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
to integrate swagger codegen into your web api project you have to install “Swashbuckle.AspNetCore.Swagger” nuget package by following the steps below :
right click your project and click manage nuget packages and install “Swashbuckle.AspNetCore.Swagger” nuget package
OR
right click in dependencies and click manage nuget packages and install “Swashbuckle.AspNetCore.Swagger” nuget package
Then add the following code into your project startup class
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc(“v1”, new OpenApiInfo { Title = “API”, Version = “v1” });
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint(“/swagger/v1/swagger.json”, “API v1”));
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}