Skip to content

Commit

Permalink
Fix some validation attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed May 14, 2021
1 parent 3190acc commit c31eb2a
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 76 deletions.
18 changes: 9 additions & 9 deletions Tzkt.Api/Controllers/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public Task<int> GetCount(
/// <param name="metadata">Include or not account metadata</param>
/// <returns></returns>
[HttpGet("{address}")]
public Task<Account> GetByAddress([Address] string address, bool metadata = false)
public Task<Account> GetByAddress([Required][Address] string address, bool metadata = false)
{
return Accounts.Get(address, metadata);
}
Expand All @@ -165,7 +165,7 @@ public Task<Account> GetByAddress([Address] string address, bool metadata = fals
/// <returns></returns>
[HttpGet("{address}/contracts")]
public async Task<ActionResult<IEnumerable<RelatedContract>>> GetContracts(
[Address] string address,
[Required][Address] string address,
SortParameter sort,
OffsetParameter offset,
[Range(0, 10000)] int limit = 100)
Expand Down Expand Up @@ -194,7 +194,7 @@ public async Task<ActionResult<IEnumerable<RelatedContract>>> GetContracts(
/// <returns></returns>
[HttpGet("{address}/delegators")]
public async Task<ActionResult<IEnumerable<Delegator>>> GetDelegators(
[Address] string address,
[Required][Address] string address,
AccountTypeParameter type,
Int64Parameter balance,
Int32Parameter delegationLevel,
Expand Down Expand Up @@ -251,7 +251,7 @@ public async Task<ActionResult<IEnumerable<Delegator>>> GetDelegators(
/// <returns></returns>
[HttpGet("{address}/operations")]
public async Task<ActionResult<IEnumerable<Operation>>> GetOperations(
[Address] string address,
[Required][Address] string address,
string type,
AccountParameter initiator,
AccountParameter sender,
Expand Down Expand Up @@ -410,7 +410,7 @@ public async Task<ActionResult<IEnumerable<Operation>>> GetOperations(
/// <param name="address">Account address (starting with tz or KT)</param>
/// <returns></returns>
[HttpGet("{address}/metadata")]
public Task<AccountMetadata> GetMetadata([Address] string address)
public Task<AccountMetadata> GetMetadata([Required][Address] string address)
{
return Accounts.GetMetadata(address);
}
Expand All @@ -431,7 +431,7 @@ public Task<AccountMetadata> GetMetadata([Address] string address)
/// <returns></returns>
[HttpGet("{address}/report")]
public async Task<ActionResult> GetBalanceReport(
[Address] string address,
[Required][Address] string address,
DateTimeOffset? from,
DateTimeOffset? to,
string currency,
Expand Down Expand Up @@ -525,7 +525,7 @@ public async Task<ActionResult> GetBalanceReport(
/// <returns></returns>
[HttpGet("{address}/balance_history")]
public async Task<ActionResult<IEnumerable<HistoricalBalance>>> GetBalanceHistory(
[Address] string address,
[Required][Address] string address,
[Min(1)] int? step,
SelectParameter select,
SortParameter sort,
Expand Down Expand Up @@ -573,7 +573,7 @@ public async Task<ActionResult<IEnumerable<HistoricalBalance>>> GetBalanceHistor
/// <param name="level">Block height at which you want to know account balance</param>
/// <returns></returns>
[HttpGet("{address}/balance_history/{level:int}")]
public Task<long> GetBalanceAtLevel([Address] string address, int level)
public Task<long> GetBalanceAtLevel([Required][Address] string address, [Min(0)] int level)
{
return History.Get(address, level);
}
Expand All @@ -588,7 +588,7 @@ public Task<long> GetBalanceAtLevel([Address] string address, int level)
/// <param name="datetime">Datetime at which you want to know account balance (e.g. `2020-01-01`, or `2019-12-30T23:42:59Z`)</param>
/// <returns></returns>
[HttpGet("{address}/balance_history/{datetime:DateTime}")]
public Task<long> GetBalanceAtDate([Address] string address, DateTimeOffset datetime)
public Task<long> GetBalanceAtDate([Required][Address] string address, DateTimeOffset datetime)
{
return History.Get(address, datetime.DateTime);
}
Expand Down
6 changes: 3 additions & 3 deletions Tzkt.Api/Controllers/BigMapsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public async Task<ActionResult<IEnumerable<BigMapKey>>> GetKeys(
[HttpGet("{id:int}/keys/{key}")]
public async Task<ActionResult<BigMapKey>> GetKey(
[Min(0)] int id,
string key,
[Required] string key,
MichelineFormat micheline = MichelineFormat.Json)
{
try
Expand Down Expand Up @@ -284,7 +284,7 @@ public async Task<ActionResult<BigMapKey>> GetKey(
[HttpGet("{id:int}/keys/{key}/updates")]
public async Task<ActionResult<IEnumerable<BigMapKeyUpdate>>> GetKeyUpdates(
[Min(0)] int id,
string key,
[Required] string key,
SortParameter sort,
OffsetParameter offset,
[Range(0, 10000)] int limit = 100,
Expand Down Expand Up @@ -391,7 +391,7 @@ public async Task<ActionResult<IEnumerable<BigMapKeyHistorical>>> GetHistoricalK
public async Task<ActionResult<BigMapKeyHistorical>> GetKey(
[Min(0)] int id,
[Min(0)] int level,
string key,
[Required] string key,
MichelineFormat micheline = MichelineFormat.Json)
{
try
Expand Down
2 changes: 1 addition & 1 deletion Tzkt.Api/Controllers/BlocksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public async Task<ActionResult<IEnumerable<Block>>> Get(
/// <returns></returns>
[HttpGet("{hash}")]
public Task<Block> GetByHash(
[BlockHash] string hash,
[Required][BlockHash] string hash,
bool operations = false,
MichelineFormat micheline = MichelineFormat.Json,
Symbols quote = Symbols.None)
Expand Down
2 changes: 1 addition & 1 deletion Tzkt.Api/Controllers/CommitmentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public CommitmentsController(CommitmentRepository commitments, StateCache state)
/// <param name="address">Blinded address (starting with btz)</param>
/// <returns></returns>
[HttpGet("{address}")]
public Task<Commitment> Get([BlindedAddress] string address)
public Task<Commitment> Get([Required][BlindedAddress] string address)
{
return Commitments.Get(address);
}
Expand Down
62 changes: 31 additions & 31 deletions Tzkt.Api/Controllers/ContractsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public Task<int> GetCount(ContractKindParameter kind)
/// <param name="address">Contract address (starting with KT)</param>
/// <returns></returns>
[HttpGet("{address}")]
public Task<Contract> GetByAddress([Address] string address)
public Task<Contract> GetByAddress([Required][Address] string address)
{
return Accounts.GetContract(address);
}
Expand All @@ -170,7 +170,7 @@ public Task<Contract> GetByAddress([Address] string address)
/// <returns></returns>
[HttpGet("{address}/same")]
public async Task<ActionResult<IEnumerable<Contract>>> GetSame(
[Address] string address,
[Required][Address] string address,
SelectParameter select,
SortParameter sort,
OffsetParameter offset,
Expand Down Expand Up @@ -229,7 +229,7 @@ public async Task<ActionResult<IEnumerable<Contract>>> GetSame(
/// <returns></returns>
[HttpGet("{address}/similar")]
public async Task<ActionResult<IEnumerable<Contract>>> GetSimilar(
[Address] string address,
[Required][Address] string address,
SelectParameter select,
SortParameter sort,
OffsetParameter offset,
Expand Down Expand Up @@ -282,7 +282,7 @@ public async Task<ActionResult<IEnumerable<Contract>>> GetSimilar(
/// <param name="format">Code format (`0` - micheline, `1` - michelson, `2` - bytes (base64))</param>
/// <returns></returns>
[HttpGet("{address}/code")]
public async Task<object> GetCode([Address] string address, [Range(0, 2)] int format = 0)
public async Task<object> GetCode([Required][Address] string address, [Range(0, 2)] int format = 0)
{
if (format == 0)
return await Accounts.GetMichelineCode(address);
Expand All @@ -300,7 +300,7 @@ public async Task<object> GetCode([Address] string address, [Range(0, 2)] int fo
/// <param name="address">Contract address</param>
/// <returns></returns>
[HttpGet("{address}/interface")]
public Task<ContractInterface> GetInterface([Address] string address)
public Task<ContractInterface> GetInterface([Required][Address] string address)
{
return Accounts.GetContractInterface(address);
}
Expand All @@ -321,7 +321,7 @@ public Task<ContractInterface> GetInterface([Address] string address)
/// <param name="michelson">Include parameters schema in michelson format</param>
/// <returns></returns>
[HttpGet("{address}/entrypoints")]
public Task<IEnumerable<Entrypoint>> GetEntrypoints([Address] string address, bool all = false, bool json = true, bool micheline = false, bool michelson = false)
public Task<IEnumerable<Entrypoint>> GetEntrypoints([Required][Address] string address, bool all = false, bool json = true, bool micheline = false, bool michelson = false)
{
return Accounts.GetEntrypoints(address, all, json, micheline, michelson);
}
Expand All @@ -339,7 +339,7 @@ public Task<IEnumerable<Entrypoint>> GetEntrypoints([Address] string address, bo
/// <param name="michelson">Include parameters schema in michelson format</param>
/// <returns></returns>
[HttpGet("{address}/entrypoints/{name}")]
public Task<Entrypoint> GetEntrypointByName([Address] string address, string name, bool json = true, bool micheline = false, bool michelson = false)
public Task<Entrypoint> GetEntrypointByName([Required][Address] string address, [Required] string name, bool json = true, bool micheline = false, bool michelson = false)
{
return Accounts.GetEntrypoint(address, name, json, micheline, michelson);
}
Expand All @@ -355,7 +355,7 @@ public Task<Entrypoint> GetEntrypointByName([Address] string address, string nam
/// <param name="value">Json parameters</param>
/// <returns></returns>
[HttpGet("{address}/entrypoints/{name}/build")]
public async Task<ActionResult> BuildEntrypointParameters([Address] string address, string name, string value)
public async Task<ActionResult> BuildEntrypointParameters([Required][Address] string address, [Required] string name, string value)
{
try
{
Expand All @@ -379,7 +379,7 @@ public async Task<ActionResult> BuildEntrypointParameters([Address] string addre
/// <param name="value">Json parameters</param>
/// <returns></returns>
[HttpPost("{address}/entrypoints/{name}/build")]
public async Task<ActionResult> BuildEntrypointParameters([Address] string address, string name, [FromBody] object value)
public async Task<ActionResult> BuildEntrypointParameters([Required][Address] string address, [Required] string name, [FromBody] object value)
{
try
{
Expand All @@ -402,7 +402,7 @@ public async Task<ActionResult> BuildEntrypointParameters([Address] string addre
/// <param name="path">Path in the JSON value (point-separated list of field names, e.g. `path=settings.refund_time` to return</param>
/// <returns></returns>
[HttpGet("{address}/storage")]
public async Task<ActionResult> GetStorage([Address] string address, [Min(0)] int level = 0, string path = null)
public async Task<ActionResult> GetStorage([Required][Address] string address, [Min(0)] int level = 0, string path = null)
{
#region safe path
JsonPath[] jsonPath = null;
Expand Down Expand Up @@ -433,7 +433,7 @@ public async Task<ActionResult> GetStorage([Address] string address, [Min(0)] in
/// <param name="level">Level at which storage schema should be taken. If `0` or not specified, the current schema will be returned.</param>
/// <returns></returns>
[HttpGet("{address}/storage/schema")]
public async Task<ActionResult> GetStorageSchema([Address] string address, [Min(0)] int level = 0)
public async Task<ActionResult> GetStorageSchema([Required][Address] string address, [Min(0)] int level = 0)
{
if (level == 0)
return this.Json(await Accounts.GetStorageSchema(address));
Expand All @@ -451,7 +451,7 @@ public async Task<ActionResult> GetStorageSchema([Address] string address, [Min(
/// <param name="limit">Maximum number of items to return</param>
/// <returns></returns>
[HttpGet("{address}/storage/history")]
public Task<IEnumerable<StorageRecord>> GetStorageHistory([Address] string address, [Min(0)] int lastId = 0, [Range(0, 1000)] int limit = 10)
public Task<IEnumerable<StorageRecord>> GetStorageHistory([Required][Address] string address, [Min(0)] int lastId = 0, [Range(0, 1000)] int limit = 10)
{
return Accounts.GetStorageHistory(address, lastId, limit);
}
Expand All @@ -466,7 +466,7 @@ public Task<IEnumerable<StorageRecord>> GetStorageHistory([Address] string addre
/// <param name="level">Level at which storage value should be taken. If `0` or not specified, the current value will be returned.</param>
/// <returns></returns>
[HttpGet("{address}/storage/raw")]
public Task<IMicheline> GetRawStorage([Address] string address, [Min(0)] int level = 0)
public Task<IMicheline> GetRawStorage([Required][Address] string address, [Min(0)] int level = 0)
{
if (level == 0)
return Accounts.GetRawStorageValue(address);
Expand All @@ -483,7 +483,7 @@ public Task<IMicheline> GetRawStorage([Address] string address, [Min(0)] int lev
/// <param name="level">Level at which storage schema should be taken. If `0` or not specified, the current schema will be returned.</param>
/// <returns></returns>
[HttpGet("{address}/storage/raw/schema")]
public Task<IMicheline> GetRawStorageSchema([Address] string address, [Min(0)] int level = 0)
public Task<IMicheline> GetRawStorageSchema([Required][Address] string address, [Min(0)] int level = 0)
{
if (level == 0)
return Accounts.GetRawStorageSchema(address);
Expand All @@ -501,7 +501,7 @@ public Task<IMicheline> GetRawStorageSchema([Address] string address, [Min(0)] i
/// <param name="limit">Maximum number of items to return</param>
/// <returns></returns>
[HttpGet("{address}/storage/raw/history")]
public Task<IEnumerable<StorageRecord>> GetRawStorageHistory([Address] string address, [Min(0)] int lastId = 0, [Range(0, 1000)] int limit = 10)
public Task<IEnumerable<StorageRecord>> GetRawStorageHistory([Required][Address] string address, [Min(0)] int lastId = 0, [Range(0, 1000)] int limit = 10)
{
return Accounts.GetRawStorageHistory(address, lastId, limit);
}
Expand All @@ -523,7 +523,7 @@ public Task<IEnumerable<StorageRecord>> GetRawStorageHistory([Address] string ad
/// <returns></returns>
[HttpGet("{address}/bigmaps")]
public async Task<ActionResult<IEnumerable<BigMap>>> GetBigMaps(
[Address] string address,
[Required][Address] string address,
BigMapTagsParameter tags,
SelectParameter select,
SortParameter sort,
Expand Down Expand Up @@ -581,8 +581,8 @@ public async Task<ActionResult<IEnumerable<BigMap>>> GetBigMaps(
/// <returns></returns>
[HttpGet("{address}/bigmaps/{name}")]
public async Task<ActionResult<BigMap>> GetBigMapByName(
[Address] string address,
string name,
[Required][Address] string address,
[Required] string name,
MichelineFormat micheline = MichelineFormat.Json)
{
var acc = await Accounts.GetRawAsync(address);
Expand Down Expand Up @@ -616,8 +616,8 @@ public async Task<ActionResult<BigMap>> GetBigMapByName(
/// <returns></returns>
[HttpGet("{address}/bigmaps/{name}/keys")]
public async Task<ActionResult<IEnumerable<BigMapKey>>> GetBigMapByNameKeys(
[Address] string address,
string name,
[Required][Address] string address,
[Required] string name,
bool? active,
JsonParameter key,
JsonParameter value,
Expand Down Expand Up @@ -682,9 +682,9 @@ public async Task<ActionResult<IEnumerable<BigMapKey>>> GetBigMapByNameKeys(
/// <returns></returns>
[HttpGet("{address}/bigmaps/{name}/keys/{key}")]
public async Task<ActionResult<BigMapKey>> GetKey(
[Address] string address,
string name,
string key,
[Required][Address] string address,
[Required] string name,
[Required] string key,
MichelineFormat micheline = MichelineFormat.Json)
{
var acc = await Accounts.GetRawAsync(address);
Expand Down Expand Up @@ -732,9 +732,9 @@ public async Task<ActionResult<BigMapKey>> GetKey(
/// <returns></returns>
[HttpGet("{address}/bigmaps/{name}/keys/{key}/updates")]
public async Task<ActionResult<IEnumerable<BigMapKeyUpdate>>> GetKeyUpdates(
[Address] string address,
string name,
string key,
[Required][Address] string address,
[Required] string name,
[Required] string key,
SortParameter sort,
OffsetParameter offset,
[Range(0, 10000)] int limit = 100,
Expand Down Expand Up @@ -795,8 +795,8 @@ public async Task<ActionResult<IEnumerable<BigMapKeyUpdate>>> GetKeyUpdates(
/// <returns></returns>
[HttpGet("{address}/bigmaps/{name}/historical_keys/{level:int}")]
public async Task<ActionResult<IEnumerable<BigMapKeyHistorical>>> GetHistoricalKeys(
[Address] string address,
string name,
[Required][Address] string address,
[Required] string name,
[Min(0)] int level,
bool? active,
JsonParameter key,
Expand Down Expand Up @@ -862,10 +862,10 @@ public async Task<ActionResult<IEnumerable<BigMapKeyHistorical>>> GetHistoricalK
/// <returns></returns>
[HttpGet("{address}/bigmaps/{name}/historical_keys/{level:int}/{key}")]
public async Task<ActionResult<BigMapKeyHistorical>> GetKey(
[Address] string address,
string name,
[Required][Address] string address,
[Required] string name,
[Min(0)] int level,
string key,
[Required] string key,
MichelineFormat micheline = MichelineFormat.Json)
{
var acc = await Accounts.GetRawAsync(address);
Expand Down
2 changes: 1 addition & 1 deletion Tzkt.Api/Controllers/CyclesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task<ActionResult<IEnumerable<Cycle>>> Get(
/// <param name="quote">Comma-separated list of ticker symbols to inject historical prices into response</param>
/// <returns></returns>
[HttpGet("{index:int}")]
public Task<Cycle> GetByIndex(int index, Symbols quote = Symbols.None)
public Task<Cycle> GetByIndex([Min(0)] int index, Symbols quote = Symbols.None)
{
return Cycles.Get(index, quote);
}
Expand Down
2 changes: 1 addition & 1 deletion Tzkt.Api/Controllers/DelegatesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Task<int> GetCount(BoolParameter active)
/// <param name="address">Delegate address (starting with tz)</param>
/// <returns></returns>
[HttpGet("{address}")]
public Task<Models.Delegate> GetByAddress([Address] string address)
public Task<Models.Delegate> GetByAddress([Required][Address] string address)
{
return Accounts.GetDelegate(address);
}
Expand Down
Loading

0 comments on commit c31eb2a

Please sign in to comment.