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