@@ -8,9 +8,6 @@ namespace Api.Setup;
88
99internal static class ApiEndpoints
1010{
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 ) ) ;
13-
1411 public static void ConfigureEndpoints ( this WebApplication app )
1512 {
1613 var apiVersionSet = app . NewApiVersionSet ( )
@@ -42,8 +39,8 @@ public static void ConfigureEndpoints(this WebApplication app)
4239 . WithDescription ( "Get longest downward trend in days between given dates" )
4340 . WithOpenApi ( operation =>
4441 {
45- operation . Parameters [ 0 ] . Example = s_exampleFromDate ;
46- operation . Parameters [ ^ 1 ] . Example = s_exampleToDate ;
42+ operation . Parameters [ 0 ] . Example = GetExampleString ( - 1 ) ;
43+ operation . Parameters [ ^ 1 ] . Example = GetExampleString ( ) ;
4744 return operation ;
4845 } )
4946 . Produces < HighestTradingVolumeResponse > ( ( int ) HttpStatusCode . OK )
@@ -76,8 +73,8 @@ public static void ConfigureEndpoints(this WebApplication app)
7673 . WithDescription ( "Get the date with the highest trading volume between given dates" )
7774 . WithOpenApi ( operation =>
7875 {
79- operation . Parameters [ 0 ] . Example = s_exampleFromDate ;
80- operation . Parameters [ ^ 1 ] . Example = s_exampleToDate ;
76+ operation . Parameters [ 0 ] . Example = GetExampleString ( - 1 ) ;
77+ operation . Parameters [ ^ 1 ] . Example = GetExampleString ( ) ;
8178 return operation ;
8279 } )
8380 . Produces < HighestTradingVolumeResponse > ( ( int ) HttpStatusCode . OK )
@@ -110,8 +107,8 @@ public static void ConfigureEndpoints(this WebApplication app)
110107 . WithDescription ( "Get pair of dates when it is best to buy and sell between given dates" )
111108 . WithOpenApi ( operation =>
112109 {
113- operation . Parameters [ 0 ] . Example = s_exampleFromDate ;
114- operation . Parameters [ ^ 1 ] . Example = s_exampleToDate ;
110+ operation . Parameters [ 0 ] . Example = GetExampleString ( - 1 ) ;
111+ operation . Parameters [ ^ 1 ] . Example = GetExampleString ( ) ;
115112 return operation ;
116113 } )
117114 . Produces < BuyAndSellResponse > ( ( int ) HttpStatusCode . OK )
@@ -120,6 +117,11 @@ public static void ConfigureEndpoints(this WebApplication app)
120117 . ProducesProblem ( ( int ) HttpStatusCode . TooManyRequests )
121118 . ProducesProblem ( ( int ) HttpStatusCode . InternalServerError ) ;
122119 }
120+
121+ private static OpenApiString GetExampleString ( int addMonths = 0 )
122+ {
123+ return new ( DateOnlyExampleProvider . GetExample ( ) . AddMonths ( addMonths ) . ToString ( "yyyy-MM-dd" , CultureInfo . InvariantCulture ) ) ;
124+ }
123125}
124126
125127public record LongestDownwardTrendResponse ( int Days ) ;
0 commit comments