Skip to content
Permalink
Browse files

added swagger

  • Loading branch information
ignatandrei committed Nov 16, 2019
1 parent c7d8f32 commit 4fbff903c4510acbcb219d0263ae89736e9f2d8d
@@ -1,6 +1,7 @@
using InfoValutarShared;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace InfoValutarPluginStarter
{
@@ -10,6 +11,7 @@ public class GetFakeExchangeRates : BankGetExchange

public async IAsyncEnumerable<ExchangeRates> GetActualRates()
{
await Task.Delay(10);
yield return new ExchangeRates()
{
Bank = this.Bank,
@@ -9,25 +9,42 @@

namespace InfoValutarWebAPI.Controllers
{
/// <summary>
/// try with version 1.0
/// </summary>
[ApiController]
[ApiVersion( "1.0" )]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
public class TodayRates : ControllerBase
{
private readonly ILogger<TodayRates> _logger;
private readonly LoadExchangeProviders _prov;

/// <summary>
/// constructor
/// </summary>
/// <param name="logger"></param>
/// <param name="prov"></param>
public TodayRates(ILogger<TodayRates> logger, LoadExchangeProviders prov)
{
_logger = logger;
_prov = prov;
}

/// <summary>
/// all available banks
/// version : 1.0
/// </summary>
/// <returns></returns>
[HttpGet]
public IEnumerable<string> Banks()
{
return _prov.Banks();
}
/// <summary>
/// all exchange rates for banks
/// version : 1.0
/// </summary>
/// <returns></returns>
[HttpGet("{bank}")]
public IAsyncEnumerable<ExchangeRates> Rates([FromRoute] string bank)
{
@@ -1,7 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<DocumentationFile>InfoValutarWebAPI.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>

<ItemGroup>
@@ -20,6 +26,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.0.0" />
<PackageReference Include="NSwag.AspNetCore" Version="13.1.5" />
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">

Some generated files are not rendered by default. Learn more.

@@ -9,15 +9,22 @@

namespace InfoValutarWebAPI
{
/// <summary>
/// starting point
/// </summary>
public class Program
{
/// <summary>
/// starting point
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();

}

public static IHostBuilder CreateHostBuilder(string[] args) =>
private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using InfoValutarLoadingLibs;
using Microsoft.AspNetCore.Builder;
@@ -11,10 +12,11 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NSwag;

namespace InfoValutarWebAPI
{
public class Startup
class Startup
{
public Startup(IConfiguration configuration)
{
@@ -29,6 +31,27 @@ public void ConfigureServices(IServiceCollection services)
services.AddControllers();
services.AddSingleton< LoadExchangeProviders>(new LoadExchangeProviders("plugins"));
services.AddApiVersioning();
services.AddOpenApiDocument(c=> {


c.PostProcess = d =>
{
d.Info.Title = "Infovalutar API";
d.Info.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
d.Info.Description = "Source code / docs at https://github.com/ignatandrei/InfoValutar/";
d.Info.Contact = new OpenApiContact
{
Name = "Andrei Ignat",
Email = string.Empty,
Url = "http://msprogrammer.serviciipeweb.ro/category/exchange-rates/"
};
d.Info.License = new OpenApiLicense()
{
Name = "Use under MIT",
//Url = "https://example.com/license"
};
};
});
}


@@ -49,6 +72,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
endpoints.MapControllers();
});
app.UseOpenApi();
app.UseSwaggerUi3();
}
}
}

0 comments on commit 4fbff90

Please sign in to comment.
You can’t perform that action at this time.