|
| 1 | +using System.Globalization; |
1 | 2 | using System.Net; |
2 | 3 | using Asp.Versioning; |
| 4 | +using Microsoft.OpenApi.Any; |
| 5 | +using Microsoft.OpenApi.Models; |
3 | 6 | using Services; |
4 | 7 |
|
5 | 8 | namespace Api.Setup; |
6 | 9 |
|
7 | 10 | internal static class ApiEndpoints |
8 | 11 | { |
9 | | - // private static readonly OpenApiString ExampleFromDate = new(DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); |
10 | | - // private static readonly OpenApiString ExampleToDate = new(DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); |
| 12 | + private static readonly OpenApiString s_exampleFromDate = new(DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); |
| 13 | + private static readonly OpenApiString s_exampleToDate = new(DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); |
11 | 14 |
|
12 | 15 | public static void ConfigureEndpoints(this WebApplication app) |
13 | 16 | { |
@@ -42,6 +45,12 @@ public static void ConfigureEndpoints(this WebApplication app) |
42 | 45 | .Produces((int)HttpStatusCode.BadRequest) |
43 | 46 | .ProducesProblem((int)HttpStatusCode.TooManyRequests) |
44 | 47 | .ProducesProblem((int)HttpStatusCode.InternalServerError) |
| 48 | + .WithOpenApi(operation => |
| 49 | + { |
| 50 | + operation.Parameters[0].Example = s_exampleFromDate; |
| 51 | + operation.Parameters[^1].Example = s_exampleToDate; |
| 52 | + return operation; |
| 53 | + }) |
45 | 54 | .WithDescription("Get longest downward trend in days between given dates"); |
46 | 55 |
|
47 | 56 | group.MapGet("/highestradingvolume", |
@@ -70,6 +79,12 @@ public static void ConfigureEndpoints(this WebApplication app) |
70 | 79 | .Produces((int)HttpStatusCode.BadRequest) |
71 | 80 | .ProducesProblem((int)HttpStatusCode.TooManyRequests) |
72 | 81 | .ProducesProblem((int)HttpStatusCode.InternalServerError) |
| 82 | + .WithOpenApi(operation => |
| 83 | + { |
| 84 | + operation.Parameters[0].Example = s_exampleFromDate; |
| 85 | + operation.Parameters[^1].Example = s_exampleToDate; |
| 86 | + return operation; |
| 87 | + }) |
73 | 88 | .WithDescription("Get the date with the highest trading volume between given dates"); |
74 | 89 |
|
75 | 90 | group.MapGet("/buyandsell", |
@@ -98,20 +113,14 @@ public static void ConfigureEndpoints(this WebApplication app) |
98 | 113 | .Produces((int)HttpStatusCode.BadRequest) |
99 | 114 | .ProducesProblem((int)HttpStatusCode.TooManyRequests) |
100 | 115 | .ProducesProblem((int)HttpStatusCode.InternalServerError) |
| 116 | + .WithOpenApi(operation => |
| 117 | + { |
| 118 | + operation.Parameters[0].Example = s_exampleFromDate; |
| 119 | + operation.Parameters[^1].Example = s_exampleToDate; |
| 120 | + return operation; |
| 121 | + }) |
101 | 122 | .WithDescription("Get pair of dates when it is best to buy and sell between given dates"); |
102 | 123 | } |
103 | | - |
104 | | - // private static void ConfigureEndpoint(RouteGroupBuilder group, string route, string description, Delegate handler) |
105 | | - // { |
106 | | - // group.MapGet(route, handler) |
107 | | - // .WithDescription(description) |
108 | | - // .WithOpenApi(operation => |
109 | | - // { |
110 | | - // operation.Parameters[0].Example = ExampleFromDate; |
111 | | - // operation.Parameters[^1].Example = ExampleToDate; |
112 | | - // return operation; |
113 | | - // }); |
114 | | - // } |
115 | 124 | } |
116 | 125 |
|
117 | 126 | public record LongestDownwardTrendResponse(int Days); |
|
0 commit comments