From e4bbe97404478649d87b1a9c9550c8d9d9f22020 Mon Sep 17 00:00:00 2001 From: "Lazar Prijovic @madrazzl3" Date: Fri, 24 Jun 2022 01:23:16 +0300 Subject: [PATCH 1/2] Add return type specification for some methods in Unity API --- .../Controllers/Unity3dController.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Stratis.Features.Unity3dApi/Controllers/Unity3dController.cs b/src/Stratis.Features.Unity3dApi/Controllers/Unity3dController.cs index a9cc196c89..97f028ccd1 100644 --- a/src/Stratis.Features.Unity3dApi/Controllers/Unity3dController.cs +++ b/src/Stratis.Features.Unity3dApi/Controllers/Unity3dController.cs @@ -187,7 +187,7 @@ public GetUTXOsResponseModel GetUTXOsForAddress([FromQuery] string address) /// Unexpected exception occurred [Route("getaddressbalance")] [HttpGet] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GetBalanceResponseModel))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] public IActionResult GetAddressBalance(string address) { @@ -304,10 +304,10 @@ public RawTxModel GetRawTransaction([FromQuery] string trxid) /// Request is null [Route("send-transaction")] [HttpPost] - [ProducesResponseType((int)HttpStatusCode.OK)] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.InternalServerError)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(WalletSendTransactionModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(ErrorResult))] + [ProducesResponseType((int)HttpStatusCode.Forbidden, Type = typeof(ErrorResult))] + [ProducesResponseType((int)HttpStatusCode.InternalServerError, Type = typeof(ErrorResult))] public async Task SendTransactionAsync([FromBody] SendTransactionRequest request, CancellationToken cancellationToken = default(CancellationToken)) { @@ -521,9 +521,9 @@ public ReceiptResponse GetReceiptAPI([FromQuery] string txHash) /// Unable to deserialize method parameters [Route("local-call")] [HttpPost] - [ProducesResponseType((int)HttpStatusCode.OK)] - [ProducesResponseType((int)HttpStatusCode.BadRequest)] - [ProducesResponseType((int)HttpStatusCode.InternalServerError)] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(ILocalExecutionResult))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(ErrorResult))] + [ProducesResponseType((int)HttpStatusCode.InternalServerError, Type = typeof(ErrorResult))] public IActionResult LocalCallSmartContractTransaction([FromBody] LocalCallContractRequest request) { if (!this.ModelState.IsValid) From e26ebd71efa8a1524ace2269f459447ac6c85812 Mon Sep 17 00:00:00 2001 From: "Lazar Prijovic @madrazzl3" Date: Mon, 27 Jun 2022 12:35:21 +0300 Subject: [PATCH 2/2] Update swagger generation for types with custom serialization --- src/Stratis.Features.Unity3dApi/Startup.cs | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Stratis.Features.Unity3dApi/Startup.cs b/src/Stratis.Features.Unity3dApi/Startup.cs index 446a76afe0..b9aed389e3 100644 --- a/src/Stratis.Features.Unity3dApi/Startup.cs +++ b/src/Stratis.Features.Unity3dApi/Startup.cs @@ -8,6 +8,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Models; +using NBitcoin; using Newtonsoft.Json.Serialization; using Stratis.Bitcoin; using Stratis.Bitcoin.Features.Api; @@ -128,7 +131,26 @@ public void ConfigureServices(IServiceCollection services) services.AddTransient, ConfigureSwaggerOptions>(); // Register the Swagger generator. This will use the options we injected just above. - services.AddSwaggerGen(); + services.AddSwaggerGen(options => { + options.MapType(typeof(Money), () => new OpenApiSchema + { + Type = "integer", + Example = new OpenApiInteger(9999) + }); + + options.MapType(typeof(uint160), () => new OpenApiSchema + { + Type = "string", + Example = new OpenApiString("ffffffffffffffffffffffffffffffffffffffff") + }); + + options.MapType(typeof(uint256), () => new OpenApiSchema + { + Type = "string", + Example = new OpenApiString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + }); + }); + services.AddSwaggerGenNewtonsoftSupport(); // Use Newtonsoft JSON serializer with swagger. Needs to be placed after AddSwaggerGen() // Hack to be able to access and modify the options object