Commit 08621f0c authored by Jeremy Bokobza's avatar Jeremy Bokobza Committed by GitHub

Added Swagger documentation (#6)

* Rename Safe to Wallet

* Added versioning to the Api

* Added Swagger documentation
parent 7dcaa7b5
...@@ -2,20 +2,15 @@ ...@@ -2,20 +2,15 @@
namespace Breeze.Api.Controllers namespace Breeze.Api.Controllers
{ {
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
public class NodeController : Controller public class NodeController : Controller
{ {
[Route("connect")] [HttpGet]
public IActionResult Connect(string[] args)
{
return NotFound();
}
[Route("status")] [Route("status")]
public IActionResult Status() public IActionResult Status()
{ {
return this.NotFound(); return this.NotFound();
} }
} }
} }
\ No newline at end of file
using Microsoft.AspNetCore.Builder; using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Swashbuckle.AspNetCore.Swagger;
namespace Breeze.Api namespace Breeze.Api
{ {
...@@ -29,7 +32,30 @@ namespace Breeze.Api ...@@ -29,7 +32,30 @@ namespace Breeze.Api
.AddJsonOptions(options => NBitcoin.JsonConverters.Serializer.RegisterFrontConverters(options.SerializerSettings)) .AddJsonOptions(options => NBitcoin.JsonConverters.Serializer.RegisterFrontConverters(options.SerializerSettings))
.AddControllers(services); .AddControllers(services);
services.AddApiVersioning(); services.AddApiVersioning(options =>
{
options.DefaultApiVersion = new ApiVersion(1, 0);
});
// Register the Swagger generator, defining one or more Swagger documents
services.AddSwaggerGen(setup =>
{
setup.SwaggerDoc("v1", new Info { Title = "Breeze.Api", Version = "v1" });
// FIXME: prepopulates the version in the URL of the Swagger UI found at http://localhost:5000/swagger
// temporary needed until Swashbuckle supports it out-of-the-box
setup.DocInclusionPredicate((version, apiDescription) =>
{
apiDescription.RelativePath = apiDescription.RelativePath.Replace("v{version}", version);
var versionParameter = apiDescription.ParameterDescriptions.SingleOrDefault(p => p.Name == "version");
if (versionParameter != null)
{
apiDescription.ParameterDescriptions.Remove(versionParameter);
}
return true;
});
});
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
...@@ -39,6 +65,15 @@ namespace Breeze.Api ...@@ -39,6 +65,15 @@ namespace Breeze.Api
loggerFactory.AddDebug(); loggerFactory.AddDebug();
app.UseMvc(); app.UseMvc();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Breeze.Api V1");
});
} }
} }
} }
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"Microsoft.NETCore.App": "1.1.0", "Microsoft.NETCore.App": "1.1.0",
"NBitcoin": "3.0.2.10", "NBitcoin": "3.0.2.10",
"Stratis.Bitcoin": "1.0.1.2-alpha", "Stratis.Bitcoin": "1.0.1.2-alpha",
"Swashbuckle.AspNetCore": "1.0.0-rc3",
"System.Reactive": "3.1.1", "System.Reactive": "3.1.1",
"System.Runtime.Loader": "4.3.0" "System.Runtime.Loader": "4.3.0"
}, },
......
...@@ -6,12 +6,9 @@ using System.Security; ...@@ -6,12 +6,9 @@ using System.Security;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Breeze.Wallet.Models; using Breeze.Wallet.Models;
using Breeze.Wallet.Wrappers; using Breeze.Wallet.Wrappers;
using Stratis.Bitcoin;
namespace Breeze.Wallet.Controllers namespace Breeze.Wallet.Controllers
{ {
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")] [Route("api/v{version:apiVersion}/[controller]")]
public class WalletController : Controller public class WalletController : Controller
{ {
...@@ -51,7 +48,8 @@ namespace Breeze.Wallet.Controllers ...@@ -51,7 +48,8 @@ namespace Breeze.Wallet.Controllers
} }
} }
public IActionResult Load(WalletLoadModel walletLoad) [HttpGet]
public IActionResult Load([FromQuery]WalletLoadModel walletLoad)
{ {
// checks the request is valid // checks the request is valid
if (!this.ModelState.IsValid) if (!this.ModelState.IsValid)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment