File tree Expand file tree Collapse file tree 2 files changed +38
-4
lines changed
src/ProjectTemplates/Web.ProjectTemplates/content/WebApiAot-CSharp Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -24,11 +24,22 @@ public static void Main(string[] args)
2424 } ;
2525
2626 var todosApi = app . MapGroup ( "/todos" ) ;
27- todosApi . MapGet ( "/" , ( ) => sampleTodos ) ;
27+ todosApi . MapGet ( "/" , ( ) => sampleTodos )
28+ #if ( EnableOpenAPI )
29+ . WithName ( "GetTodos" ) ;
30+ #elif
31+ ;
32+ #endif
33+
2834 todosApi . MapGet ( "/{id}" , ( int id ) =>
2935 sampleTodos . FirstOrDefault ( a => a . Id == id ) is { } todo
3036 ? Results . Ok ( todo )
31- : Results . NotFound ( ) ) ;
37+ : Results . NotFound ( ) )
38+ #if ( EnableOpenAPI )
39+ . WithName ( "GetTodoById" ) ;
40+ #elif
41+ ;
42+ #endif
3243
3344 app . Run ( ) ;
3445 }
Original file line number Diff line number Diff line change 77 options . SerializerOptions . TypeInfoResolverChain . Insert ( 0 , AppJsonSerializerContext . Default ) ;
88} ) ;
99
10+ #if ( EnableOpenAPI )
11+ // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
12+ builder . Services . AddOpenApi ( ) ;
13+ #endif
14+
1015var app = builder . Build ( ) ;
1116
17+ #if ( EnableOpenAPI )
18+ if ( app . Environment . IsDevelopment ( ) )
19+ {
20+ app . MapOpenApi ( ) ;
21+ }
22+ #endif
23+
1224var sampleTodos = new Todo [ ] {
1325 new ( 1 , "Walk the dog" ) ,
1426 new ( 2 , "Do the dishes" , DateOnly . FromDateTime ( DateTime . Now ) ) ,
1830} ;
1931
2032var todosApi = app . MapGroup ( "/todos" ) ;
21- todosApi . MapGet ( "/" , ( ) => sampleTodos ) ;
33+ todosApi . MapGet ( "/" , ( ) => sampleTodos )
34+ #if ( EnableOpenAPI )
35+ . WithName ( "GetTodos" ) ;
36+ #elif
37+ ;
38+ #endif
39+
2240todosApi . MapGet ( "/{id}" , ( int id ) =>
2341 sampleTodos . FirstOrDefault ( a => a . Id == id ) is { } todo
2442 ? Results . Ok ( todo )
25- : Results . NotFound ( ) ) ;
43+ : Results . NotFound ( ) )
44+ #if ( EnableOpenAPI )
45+ . WithName ( "GetTodoById" ) ;
46+ #elif
47+ ;
48+ #endif
2649
2750app . Run ( ) ;
2851
You can’t perform that action at this time.
0 commit comments