Skip to content

Commit 8fe7acb

Browse files
Add MapApiGroup and validation
1 parent 5515464 commit 8fe7acb

File tree

12 files changed

+1487
-1131
lines changed

12 files changed

+1487
-1131
lines changed

examples/AspNetCore/WebApi/MinimalApiExample/Program.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
1818
};
1919

20-
var forecast = app.MapGroup( "/weatherforecast" ).WithApiVersionSet();
20+
var forecast = app.MapApiGroup();
2121

2222
// GET /weatherforecast?api-version=1.0
23-
forecast.MapGet( "/", () =>
23+
forecast.MapGet( "/weatherforecast", () =>
2424
{
2525
return Enumerable.Range( 1, 5 ).Select( index =>
2626
new WeatherForecast
@@ -33,24 +33,25 @@
3333
.HasApiVersion( 1.0 );
3434

3535
// GET /weatherforecast?api-version=2.0
36-
forecast.MapGet( "/", () =>
37-
{
38-
return Enumerable.Range( 0, summaries.Length ).Select( index =>
39-
new WeatherForecast
40-
(
41-
DateTime.Now.AddDays( index ),
42-
Random.Shared.Next( -20, 55 ),
43-
summaries[Random.Shared.Next( summaries.Length )]
44-
) );
45-
} )
46-
.HasApiVersion( 2.0 );
36+
var v2 = forecast.MapGroup( "/weatherforecast" )
37+
.HasApiVersion( 2.0 );
38+
39+
v2.MapGet( "/", () =>
40+
{
41+
return Enumerable.Range( 0, summaries.Length ).Select( index =>
42+
new WeatherForecast
43+
(
44+
DateTime.Now.AddDays( index ),
45+
Random.Shared.Next( -20, 55 ),
46+
summaries[Random.Shared.Next( summaries.Length )]
47+
) );
48+
} );
4749

4850
// POST /weatherforecast?api-version=2.0
49-
forecast.MapPost( "/", ( WeatherForecast forecast ) => { } )
50-
.HasApiVersion( 2.0 );
51+
v2.MapPost( "/", ( WeatherForecast forecast ) => Results.Ok() );
5152

5253
// DELETE /weatherforecast
53-
forecast.MapDelete( "/", () => Results.NoContent() )
54+
forecast.MapDelete( "/weatherforecast", () => Results.NoContent() )
5455
.IsApiVersionNeutral();
5556

5657
app.Run();

0 commit comments

Comments
 (0)