2
2
#define DOCUMENTtransformerInOut
3
3
//#define DOCUMENTtransformer1
4
4
//#define DOCUMENTtransformer2
5
- // #define DOCUMENTtransformerUse999
5
+ //#define DOCUMENTtransformerUse999
6
6
//#define FIRST
7
7
//#define OPENAPIWITHSCALAR
8
8
//#define MAPOPENAPIWITHCACHING
@@ -61,7 +61,7 @@ internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary
61
61
using Microsoft . Extensions . DependencyInjection ;
62
62
using Microsoft . AspNetCore . Builder ;
63
63
64
- var builder = WebApplication . CreateBuilder ( ) ;
64
+ var builder = WebApplication . CreateBuilder ( args ) ;
65
65
66
66
builder . Services . AddOpenApi ( options =>
67
67
{
@@ -96,7 +96,7 @@ internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary
96
96
using Microsoft . AspNetCore . Builder ;
97
97
using Microsoft . AspNetCore . OpenApi ;
98
98
using Microsoft . Extensions . DependencyInjection ;
99
- using Microsoft . OpenApi . Models ;
99
+ using Microsoft . OpenApi ;
100
100
101
101
var builder = WebApplication . CreateBuilder ( ) ;
102
102
@@ -125,7 +125,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
125
125
var authenticationSchemes = await authenticationSchemeProvider . GetAllSchemesAsync ( ) ;
126
126
if ( authenticationSchemes . Any ( authScheme => authScheme . Name == "Bearer" ) )
127
127
{
128
- var requirements = new Dictionary < string , OpenApiSecurityScheme >
128
+ var securitySchemes = new Dictionary < string , IOpenApiSecurityScheme >
129
129
{
130
130
[ "Bearer" ] = new OpenApiSecurityScheme
131
131
{
@@ -136,7 +136,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
136
136
}
137
137
} ;
138
138
document . Components ??= new OpenApiComponents ( ) ;
139
- document . Components . SecuritySchemes = requirements ;
139
+ document . Components . SecuritySchemes = securitySchemes ;
140
140
}
141
141
}
142
142
}
@@ -149,7 +149,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
149
149
using Microsoft . AspNetCore . Builder ;
150
150
using Microsoft . AspNetCore . OpenApi ;
151
151
using Microsoft . Extensions . DependencyInjection ;
152
- using Microsoft . OpenApi . Models ;
152
+ using Microsoft . OpenApi ;
153
153
154
154
var builder = WebApplication . CreateBuilder ( ) ;
155
155
@@ -159,6 +159,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
159
159
{
160
160
options . AddOperationTransformer ( ( operation , context , cancellationToken ) =>
161
161
{
162
+ operation . Responses ??= new OpenApiResponses ( ) ;
162
163
operation . Responses . Add ( "500" , new OpenApiResponse { Description = "Internal server error" } ) ;
163
164
return Task . CompletedTask ;
164
165
} ) ;
@@ -183,7 +184,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
183
184
using Microsoft . AspNetCore . Builder ;
184
185
using Microsoft . AspNetCore . OpenApi ;
185
186
using Microsoft . Extensions . DependencyInjection ;
186
- using Microsoft . OpenApi . Models ;
187
+ using Microsoft . OpenApi ;
187
188
188
189
var builder = WebApplication . CreateBuilder ( ) ;
189
190
@@ -217,7 +218,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
217
218
if ( authenticationSchemes . Any ( authScheme => authScheme . Name == "Bearer" ) )
218
219
{
219
220
// Add the security scheme at the document level
220
- var requirements = new Dictionary < string , OpenApiSecurityScheme >
221
+ var securitySchemes = new Dictionary < string , IOpenApiSecurityScheme >
221
222
{
222
223
[ "Bearer" ] = new OpenApiSecurityScheme
223
224
{
@@ -228,14 +229,15 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
228
229
}
229
230
} ;
230
231
document . Components ??= new OpenApiComponents ( ) ;
231
- document . Components . SecuritySchemes = requirements ;
232
+ document . Components . SecuritySchemes = securitySchemes ;
232
233
233
234
// Apply it as a requirement for all operations
234
235
foreach ( var operation in document . Paths . Values . SelectMany ( path => path . Operations ) )
235
236
{
237
+ operation . Value . Security ??= [ ] ;
236
238
operation . Value . Security . Add ( new OpenApiSecurityRequirement
237
239
{
238
- [ new OpenApiSecurityScheme { Reference = new OpenApiReference { Id = "Bearer" , Type = ReferenceType . SecurityScheme } } ] = Array . Empty < string > ( )
240
+ [ new OpenApiSecuritySchemeReference ( "Bearer" ) ] = [ ]
239
241
} ) ;
240
242
}
241
243
}
@@ -285,9 +287,9 @@ public class Body {
285
287
using Microsoft . AspNetCore . Builder ;
286
288
using Microsoft . AspNetCore . OpenApi ;
287
289
using Microsoft . Extensions . DependencyInjection ;
288
- using Microsoft . OpenApi . Models ;
290
+ using Microsoft . OpenApi ;
289
291
290
- var builder = WebApplication . CreateBuilder ( ) ;
292
+ var builder = WebApplication . CreateBuilder ( args ) ;
291
293
292
294
builder . Services . AddOpenApi ( ) ;
293
295
@@ -316,9 +318,9 @@ public class Body {
316
318
using Microsoft . AspNetCore . Builder ;
317
319
using Microsoft . AspNetCore . OpenApi ;
318
320
using Microsoft . Extensions . DependencyInjection ;
319
- using Microsoft . OpenApi . Models ;
321
+ using Microsoft . OpenApi ;
320
322
321
- var builder = WebApplication . CreateBuilder ( ) ;
323
+ var builder = WebApplication . CreateBuilder ( args ) ;
322
324
323
325
builder . Services . AddAuthentication ( ) . AddJwtBearer ( ) ;
324
326
builder . Services . AddAuthorization ( o =>
@@ -343,9 +345,9 @@ public class Body {
343
345
using Microsoft . AspNetCore . Builder ;
344
346
using Microsoft . AspNetCore . OpenApi ;
345
347
using Microsoft . Extensions . DependencyInjection ;
346
- using Microsoft . OpenApi . Models ;
348
+ using Microsoft . OpenApi ;
347
349
348
- var builder = WebApplication . CreateBuilder ( ) ;
350
+ var builder = WebApplication . CreateBuilder ( args ) ;
349
351
350
352
builder . Services . AddOutputCache ( options =>
351
353
{
@@ -374,10 +376,10 @@ public class Body {
374
376
using Microsoft . AspNetCore . Builder ;
375
377
using Microsoft . AspNetCore . OpenApi ;
376
378
using Microsoft . Extensions . DependencyInjection ;
377
- using Microsoft . OpenApi . Models ;
379
+ using Microsoft . OpenApi ;
378
380
using Scalar . AspNetCore ;
379
381
380
- var builder = WebApplication . CreateBuilder ( ) ;
382
+ var builder = WebApplication . CreateBuilder ( args ) ;
381
383
382
384
builder . Services . AddOpenApi ( ) ;
383
385
@@ -417,9 +419,9 @@ public class Body {
417
419
#if DOCUMENTtransformerUse999
418
420
// <snippet_transUse>
419
421
using Microsoft . AspNetCore . OpenApi ;
420
- using Microsoft . OpenApi . Models ;
422
+ using Microsoft . OpenApi ;
421
423
422
- var builder = WebApplication . CreateBuilder ( ) ;
424
+ var builder = WebApplication . CreateBuilder ( args ) ;
423
425
424
426
builder . Services . AddOpenApi ( options =>
425
427
{
@@ -485,9 +487,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
485
487
#if DOCUMENTtransformerInOut
486
488
// <snippet_transInOut>
487
489
using Microsoft . AspNetCore . OpenApi ;
488
- using Microsoft . OpenApi . Models ;
490
+ using Microsoft . OpenApi ;
489
491
490
- var builder = WebApplication . CreateBuilder ( ) ;
492
+ var builder = WebApplication . CreateBuilder ( args ) ;
491
493
492
494
builder . Services . AddOpenApi ( options =>
493
495
{
0 commit comments