-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIinfo.cs
More file actions
44 lines (42 loc) · 1.52 KB
/
APIinfo.cs
File metadata and controls
44 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Text.RegularExpressions;
namespace Webtech3;
/// <summary>
/// Attribute for fast & comfortable adding routing info
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class APIInfo(
string url,
bool auth = false,
HTTP.Methods[]? methods = null,
byte[]? roles = null,
string? description = null
) : Attribute {
/// <summary>
/// Regex Url pattern for API endpoint.
/// </summary>
/// <value>Regex pattern</value>
public string Url { get; init; } = url;
/// <summary>
/// List of HTTP methods, than can be handled by endpoint
/// </summary>
/// <value>HTTP methods list</value>
public HTTP.Methods[] Methods { get; init; } = methods ?? [HTTP.Methods.GET];
/// <summary>
/// Flag for server, means - need or not do auth.
/// </summary>
/// <value>True if need, false - if not. Auto true if roles is specified.</value>
public bool Authentication { get; init; } = auth ? auth : roles != null;
/// <summary>
/// Roles for accessing this endpoint
/// </summary>
/// <value>Byte array, that can be null (no roles specified)</value>
public byte[]? Roles { get; init; } = roles;
/// <summary>
/// Description of endpoint
/// </summary>
/// <value>String if specified, null otherwise</value>
public string? Description { get; init; } = description;
internal bool IsMatch(string url, HTTP.Methods method)
=> Regex.IsMatch(url, this.Url)
&& (from m in this.Methods select m == method).Any();
}