Swagger/OpenAPI –part 16

In order to see the WebAPI, Swagger is a default technology. Reading https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?view=aspnetcore-3.0 , seems to have 2 options: Swashbuckle and NSwag. Looking at github repositories, both have > 2k stars, active development, tutorials. The only thing that I see more at NSwag are generators for Angular.

Integrated NSwag as for the tutorial from https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-nswag?view=aspnetcore-3.0&tabs=visual-studio . There is a small problem – when I try the swagger , I should put explicit the version. However, a not experienced user can not see this value.

Trying to put documentation : when I go to Project=>Properties=>Build and click the XML documentation, shows the full path to the XML. I do not need this!  So I edit the .csproj directly and change from full path to file

Also, because I want to be sure to have documentation, I change “warnings to errors”.

So now I must document Program and main(removed public from startup.cs and createwebhost – to not document)

Total: 6 changes , https://github.com/ignatandrei/InfoValutar/commit/4fbff903c4510acbcb219d0263ae89736e9f2d8d

So now I can browse to swagger

However, I should indicate to people that swagger is enabled to invite them browse to this – and this is easy to do in Kestrel, right ? Just take the address of the url …

So, trying in Program.cs to find the adresses:

var build = CreateHostBuilder(args).Build();
var s = build.Services.GetService(typeof(KestrelServerOptions));
var s1 = build.Services.GetService(typeof(IServer));
var s2 = build.Services.GetService(typeof(IServerAddressesFeature));
build.Run();

 

Not a chance – not yet configured. So , next chance is in Startup.cs

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//other code
var sa = app.ServerFeatures.Get<IServerAddressesFeature>();
var urls =string.Join(",", sa.Addresses.Select(it => it + "swagger"));
Console.WriteLine("please use " + urls);

( for this, you must not use IIS Express, but rather the project)

 

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe