11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4- using System . Text ;
54using System . Threading . Tasks ;
65using CSharpFunctionalExtensions ;
76using Microsoft . AspNetCore . Mvc ;
8- using Microsoft . Extensions . Options ;
97using Microsoft . OpenApi ;
108using Microsoft . OpenApi . Extensions ;
119using Microsoft . OpenApi . Models ;
@@ -23,15 +21,14 @@ namespace Stratis.Bitcoin.Features.SmartContracts.ReflectionExecutor.Controllers
2321 /// <summary>
2422 /// Controller for dynamically generating swagger documents for smart contract assemblies.
2523 /// </summary>
26- [ Route ( "swagger/contracts" ) ]
2724 public class ContractSwaggerController : Controller
2825 {
2926 private readonly SwaggerGeneratorOptions options ;
3027 private readonly ILoader loader ;
3128 private readonly IWalletManager walletmanager ;
3229 private readonly IStateRepositoryRoot stateRepository ;
3330 private readonly Network network ;
34- private SwaggerUIOptions uiOptions ;
31+ private readonly SwaggerUIOptions uiOptions ;
3532
3633 public ContractSwaggerController (
3734 SwaggerGeneratorOptions options ,
@@ -55,7 +52,7 @@ public ContractSwaggerController(
5552 /// <param name="address">The contract's address.</param>
5653 /// <returns>A <see cref="SwaggerDocument"/> model.</returns>
5754 /// <exception cref="Exception"></exception>
58- [ Route ( "{address}" ) ]
55+ [ Route ( "swagger/contracts/ {address}" ) ]
5956 [ HttpGet ]
6057 public async Task < IActionResult > ContractSwaggerDoc ( string address )
6158 {
@@ -94,25 +91,35 @@ public async Task<IActionResult> ContractSwaggerDoc(string address)
9491 /// <param name="address">The contract's address.</param>
9592 /// <returns>A success response.</returns>
9693 [ HttpPost ]
97- public async Task < IActionResult > AddContractToSwagger ( [ FromBody ] string address )
94+ [ Route ( "api/swagger/contracts" ) ]
95+ public async Task < IActionResult > AddContractToSwagger ( [ FromBody ] AddContractRequest address )
9896 {
9997 // Check that the contract exists
100- var code = this . stateRepository . GetCode ( address . ToUint160 ( this . network ) ) ;
98+ var code = this . stateRepository . GetCode ( address . Address . ToUint160 ( this . network ) ) ;
10199
102100 if ( code == null )
103101 throw new Exception ( "Contract does not exist" ) ;
104102
105- var newUrls = new List < UrlDescriptor > ( this . uiOptions . ConfigObject . Urls ) ;
106-
107- newUrls . Add ( new UrlDescriptor
103+ var newUrls = new List < UrlDescriptor > ( this . uiOptions . ConfigObject . Urls )
108104 {
109- Name = $ "Contract { address } ",
110- Url = $ "/swagger/contracts/{ address } "
111- } ) ;
105+ new UrlDescriptor
106+ {
107+ Name = $ "Contract { address . Address } ",
108+ Url = $ "contracts/{ address . Address } "
109+ }
110+ } ;
112111
113112 this . uiOptions . ConfigObject . Urls = newUrls ;
114113
115114 return Ok ( ) ;
116115 }
116+
117+ public class AddContractRequest
118+ {
119+ /// <summary>
120+ /// The contract address to add.
121+ /// </summary>
122+ public string Address { get ; set ; }
123+ }
117124 }
118- }
125+ }
0 commit comments