Skip to content

lucianopereira86/NetCore3-Swagger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

titulo

NetCore3-Swagger

Creating a .Net Core 3 web API with Swagger. This example in complete inside the api folder.

Technologies

Topics

.Net Core 3

Download the Visual Studio 2019 here and install it.

Create a new project:

netcore01

Choose ASP.Net Core Web Application:

netcore02

Name the project and configure the local path:

netcore03

Select an empty .Net Core project and uncheck the HTTPS and Docker support options:

netcore04

After the solution be compiled, create a folder named "Controllers" and add into it a class named "TestController" with an async method:

netcore07

Now, let's config the "Startup" class:

netcore08

Run the project in debug mode and access the URL below:

http:https://localhost:<API-PORT>/api/Test

If the "OK!" message be displayed in the browser, our web API is running!

Swagger

Inside the Visual Studio 2019, open the Package Manager Console and run the following commands to install the Swashbuckle version compatible with .Net Core 3:

Install-Package Swashbuckle.AspNetCore -Version 5.0.0-rc3
Install-Package Swashbuckle.AspNetCore.Filters -Version 5.0.0-rc3
Install-Package Swashbuckle.AspNetCore.Annotations -Version 5.0.0-rc3

Open the "Startup" class again and modify the "ConfigureServices" method:

swagger01

And the "Configure" method as well:

swagger02

Open the project's properties window, go to "Build", check the "XML documentation file" option and type your project name with the XML extension:

swagger03_04

Go to "Debug" and type "swagger" inside the input field above the environment variables list:

swagger04

WARNING: To avoid the MSB3073 error during the compilation, edit the project's .csproj file by adding the tag OpenApiGenerateDocuments inside PropertyGroup:
  <PropertyGroup>
        <TargetFramework>netcoreapp3.0</TargetFramework>
	<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
  </PropertyGroup>

Inside the "TestController", put a simple annotation above the "Get" method:

swagger03

Now, let's run the project again. The Swagger page will open in this URL:

http:https://localhost:<API-PORT>/swagger/index.html

This will be the result:

swagger08

Try the "Get" method and the "OK!" message will return from the API.

swagger09

About

Creating a .Net Core 3 web API with Swagger

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages