Click here to Skip to main content
13,700,737 members
Click here to Skip to main content
Add your own
alternative version

Stats

10.3K views
4 bookmarked
Posted 18 Aug 2017
Licenced CPOL

Swagger Integration in ASP.NET Web API Project

, 18 Aug 2017
Rate this:
Please Sign up or sign in to vote.
How can I integrate Swagger in ASP.NET Web API project

Introduction

When you create a new ASP.NET Web API project, you need to present your APIs in a simple and comprehensive way? You can use Swagger.

“Swagger is a simple yet powerful representation of your RESTful API. With the largest ecosystem of API tooling on the planet, thousands of developers are supporting Swagger in almost every modern programming language and deployment environment. With a Swagger-enabled API, you get interactive documentation, client SDK generation and discoverability.”

Background

Able to create ASP.NET Web API 2.0. Use Postman.

Add Swagger to WEB API project

To add Swagger to an ASP.NET Web API, we will install an open-source project called Swashbuckle via NuGet.

When we install the package, a new config file was added: SwaggerConfig as mentioned in the picture below:

Swagger Configuration

In the configuration file added, we find the minimum configuration needed to enable Swagger and Swagger UI:

Now, when we start a new debugging session, we get the URI of our API and we navigate to Swagger: http://localhost:[PORT_NUM]/swagger

And if we want to display our APIs:

So What About Documentation?

If we commented our code, we can enable XML Comments to display it in Swagger.

In Solution Explorer, right-click on the Web API project and click Properties. Click the Build tab and navigate to Output. Make sure XML documentation file is checked. You can leave the default file path. In my case, it is bin\SwaggerSolution.Services.XML.

After we enable the comment in the configuration file of Swagger: SwaggerConfig:

Now, let's run the project and take a look. :)

I added this project as an extension to be able to use it easily in your project.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

didourebai
Technical Lead
Canada Canada
I am Rebaï Hamida, Microsoft MVP in Visual Studio and Development Technologies.
I'm a software architect and developer who like to build open source projects, writing articles, learning and teaching best practices. you can find out in my blog : http://hamidarebai.blogspot.com/

Innovative Software engineer : hands-on, competent software engineer, passionate and proficient C# developer, offering more than seven years of experience in the full software development lifecycle – from concept through delivery of next-generation applications and customized solutions, producing code to a consistently high standard and testing software across a variety of platforms.
Expert in advanced development methodologies, tools and processes contributing to the design and roll-out of cutting-edge software applications.
Known for excellent troubleshooting skills – able to analyze code and engineer well-researched, cost-effective and responsive solutions.


Success is only a consequence of a continuous work and remarkable intelligence.
I believe that I have to make a change in my country, I can’t live without leaving my footprint.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180910.1 | Last Updated 18 Aug 2017
Article Copyright 2017 by didourebai
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid