Skip to content

Commit 8ee379d

Browse files
Update to .NET 10 (#231)
* Update to .NET 10 preview 4 Update to preview 4 of .NET 10. * Remove local packages Consume Swashbuckle packages from MyGet again. * Update .NET SDK to 10.0.100-preview.5.25277.114 (#330) * Update .NET SDK Update .NET SDK to version 10.0.100-preview.5.25277.114. --- updated-dependencies: - dependency-name: Microsoft.NET.Sdk dependency-version: 10.0.100-preview.5.25277.114 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: costellobot <[email protected]> * Bump .NET NuGet packages Bumps .NET dependencies to their latest versions for the .NET 10.0.100-preview.5.25277.114 SDK. Bumps Microsoft.AspNetCore.Mvc.Testing from 10.0.0-preview.4.25258.110 to 10.0.0-preview.5.25277.114. Bumps Microsoft.AspNetCore.OpenApi from 10.0.0-preview.4.25258.110 to 10.0.0-preview.5.25277.114. Bumps Microsoft.EntityFrameworkCore.Sqlite from 10.0.0-preview.4.25258.110 to 10.0.0-preview.5.25277.114. Bumps Microsoft.Extensions.ApiDescription.Server from 10.0.0-preview.4.25258.110 to 10.0.0-preview.5.25277.114. --- updated-dependencies: - dependency-name: Microsoft.AspNetCore.Mvc.Testing dependency-version: 10.0.0-preview.5.25277.114 dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.AspNetCore.OpenApi dependency-version: 10.0.0-preview.5.25277.114 dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.EntityFrameworkCore.Sqlite dependency-version: 10.0.0-preview.5.25277.114 dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.Extensions.ApiDescription.Server dependency-version: 10.0.0-preview.5.25277.114 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: costellobot <[email protected]> * Apply suggestions from code review * Bump Swashbuckle.AspNetCore Update for .NET 10 preview 5. --------- Signed-off-by: costellobot <[email protected]> Co-authored-by: Martin Costello <[email protected]> * Bump Swashbuckle.AspNetCore Update to v10. * Bump Swashbuckle.AspNetCore Update to the latest build. * Update to ASP.NET Core 10 preview 6 Update to preview 6 of ASP.NET Core 10. * Use UseKestrel() with WebApplicationFactory<T> Use the new `UseKestrel()` method for `WebApplicationFactory<T>` to remove the customisation needed to host the application on an HTTP port. * Update .NET SDK to 10.0.100-preview.7.25380.108 (#392) * Update .NET SDK Update .NET SDK to version 10.0.100-preview.7.25380.108. --- updated-dependencies: - dependency-name: Microsoft.NET.Sdk dependency-version: 10.0.100-preview.7.25380.108 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: costellobot <[email protected]> * Bump .NET NuGet packages Bumps .NET dependencies to their latest versions for the .NET 10.0.100-preview.7.25380.108 SDK. Bumps Microsoft.AspNetCore.Mvc.Testing from 10.0.0-preview.6.25358.103 to 10.0.0-preview.7.25380.108. Bumps Microsoft.AspNetCore.OpenApi from 10.0.0-preview.6.25358.103 to 10.0.0-preview.7.25380.108. Bumps Microsoft.EntityFrameworkCore.Sqlite from 10.0.0-preview.6.25358.103 to 10.0.0-preview.7.25380.108. Bumps Microsoft.Extensions.ApiDescription.Server from 10.0.0-preview.6.25358.103 to 10.0.0-preview.7.25380.108. --- updated-dependencies: - dependency-name: Microsoft.AspNetCore.Mvc.Testing dependency-version: 10.0.0-preview.7.25380.108 dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.AspNetCore.OpenApi dependency-version: 10.0.0-preview.7.25380.108 dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.EntityFrameworkCore.Sqlite dependency-version: 10.0.0-preview.7.25380.108 dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.Extensions.ApiDescription.Server dependency-version: 10.0.0-preview.7.25380.108 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: costellobot <[email protected]> --------- Signed-off-by: costellobot <[email protected]> * Update NuGet packages Update NuGet packages for .NET 10 preview 7. * Bump Microsoft.OpenApi Bump Microsoft.OpenApi to 2.1.0. * Update .NET SDK (#451) Update .NET SDK to version 10.0.100-rc.1.25451.107. --- updated-dependencies: - dependency-name: Microsoft.NET.Sdk dependency-version: 10.0.100-rc.1.25451.107 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: costellobot <[email protected]> * Update NuGet packages Update NuGet packages for .NET 10 RC1. * Fix build Update Swasbuckle.AspNetCore and Microsoft.OpenApi to their latest versions. * Bump Microsoft.OpenApi Bump Microsoft.OpenApi to 2.3.3. * Update .NET SDK to 10.0.100-rc.2.25502.107 (#519) * Update .NET SDK Update .NET SDK to version 10.0.100-rc.2.25502.107. --- updated-dependencies: - dependency-name: Microsoft.NET.Sdk dependency-version: 10.0.100-rc.2.25502.107 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: costellobot <[email protected]> * Bump .NET NuGet packages Bumps .NET dependencies to their latest versions for the .NET 10.0.100-rc.2.25502.107 SDK. Bumps Microsoft.AspNetCore.Mvc.Testing from 10.0.0-rc.1.25451.107 to 10.0.0-rc.2.25502.107. Bumps Microsoft.AspNetCore.OpenApi from 10.0.0-rc.1.25451.107 to 10.0.0-rc.2.25502.107. Bumps Microsoft.EntityFrameworkCore.Sqlite from 10.0.0-rc.1.25451.107 to 10.0.0-rc.2.25502.107. Bumps Microsoft.Extensions.ApiDescription.Server from 10.0.0-rc.1.25451.107 to 10.0.0-rc.2.25502.107. --- updated-dependencies: - dependency-name: Microsoft.AspNetCore.Mvc.Testing dependency-version: 10.0.0-rc.2.25502.107 dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.AspNetCore.OpenApi dependency-version: 10.0.0-rc.2.25502.107 dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.EntityFrameworkCore.Sqlite dependency-version: 10.0.0-rc.2.25502.107 dependency-type: direct:production update-type: version-update:semver-major - dependency-name: Microsoft.Extensions.ApiDescription.Server dependency-version: 10.0.0-rc.2.25502.107 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: costellobot <[email protected]> --------- Signed-off-by: costellobot <[email protected]> * Update Swashbuckle.AspNetCore Update packages for .NET 10 RC2. * Update Microsoft.OpenApi Update to the latest release of v2. * Update Swashbuckle.AspNetCore Update to latest prerelease. * Update to .NET 10 GA Update to stable version of .NET 10. --------- Signed-off-by: costellobot <[email protected]> Co-authored-by: martincostello <[email protected]>
1 parent 3cdda44 commit 8ee379d

20 files changed

+80
-230
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "coreclr",
77
"request": "launch",
88
"preLaunchTask": "build",
9-
"program": "${workspaceFolder}/src/TodoApp/bin/Debug/net9.0/TodoApp.dll",
9+
"program": "${workspaceFolder}/src/TodoApp/bin/Debug/net10.0/TodoApp.dll",
1010
"args": [],
1111
"cwd": "${workspaceFolder}/src/TodoApp",
1212
"stopAtEntry": false,

.vsconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "1.0",
33
"components": [
44
"Component.Microsoft.VisualStudio.RazorExtension",
5-
"Microsoft.NetCore.Component.Runtime.9.0",
5+
"Microsoft.NetCore.Component.Runtime.10.0",
66
"Microsoft.NetCore.Component.SDK",
77
"Microsoft.VisualStudio.Component.CoreEditor",
88
"Microsoft.VisualStudio.Component.JavaScript.Diagnostics",

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.307",
3+
"version": "10.0.100",
44
"allowPrerelease": false,
55
"rollForward": "latestMajor"
66
}

perf/TodoApp.Benchmarks/TodoApp.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
44
<RootNamespace>TodoApp</RootNamespace>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
</PropertyGroup>
77
<ItemGroup>
88
<ProjectReference Include="..\..\src\TodoApp\TodoApp.csproj" />

src/TodoApp/OpenApi/AspNetCore/AddExamplesTransformer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +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.AspNetCore.OpenApi;
5-
using Microsoft.OpenApi.Models;
5+
using Microsoft.OpenApi;
66

77
namespace TodoApp.OpenApi.AspNetCore;
88

src/TodoApp/OpenApi/AspNetCore/AddSchemaDescriptionsTransformer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Xml;
88
using System.Xml.XPath;
99
using Microsoft.AspNetCore.OpenApi;
10-
using Microsoft.OpenApi.Models;
10+
using Microsoft.OpenApi;
1111

1212
namespace TodoApp.OpenApi.AspNetCore;
1313

src/TodoApp/OpenApi/AspNetCore/AspNetCoreOpenApiEndpoints.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Martin Costello, 2024. All rights reserved.
22
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
33

4-
using Microsoft.OpenApi.Models;
4+
using Microsoft.OpenApi;
55

66
namespace TodoApp.OpenApi.AspNetCore;
77

@@ -14,6 +14,9 @@ public static IServiceCollection AddAspNetCoreOpenApi(this IServiceCollection se
1414
// Add a document transformer to customise the generated OpenAPI document
1515
options.AddDocumentTransformer((document, _, _) =>
1616
{
17+
// TODO Use 3.1 when all three OpenAPI implementations support it
18+
options.OpenApiVersion = Microsoft.OpenApi.OpenApiSpecVersion.OpenApi3_0;
19+
1720
// Add a title and version for the OpenAPI document
1821
document.Info.Title = "Todo API (ASP.NET Core OpenAPI)";
1922
document.Info.Description = "An API for managing Todo items.";
@@ -39,18 +42,16 @@ public static IServiceCollection AddAspNetCoreOpenApi(this IServiceCollection se
3942
Description = "Bearer authentication using a JWT.",
4043
Scheme = "bearer",
4144
Type = SecuritySchemeType.Http,
42-
Reference = new()
43-
{
44-
Id = "Bearer",
45-
Type = ReferenceType.SecurityScheme,
46-
},
4745
};
4846

47+
var referenceId = "Bearer";
48+
var reference = new OpenApiSecuritySchemeReference(referenceId, document);
49+
4950
document.Components ??= new();
50-
document.Components.SecuritySchemes ??= new Dictionary<string, OpenApiSecurityScheme>();
51-
document.Components.SecuritySchemes[scheme.Reference.Id] = scheme;
52-
document.SecurityRequirements ??= [];
53-
document.SecurityRequirements.Add(new() { [scheme] = [] });
51+
document.Components.SecuritySchemes ??= new Dictionary<string, IOpenApiSecurityScheme>();
52+
document.Components.SecuritySchemes[referenceId] = scheme;
53+
document.Security ??= [];
54+
document.Security.Add(new() { [reference] = [] });
5455

5556
return Task.CompletedTask;
5657
});

src/TodoApp/OpenApi/ExampleFormatter.cs

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

44
using System.Text.Json;
5+
using System.Text.Json.Nodes;
56
using System.Text.Json.Serialization;
6-
using Microsoft.OpenApi.Any;
77

88
namespace TodoApp.OpenApi;
99

@@ -19,9 +19,9 @@ internal static class ExampleFormatter
1919
/// <typeparam name="TProvider">The type of the example provider.</typeparam>
2020
/// <param name="context">The JSON serializer context to use.</param>
2121
/// <returns>
22-
/// The <see cref="IOpenApiAny"/> to use as the example.
22+
/// The <see cref="JsonNode"/> to use as the example.
2323
/// </returns>
24-
public static IOpenApiAny AsJson<TSchema, TProvider>(JsonSerializerContext context)
24+
public static JsonNode? AsJson<TSchema, TProvider>(JsonSerializerContext context)
2525
where TProvider : IExampleProvider<TSchema>
2626
=> AsJson(TProvider.GenerateExample(), context);
2727

@@ -32,87 +32,12 @@ public static IOpenApiAny AsJson<TSchema, TProvider>(JsonSerializerContext conte
3232
/// <param name="example">The example value to format as JSON.</param>
3333
/// <param name="context">The JSON serializer context to use.</param>
3434
/// <returns>
35-
/// The <see cref="IOpenApiAny"/> to use as the example.
35+
/// The <see cref="JsonNode"/> to use as the example.
3636
/// </returns>
37-
public static IOpenApiAny AsJson<T>(T example, JsonSerializerContext context)
37+
public static JsonNode? AsJson<T>(T example, JsonSerializerContext context)
3838
{
3939
// Apply any formatting rules configured for the API (e.g. camel casing)
4040
var json = JsonSerializer.Serialize(example, typeof(T), context);
41-
using var document = JsonDocument.Parse(json);
42-
43-
if (document.RootElement.ValueKind == JsonValueKind.String)
44-
{
45-
return new OpenApiString(document.RootElement.ToString());
46-
}
47-
48-
var result = new OpenApiObject();
49-
50-
// Recursively build up the example from the properties of the object
51-
foreach (var token in document.RootElement.EnumerateObject())
52-
{
53-
if (TryParse(token.Value, out var any))
54-
{
55-
result[token.Name] = any;
56-
}
57-
}
58-
59-
return result;
60-
}
61-
62-
private static bool TryParse(JsonElement token, out IOpenApiAny? any)
63-
{
64-
any = null;
65-
66-
switch (token.ValueKind)
67-
{
68-
case JsonValueKind.Array:
69-
var array = new OpenApiArray();
70-
71-
foreach (var value in token.EnumerateArray())
72-
{
73-
if (TryParse(value, out var child))
74-
{
75-
array.Add(child);
76-
}
77-
}
78-
79-
any = array;
80-
return true;
81-
82-
case JsonValueKind.False:
83-
any = new OpenApiBoolean(false);
84-
return true;
85-
86-
case JsonValueKind.True:
87-
any = new OpenApiBoolean(true);
88-
return true;
89-
90-
case JsonValueKind.Number:
91-
any = new OpenApiDouble(token.GetDouble());
92-
return true;
93-
94-
case JsonValueKind.String:
95-
any = new OpenApiString(token.GetString());
96-
return true;
97-
98-
case JsonValueKind.Object:
99-
var obj = new OpenApiObject();
100-
101-
foreach (var child in token.EnumerateObject())
102-
{
103-
if (TryParse(child.Value, out var value))
104-
{
105-
obj[child.Name] = value;
106-
}
107-
}
108-
109-
any = obj;
110-
return true;
111-
112-
case JsonValueKind.Null:
113-
case JsonValueKind.Undefined:
114-
default:
115-
return false;
116-
}
41+
return JsonNode.Parse(json);
11742
}
11843
}

src/TodoApp/OpenApi/ExamplesProcessor.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.AspNetCore.Mvc.ApiExplorer;
77
using Microsoft.AspNetCore.Mvc.ModelBinding;
8-
using Microsoft.OpenApi.Models;
8+
using Microsoft.OpenApi;
99

1010
namespace TodoApp.OpenApi;
1111

@@ -56,7 +56,7 @@ protected void Process(OpenApiSchema schema, Type type)
5656
}
5757

5858
private static void TryAddParameterExamples(
59-
IList<OpenApiParameter> parameters,
59+
IList<IOpenApiParameter> parameters,
6060
ApiDescription description,
6161
IList<IOpenApiExampleMetadata> examples)
6262
{
@@ -89,11 +89,14 @@ private static void TryAddParameterExamples(
8989
}
9090

9191
private static void TryAddRequestExamples(
92-
OpenApiRequestBody body,
92+
IOpenApiRequestBody body,
9393
ApiDescription description,
9494
IList<IOpenApiExampleMetadata> examples)
9595
{
96-
if (!body.Content.TryGetValue("application/json", out var mediaType) || mediaType.Example is not null)
96+
if (body is null ||
97+
body.Content is null ||
98+
!body.Content.TryGetValue("application/json", out var mediaType) ||
99+
mediaType.Example is not null)
97100
{
98101
return;
99102
}
@@ -130,7 +133,7 @@ private static void TryAddResponseExamples(
130133
foreach (var responseFormat in schemaResponse.ApiResponseFormats)
131134
{
132135
if (responses.TryGetValue(schemaResponse.StatusCode.ToString(CultureInfo.InvariantCulture), out var response) &&
133-
response.Content.TryGetValue(responseFormat.MediaType, out var mediaType))
136+
response.Content?.TryGetValue(responseFormat.MediaType, out var mediaType) is true)
134137
{
135138
mediaType.Example ??= (metadata ?? examples.SingleOrDefault((p) => p.SchemaType == schemaResponse.Type))?.GenerateExample(Context);
136139
}

src/TodoApp/OpenApi/IOpenApiExampleMetadata.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) Martin Costello, 2024. All rights reserved.
22
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
33

4+
using System.Text.Json.Nodes;
45
using System.Text.Json.Serialization;
5-
using Microsoft.OpenApi.Any;
66

77
namespace TodoApp.OpenApi;
88

@@ -29,7 +29,7 @@ public interface IOpenApiExampleMetadata
2929
/// </summary>
3030
/// <param name="context">The JSON serializer context to use to generate the example.</param>
3131
/// <returns>
32-
/// The OpenAPI example to use.
32+
/// The OpenAPI example to use, if any.
3333
/// </returns>
34-
IOpenApiAny GenerateExample(JsonSerializerContext context);
34+
JsonNode? GenerateExample(JsonSerializerContext context);
3535
}

0 commit comments

Comments
 (0)