Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define DOCUMENTtransformerInOut
//#define DOCUMENTtransformer1
//#define DOCUMENTtransformer2
// #define DOCUMENTtransformerUse999
//#define DOCUMENTtransformerUse999
//#define FIRST
//#define OPENAPIWITHSCALAR
//#define MAPOPENAPIWITHCACHING
Expand Down Expand Up @@ -61,7 +61,7 @@ internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Builder;

var builder = WebApplication.CreateBuilder();
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenApi(options =>
{
Expand Down Expand Up @@ -96,7 +96,7 @@ internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

var builder = WebApplication.CreateBuilder();

Expand Down Expand Up @@ -125,7 +125,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
var authenticationSchemes = await authenticationSchemeProvider.GetAllSchemesAsync();
if (authenticationSchemes.Any(authScheme => authScheme.Name == "Bearer"))
{
var requirements = new Dictionary<string, OpenApiSecurityScheme>
var securitySchemes = new Dictionary<string, IOpenApiSecurityScheme>
{
["Bearer"] = new OpenApiSecurityScheme
{
Expand All @@ -136,7 +136,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
}
};
document.Components ??= new OpenApiComponents();
document.Components.SecuritySchemes = requirements;
document.Components.SecuritySchemes = securitySchemes;
}
}
}
Expand All @@ -149,7 +149,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

var builder = WebApplication.CreateBuilder();

Expand All @@ -159,6 +159,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
{
options.AddOperationTransformer((operation, context, cancellationToken) =>
{
operation.Responses ??= new OpenApiResponses();
operation.Responses.Add("500", new OpenApiResponse { Description = "Internal server error" });
return Task.CompletedTask;
});
Expand All @@ -183,7 +184,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

var builder = WebApplication.CreateBuilder();

Expand Down Expand Up @@ -217,7 +218,7 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
if (authenticationSchemes.Any(authScheme => authScheme.Name == "Bearer"))
{
// Add the security scheme at the document level
var requirements = new Dictionary<string, OpenApiSecurityScheme>
var securitySchemes = new Dictionary<string, IOpenApiSecurityScheme>
{
["Bearer"] = new OpenApiSecurityScheme
{
Expand All @@ -228,14 +229,15 @@ public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransf
}
};
document.Components ??= new OpenApiComponents();
document.Components.SecuritySchemes = requirements;
document.Components.SecuritySchemes = securitySchemes;

// Apply it as a requirement for all operations
foreach (var operation in document.Paths.Values.SelectMany(path => path.Operations))
{
operation.Value.Security ??= [];
operation.Value.Security.Add(new OpenApiSecurityRequirement
{
[new OpenApiSecurityScheme { Reference = new OpenApiReference { Id = "Bearer", Type = ReferenceType.SecurityScheme } }] = Array.Empty<string>()
[new OpenApiSecuritySchemeReference("Bearer")] = []
});
}
}
Expand Down Expand Up @@ -285,9 +287,9 @@ public class Body {
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

var builder = WebApplication.CreateBuilder();
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenApi();

Expand Down Expand Up @@ -316,9 +318,9 @@ public class Body {
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

var builder = WebApplication.CreateBuilder();
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAuthentication().AddJwtBearer();
builder.Services.AddAuthorization(o =>
Expand All @@ -343,9 +345,9 @@ public class Body {
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

var builder = WebApplication.CreateBuilder();
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOutputCache(options =>
{
Expand Down Expand Up @@ -374,10 +376,10 @@ public class Body {
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;
using Scalar.AspNetCore;

var builder = WebApplication.CreateBuilder();
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenApi();

Expand Down Expand Up @@ -417,9 +419,9 @@ public class Body {
#if DOCUMENTtransformerUse999
// <snippet_transUse>
using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

var builder = WebApplication.CreateBuilder();
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenApi(options =>
{
Expand Down Expand Up @@ -485,9 +487,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
#if DOCUMENTtransformerInOut
// <snippet_transInOut>
using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

var builder = WebApplication.CreateBuilder();
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenApi(options =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<OpenApiDocumentsDirectory>./</OpenApiDocumentsDirectory>
Expand All @@ -14,14 +14,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.0">
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0-rc.1.25451.107" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0-rc.1.25451.107" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="10.0.0-rc.1.25451.107">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Scalar.AspNetCore" Version="1.2.50" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUi" Version="7.1.0" />
<PackageReference Include="Scalar.AspNetCore" Version="2.8.10" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUi" Version="9.0.6" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"sdk": {
"version": "9.0.100-rc.1.24414.13"
"version": "10.0.0",
"rollForward": "latestFeature",
"allowPrerelease": true
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand All @@ -12,8 +12,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.*-*" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.*-*">
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.*-*" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="10.0.*-*">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down