Skip to content

Commit 366e565

Browse files
Update Swashbuckle.AspNetCore
Update Swashbuckle.AspNetCore to a version that supports ASP.NET Core 10 preview 2 and Microsoft.OpenApi 2.0.0-preview7.
1 parent f984b6e commit 366e565

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

src/TodoApp/OpenApi/Swashbuckle/ExampleFilter.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
33

44
using Microsoft.OpenApi.Models;
5+
using Microsoft.OpenApi.Models.Interfaces;
56
using Swashbuckle.AspNetCore.SwaggerGen;
67

78
namespace TodoApp.OpenApi.Swashbuckle;
@@ -16,6 +17,11 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
1617
=> Process(operation, context.ApiDescription);
1718

1819
/// <inheritdoc />
19-
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
20-
=> Process(schema, context.Type);
20+
public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
21+
{
22+
if (schema is OpenApiSchema concrete)
23+
{
24+
Process(concrete, context.Type);
25+
}
26+
}
2127
}

src/TodoApp/OpenApi/Swashbuckle/SwashbuckleOpenApiEndpoints.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ public static IServiceCollection AddSwashbuckleOpenApi(this IServiceCollection s
4242
Type = SecuritySchemeType.Http,
4343
};
4444

45-
var reference = new OpenApiSecuritySchemeReference("Bearer");
46-
47-
options.AddSecurityDefinition(reference.Reference.Id, scheme);
48-
options.AddSecurityRequirement(new() { [reference] = [] });
45+
options.AddSecurityDefinition("Bearer", scheme);
46+
options.AddSecurityRequirement((document) => new() { [new("Bearer", document)] = [] });
4947

5048
// Enable reading OpenAPI metadata from attributes
5149
options.EnableAnnotations();

src/TodoApp/TodoApp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
<PackageReference Include="Microsoft.OpenApi" Version="2.0.0-preview7" />
2121
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.8.1" PrivateAssets="all" />
2222
<PackageReference Include="NSwag.AspNetCore" Version="14.2.0" />
23-
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.0-pr.3283.1134" />
24-
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="9.0.0-pr.3283.1134" />
23+
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.0-pr.3283.1238" />
24+
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="9.0.0-pr.3283.1238" />
2525
</ItemGroup>
2626
<ItemGroup>
2727
<Content Update="package.json;package-lock.json;tsconfig.json" CopyToPublishDirectory="Never" />

tests/TodoApp.Tests/OpenApiTests.Schema_Is_Correct_schemaUrl=swagger.verified.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@
260260
properties: {
261261
text: {
262262
type: string,
263-
description: Gets or sets the text of the Todo item.,
264-
nullable: true
263+
nullable: true,
264+
description: Gets or sets the text of the Todo item.
265265
}
266266
},
267267
additionalProperties: false,
@@ -275,8 +275,8 @@
275275
properties: {
276276
id: {
277277
type: string,
278-
description: Gets or sets the ID of the created Todo item.,
279-
nullable: true
278+
nullable: true,
279+
description: Gets or sets the ID of the created Todo item.
280280
}
281281
},
282282
additionalProperties: false,
@@ -298,8 +298,8 @@
298298
},
299299
status: {
300300
type: integer,
301-
format: int32,
302-
nullable: true
301+
nullable: true,
302+
format: int32
303303
},
304304
detail: {
305305
type: string,
@@ -322,22 +322,22 @@
322322
properties: {
323323
id: {
324324
type: string,
325-
description: Gets or sets the ID of the Todo item.,
326-
nullable: true
325+
nullable: true,
326+
description: Gets or sets the ID of the Todo item.
327327
},
328328
text: {
329329
type: string,
330-
description: Gets or sets the text of the Todo item.,
331-
nullable: true
330+
nullable: true,
331+
description: Gets or sets the text of the Todo item.
332332
},
333333
isCompleted: {
334334
type: boolean,
335335
description: Gets or sets a value indicating whether the Todo item has been completed.
336336
},
337337
lastUpdated: {
338338
type: string,
339-
description: Gets or sets the date and time the Todo item was last updated.,
340-
nullable: true
339+
nullable: true,
340+
description: Gets or sets the date and time the Todo item was last updated.
341341
}
342342
},
343343
additionalProperties: false,
@@ -353,11 +353,11 @@
353353
properties: {
354354
items: {
355355
type: array,
356+
nullable: true,
356357
items: {
357358
$ref: #/components/schemas/TodoItemModel
358359
},
359-
description: Gets or sets the Todo item(s).,
360-
nullable: true
360+
description: Gets or sets the Todo item(s).
361361
}
362362
},
363363
additionalProperties: false,

tests/TodoApp.Tests/OpenApiTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public OpenApiTests(TodoAppFixture fixture, ITestOutputHelper outputHelper)
2626
[Theory]
2727
[InlineData("/nswag/v1.json")]
2828
[InlineData("/openapi/v1.json", Skip = "https://github.com/dotnet/aspnetcore/issues/61038")]
29-
[InlineData("/swagger/v1/swagger.json", Skip = "Depends on a version of Swashbuckle.AspNetCore that supports Microsoft.OpenApi 2.0.0-preview7.")]
29+
[InlineData("/swagger/v1/swagger.json", Skip = "https://github.com/microsoft/OpenAPI.NET/issues/2300")]
3030
public async Task Schema_Is_Correct(string schemaUrl)
3131
{
3232
// Arrange
@@ -49,7 +49,7 @@ public async Task Schema_Is_Correct(string schemaUrl)
4949
[Theory]
5050
[InlineData("/nswag/v1.json")]
5151
[InlineData("/openapi/v1.json")]
52-
[InlineData("/swagger/v1/swagger.json", Skip = "Depends on a version of Swashbuckle.AspNetCore that supports Microsoft.OpenApi 2.0.0-preview7.")]
52+
[InlineData("/swagger/v1/swagger.json")]
5353
public async Task Schema_Has_No_Validation_Warnings(string schemaUrl)
5454
{
5555
// Arrange

0 commit comments

Comments
 (0)