File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
src/ProjectTemplates/Web.ProjectTemplates/content/WebApiAot-CSharp Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -14,15 +14,19 @@ public static void Main(string[] args)
1414 options . SerializerOptions . TypeInfoResolverChain . Insert ( 0 , AppJsonSerializerContext . Default ) ;
1515 } ) ;
1616
17+ #if ( EnableOpenAPI )
1718 // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
1819 builder . Services . AddOpenApi ( ) ;
20+ #endif
1921
2022 var app = builder . Build ( ) ;
2123
24+ #if ( EnableOpenAPI )
2225 if ( app . Environment . IsDevelopment ( ) )
2326 {
2427 app . MapOpenApi ( ) ;
2528 }
29+ #endif
2630
2731 var sampleTodos = new Todo [ ] {
2832 new ( 1 , "Walk the dog" ) ,
@@ -33,7 +37,7 @@ public static void Main(string[] args)
3337 } ;
3438
3539 var todosApi = app . MapGroup ( "/todos" ) ;
36-
40+ #if ( EnableOpenAPI )
3741 todosApi . MapGet ( "/" , ( ) => sampleTodos )
3842 . WithName ( "GetTodos" ) ;
3943
@@ -42,6 +46,14 @@ public static void Main(string[] args)
4246 ? TypedResults . Ok ( todo )
4347 : TypedResults . NotFound ( ) )
4448 . WithName ( "GetTodoById" ) ;
49+ #else
50+ todosApi . MapGet ( "/" , ( ) => sampleTodos ) ;
51+
52+ todosApi . MapGet ( "/{id}" , Results < Ok < Todo > , NotFound > ( int id ) =>
53+ sampleTodos . FirstOrDefault ( a => a . Id == id ) is { } todo
54+ ? TypedResults . Ok ( todo )
55+ : TypedResults . NotFound ( ) ) ;
56+ #endif
4557
4658 app . Run ( ) ;
4759 }
Original file line number Diff line number Diff line change 88 options . SerializerOptions . TypeInfoResolverChain . Insert ( 0 , AppJsonSerializerContext . Default ) ;
99} ) ;
1010
11+ #if ( EnableOpenAPI )
1112// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
1213builder . Services . AddOpenApi ( ) ;
14+ #endif
1315
1416var app = builder . Build ( ) ;
1517
18+ #if ( EnableOpenAPI )
1619if ( app . Environment . IsDevelopment ( ) )
1720{
1821 app . MapOpenApi ( ) ;
1922}
23+ #endif
2024
2125var sampleTodos = new Todo [ ] {
2226 new ( 1 , "Walk the dog" ) ,
2731} ;
2832
2933var todosApi = app . MapGroup ( "/todos" ) ;
34+ #if ( EnableOpenAPI )
3035todosApi . MapGet ( "/" , ( ) => sampleTodos )
3136 . WithName ( "GetTodos" ) ;
3237
3540 ? TypedResults . Ok ( todo )
3641 : TypedResults . NotFound ( ) )
3742 . WithName ( "GetTodoById" ) ;
43+ #else
44+ todosApi . MapGet ( "/" , ( ) => sampleTodos ) ;
45+
46+ todosApi . MapGet ( "/{id}" , Results < Ok < Todo > , NotFound > ( int id ) =>
47+ sampleTodos . FirstOrDefault ( a => a . Id == id ) is { } todo
48+ ? TypedResults . Ok ( todo )
49+ : TypedResults . NotFound ( ) ) ;
50+ #endif
3851
3952app . Run ( ) ;
4053
You can’t perform that action at this time.
0 commit comments