22#define DOCUMENTtransformerInOut
33//#define DOCUMENTtransformer1
44//#define DOCUMENTtransformer2
5- // #define DOCUMENTtransformerUse999
5+ //#define DOCUMENTtransformerUse999
66//#define FIRST
77//#define OPENAPIWITHSCALAR
88//#define MAPOPENAPIWITHCACHING
@@ -61,7 +61,7 @@ internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary
6161using Microsoft . Extensions . DependencyInjection ;
6262using Microsoft . AspNetCore . Builder ;
6363
64- var builder = WebApplication . CreateBuilder ( ) ;
64+ var builder = WebApplication . CreateBuilder ( args ) ;
6565
6666builder . Services . AddOpenApi ( options =>
6767{
@@ -96,7 +96,7 @@ internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary
9696using Microsoft . AspNetCore . Builder ;
9797using Microsoft . AspNetCore . OpenApi ;
9898using Microsoft . Extensions . DependencyInjection ;
99- using Microsoft . OpenApi . Models ;
99+ using Microsoft . OpenApi ;
100100
101101var builder = WebApplication . CreateBuilder ( ) ;
102102
@@ -125,7 +125,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
125125 var authenticationSchemes = await authenticationSchemeProvider . GetAllSchemesAsync ( ) ;
126126 if ( authenticationSchemes . Any ( authScheme => authScheme . Name == "Bearer" ) )
127127 {
128- var requirements = new Dictionary < string , OpenApiSecurityScheme >
128+ var securitySchemes = new Dictionary < string , IOpenApiSecurityScheme >
129129 {
130130 [ "Bearer" ] = new OpenApiSecurityScheme
131131 {
@@ -136,7 +136,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
136136 }
137137 } ;
138138 document . Components ??= new OpenApiComponents ( ) ;
139- document . Components . SecuritySchemes = requirements ;
139+ document . Components . SecuritySchemes = securitySchemes ;
140140 }
141141 }
142142}
@@ -149,7 +149,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
149149using Microsoft . AspNetCore . Builder ;
150150using Microsoft . AspNetCore . OpenApi ;
151151using Microsoft . Extensions . DependencyInjection ;
152- using Microsoft . OpenApi . Models ;
152+ using Microsoft . OpenApi ;
153153
154154var builder = WebApplication . CreateBuilder ( ) ;
155155
@@ -159,6 +159,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
159159{
160160 options . AddOperationTransformer ( ( operation , context , cancellationToken ) =>
161161 {
162+ operation . Responses ??= new OpenApiResponses ( ) ;
162163 operation . Responses . Add ( "500" , new OpenApiResponse { Description = "Internal server error" } ) ;
163164 return Task . CompletedTask ;
164165 } ) ;
@@ -183,7 +184,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
183184using Microsoft . AspNetCore . Builder ;
184185using Microsoft . AspNetCore . OpenApi ;
185186using Microsoft . Extensions . DependencyInjection ;
186- using Microsoft . OpenApi . Models ;
187+ using Microsoft . OpenApi ;
187188
188189var builder = WebApplication . CreateBuilder ( ) ;
189190
@@ -217,7 +218,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
217218 if ( authenticationSchemes . Any ( authScheme => authScheme . Name == "Bearer" ) )
218219 {
219220 // Add the security scheme at the document level
220- var requirements = new Dictionary < string , OpenApiSecurityScheme >
221+ var securitySchemes = new Dictionary < string , IOpenApiSecurityScheme >
221222 {
222223 [ "Bearer" ] = new OpenApiSecurityScheme
223224 {
@@ -228,14 +229,15 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
228229 }
229230 } ;
230231 document . Components ??= new OpenApiComponents ( ) ;
231- document . Components . SecuritySchemes = requirements ;
232+ document . Components . SecuritySchemes = securitySchemes ;
232233
233234 // Apply it as a requirement for all operations
234235 foreach ( var operation in document . Paths . Values . SelectMany ( path => path . Operations ) )
235236 {
237+ operation . Value . Security ??= [ ] ;
236238 operation . Value . Security . Add ( new OpenApiSecurityRequirement
237239 {
238- [ new OpenApiSecurityScheme { Reference = new OpenApiReference { Id = "Bearer" , Type = ReferenceType . SecurityScheme } } ] = Array . Empty < string > ( )
240+ [ new OpenApiSecuritySchemeReference ( "Bearer" ) ] = [ ]
239241 } ) ;
240242 }
241243 }
@@ -285,9 +287,9 @@ public class Body {
285287using Microsoft . AspNetCore . Builder ;
286288using Microsoft . AspNetCore . OpenApi ;
287289using Microsoft . Extensions . DependencyInjection ;
288- using Microsoft . OpenApi . Models ;
290+ using Microsoft . OpenApi ;
289291
290- var builder = WebApplication . CreateBuilder ( ) ;
292+ var builder = WebApplication . CreateBuilder ( args ) ;
291293
292294builder . Services . AddOpenApi ( ) ;
293295
@@ -316,9 +318,9 @@ public class Body {
316318using Microsoft . AspNetCore . Builder ;
317319using Microsoft . AspNetCore . OpenApi ;
318320using Microsoft . Extensions . DependencyInjection ;
319- using Microsoft . OpenApi . Models ;
321+ using Microsoft . OpenApi ;
320322
321- var builder = WebApplication . CreateBuilder ( ) ;
323+ var builder = WebApplication . CreateBuilder ( args ) ;
322324
323325builder . Services . AddAuthentication ( ) . AddJwtBearer ( ) ;
324326builder . Services . AddAuthorization ( o =>
@@ -343,9 +345,9 @@ public class Body {
343345using Microsoft . AspNetCore . Builder ;
344346using Microsoft . AspNetCore . OpenApi ;
345347using Microsoft . Extensions . DependencyInjection ;
346- using Microsoft . OpenApi . Models ;
348+ using Microsoft . OpenApi ;
347349
348- var builder = WebApplication . CreateBuilder ( ) ;
350+ var builder = WebApplication . CreateBuilder ( args ) ;
349351
350352builder . Services . AddOutputCache ( options =>
351353{
@@ -374,10 +376,10 @@ public class Body {
374376using Microsoft . AspNetCore . Builder ;
375377using Microsoft . AspNetCore . OpenApi ;
376378using Microsoft . Extensions . DependencyInjection ;
377- using Microsoft . OpenApi . Models ;
379+ using Microsoft . OpenApi ;
378380using Scalar . AspNetCore ;
379381
380- var builder = WebApplication . CreateBuilder ( ) ;
382+ var builder = WebApplication . CreateBuilder ( args ) ;
381383
382384builder . Services . AddOpenApi ( ) ;
383385
@@ -417,9 +419,9 @@ public class Body {
417419#if DOCUMENTtransformerUse999
418420// <snippet_transUse>
419421using Microsoft . AspNetCore . OpenApi ;
420- using Microsoft . OpenApi . Models ;
422+ using Microsoft . OpenApi ;
421423
422- var builder = WebApplication . CreateBuilder ( ) ;
424+ var builder = WebApplication . CreateBuilder ( args ) ;
423425
424426builder . Services . AddOpenApi ( options =>
425427{
@@ -485,9 +487,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
485487#if DOCUMENTtransformerInOut
486488// <snippet_transInOut>
487489using Microsoft . AspNetCore . OpenApi ;
488- using Microsoft . OpenApi . Models ;
490+ using Microsoft . OpenApi ;
489491
490- var builder = WebApplication . CreateBuilder ( ) ;
492+ var builder = WebApplication . CreateBuilder ( args ) ;
491493
492494builder . Services . AddOpenApi ( options =>
493495{
0 commit comments