| | 1 | |
|
| | 2 | | using System.Reflection; |
| | 3 | | using Kestrun.Scripting; |
| | 4 | | using Kestrun.Utilities; |
| | 5 | |
|
| | 6 | | namespace Kestrun.Hosting.Options; |
| | 7 | | /// <summary> |
| | 8 | | /// Options for mapping a route, including pattern, HTTP verbs, script code, authorization, and metadata. |
| | 9 | | /// </summary> |
| | 10 | | public record MapRouteOptions |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// The route pattern to match for this option. |
| | 14 | | /// </summary> |
| 154 | 15 | | public string? Pattern { get; set; } |
| | 16 | | /// <summary> |
| | 17 | | /// The HTTP verbs (methods) that this route responds to. |
| | 18 | | /// </summary> |
| 105 | 19 | | public List<HttpVerb> HttpVerbs { get; set; } = []; |
| | 20 | | /// <summary> |
| | 21 | | /// The script code to execute for this route. |
| | 22 | | /// </summary> |
| 35 | 23 | | public string? Code { get; set; } |
| | 24 | | /// <summary> |
| | 25 | | /// The scripting language used for the route's code. |
| | 26 | | /// </summary> |
| 68 | 27 | | public ScriptLanguage Language { get; set; } = ScriptLanguage.PowerShell; |
| | 28 | | /// <summary> |
| | 29 | | /// Additional import namespaces required for the script code. |
| | 30 | | /// </summary> |
| 11 | 31 | | public string[]? ExtraImports { get; set; } |
| | 32 | | /// <summary> |
| | 33 | | /// Additional assembly references required for the script code. |
| | 34 | | /// </summary> |
| 11 | 35 | | public Assembly[]? ExtraRefs { get; set; } |
| | 36 | | /// <summary> |
| | 37 | | /// Authorization Scheme names required for this route. |
| | 38 | | /// </summary> |
| 38 | 39 | | public string[] RequireSchemes { get; set; } = []; // Authorization scheme name, if any |
| | 40 | | /// <summary> |
| | 41 | | /// Authorization policy names required for this route. |
| | 42 | | /// </summary> |
| 33 | 43 | | public string[]? RequirePolicies { get; set; } = []; // Authorization policies, if any |
| | 44 | | /// <summary> |
| | 45 | | /// Name of the CORS policy to apply, if any. |
| | 46 | | /// </summary> |
| 27 | 47 | | public string CorsPolicyName { get; set; } = string.Empty; // Name of the CORS policy to apply, if any |
| | 48 | | /// <summary> |
| | 49 | | /// If true, short-circuits the pipeline after this route. |
| | 50 | | /// </summary> |
| 13 | 51 | | public bool ShortCircuit { get; set; } // If true, short-circuit the pipeline after this route |
| | 52 | | /// <summary> |
| | 53 | | /// Status code to return if short-circuiting the pipeline after this route. |
| | 54 | | /// </summary> |
| 1 | 55 | | public int? ShortCircuitStatusCode { get; set; } = null; // Status code to return if short-circuiting |
| | 56 | | /// <summary> |
| | 57 | | /// If true, allows anonymous access to this route. |
| | 58 | | /// </summary> |
| 13 | 59 | | public bool AllowAnonymous { get; set; } |
| | 60 | | /// <summary> |
| | 61 | | /// If true, disables antiforgery protection for this route. |
| | 62 | | /// </summary> |
| 13 | 63 | | public bool DisableAntiforgery { get; set; } |
| | 64 | | /// <summary> |
| | 65 | | /// The name of the rate limit policy to apply to this route, if any. |
| | 66 | | /// </summary> |
| 13 | 67 | | public string? RateLimitPolicyName { get; set; } |
| | 68 | |
|
| | 69 | | /// <summary> |
| | 70 | | /// Additional metadata for the route, represented as key-value pairs. |
| | 71 | | /// </summary> |
| 28 | 72 | | public Dictionary<string, object?>? Arguments { get; set; } = []; // Additional metadata for the route |
| | 73 | |
|
| | 74 | | /// <summary> |
| | 75 | | /// Metadata for OpenAPI documentation related to the route. |
| | 76 | | /// </summary> |
| | 77 | | public record OpenAPIMetadata |
| | 78 | | { |
| | 79 | | /// <summary> |
| | 80 | | /// A brief summary of the route for OpenAPI documentation. |
| | 81 | | /// </summary> |
| 11 | 82 | | public string? Summary { get; set; } |
| | 83 | | /// <summary> |
| | 84 | | /// A detailed description of the route for OpenAPI documentation. |
| | 85 | | /// </summary> |
| 11 | 86 | | public string? Description { get; set; } |
| | 87 | | /// <summary> |
| | 88 | | /// The unique operation ID for the route in OpenAPI documentation. |
| | 89 | | /// </summary> |
| 11 | 90 | | public string? OperationId { get; set; } |
| | 91 | | /// <summary> |
| | 92 | | /// Comma-separated tags for OpenAPI documentation. |
| | 93 | | /// </summary> |
| 27 | 94 | | public string[] Tags { get; set; } = []; // Comma-separated tags |
| | 95 | | /// <summary> |
| | 96 | | /// Group name for OpenAPI documentation. |
| | 97 | | /// </summary> |
| 11 | 98 | | public string? GroupName { get; set; } // Group name for OpenAPI documentation |
| | 99 | | } |
| | 100 | |
|
| | 101 | | /// <summary> |
| | 102 | | /// OpenAPI metadata for this route. |
| | 103 | | /// </summary> |
| 67 | 104 | | public OpenAPIMetadata OpenAPI { get; set; } = new OpenAPIMetadata(); // OpenAPI metadata for this route |
| | 105 | |
|
| | 106 | | /// <summary> |
| | 107 | | /// If true, throws an exception on duplicate routes. |
| | 108 | | /// </summary> |
| 5 | 109 | | public bool ThrowOnDuplicate { get; set; } |
| | 110 | | } |