Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 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
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ jobs:
uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.0
with:
dotnet-version: |
Comment thread
martincostello marked this conversation as resolved.
8.0.x
9.0.x
10.0.x

- name: Setup Node
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
Expand Down
7 changes: 5 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Company>https://github.com/domaindrivendev/Swashbuckle.AspNetCore</Company>
<ContinuousIntegrationBuild Condition=" '$(CI)' != '' ">true</ContinuousIntegrationBuild>
<Copyright>Copyright (c) 2016-$([System.DateTime]::Now.ToString(yyyy)) Richard Morris</Copyright>
<DefaultTargetFrameworks>net10.0;net9.0;net8.0</DefaultTargetFrameworks>
<DefaultTargetFrameworks>net11.0;net10.0</DefaultTargetFrameworks>
<Deterministic>true</Deterministic>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<EnablePackageValidation>$(IsPackable)</EnablePackageValidation>
Expand All @@ -18,6 +18,8 @@
<LangVersion>latest</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<NeutralLanguage>en-US</NeutralLanguage>
<!-- TODO Remove before merge -->
<NoWarn>$(NoWarn);NU5104</NoWarn>
<NuGetAuditMode>direct</NuGetAuditMode>
<!--
TODO Go through the code and add nullable annotations
Expand All @@ -35,9 +37,10 @@
<RepositoryUrl>$(PackageProjectUrl).git</RepositoryUrl>
<StaticWebAssetsEnabled>false</StaticWebAssetsEnabled>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TestTfmsInParallel>false</TestTfmsInParallel>
Comment thread
martincostello marked this conversation as resolved.
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseArtifactsOutput>true</UseArtifactsOutput>
<VersionPrefix>10.1.6</VersionPrefix>
<VersionPrefix>11.0.0</VersionPrefix>
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
</PropertyGroup>
<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' != '' AND '$(DEPENDABOT_JOB_ID)' == '' ">
Expand Down
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
<PackageVersion Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageVersion Include="JunitXml.TestLogger" Version="8.0.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit.v3" Version="0.7.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.25" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.25" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.1.0" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.25" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="10.0.4" />
<PackageVersion Include="Microsoft.Build" Version="18.4.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="4.14.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="11.0.0-preview.2.26159.112" />
<PackageVersion Include="Microsoft.Kiota.Bundle" Version="1.22.0" />
<PackageVersion Include="Microsoft.OpenApi" Version="2.7.0" />
<PackageVersion Include="Microsoft.OpenApi.YamlReader" Version="2.7.0" />
<PackageVersion Include="Microsoft.OpenApi" Version="3.4.0" />
<PackageVersion Include="Microsoft.OpenApi.YamlReader" Version="3.4.0" />
<PackageVersion Include="Microsoft.Playwright" Version="1.58.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageVersion Include="MSBuild.ProjectCreation" Version="17.0.1" />
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Once you have an API that can describe itself with a OpenAPI document, you've op
tools including a client generator that can be targeted to a wide range of popular platforms. See [swagger-codegen][swagger-codegen]
for more details.

<!-- TODO Updates for ASP.NET Core 11 -->
<!-- TODO Migration Guide and docs for ASP.NET Core 11 -->

> [!IMPORTANT]
> Version 10.0 of Swashbuckle.AspNetCore introduces breaking changes due to upgrading our dependency on [Microsoft.OpenApi][microsoft-openapi]
> to version 2.x.x to add support for generating OpenAPI 3.1 documents. Please see _[Migrating to Swashbuckle.AspNetCore v10][v10-migration]_ for more details.
Expand Down
2 changes: 1 addition & 1 deletion benchmark.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#Requires -Version 7

param(
[Parameter(Mandatory = $false)][string] $Framework = "net10.0",
[Parameter(Mandatory = $false)][string] $Framework = "net11.0",
[Parameter(Mandatory = $false)][string] $Job = ""
)

Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "10.0.200",
"version": "11.0.100-preview.2.26159.112",
"allowPrerelease": false,
"rollForward": "latestMajor",
"paths": [ ".dotnet", "$host$" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>net11.0</TargetFramework>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)..\..\src\Swashbuckle.AspNetCore.Swagger\Swashbuckle.AspNetCore.Swagger.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ public void Setup()
// Request Body
_requestBody = new OpenApiRequestBody
{
Content = new Dictionary<string, OpenApiMediaType>()
#if NET11_0_OR_GREATER
Content = new Dictionary<string, IOpenApiMediaType>
#else
Content = new Dictionary<string, OpenApiMediaType>
#endif
{
["application/json"] = new OpenApiMediaType()
{
Expand Down
16 changes: 1 addition & 15 deletions src/Shared/JsonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,10 @@ internal static class JsonExtensions
{
private static readonly JsonSerializerOptions Options = new()
{
#if NET9_0_OR_GREATER
NewLine = "\n",
#endif
WriteIndented = true,
};

public static string ToJson(this JsonNode value)
{
if (value.IsJsonNullSentinel())
{
return "null";
}
var json = value.ToJsonString(Options);

#if !NET9_0_OR_GREATER
json = json.Replace("\r\n", "\n");
#endif

return json;
}
=> value.IsJsonNullSentinel() ? "null" : value.ToJsonString(Options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ private static void ApplySwaggerResponseAttributes(
swaggerResponseAttribute.ContentTypes is { } contentTypes)
{
concrete.Content?.Clear();
#if NET11_0_OR_GREATER
concrete.Content ??= new Dictionary<string, IOpenApiMediaType>();
#else
concrete.Content ??= new Dictionary<string, OpenApiMediaType>();
#endif

foreach (var contentType in contentTypes)
{
Expand Down

This file was deleted.

This file was deleted.

4 changes: 4 additions & 0 deletions src/Swashbuckle.AspNetCore.ApiTesting/IContentValidator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Microsoft.OpenApi;

#if NET11_0_OR_GREATER
using OpenApiMediaType = Microsoft.OpenApi.IOpenApiMediaType;
#endif

namespace Swashbuckle.AspNetCore.ApiTesting;

public interface IContentValidator
Expand Down
4 changes: 4 additions & 0 deletions src/Swashbuckle.AspNetCore.ApiTesting/JsonContentValidator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using Microsoft.OpenApi;
using Newtonsoft.Json.Linq;

#if NET11_0_OR_GREATER
using OpenApiMediaType = Microsoft.OpenApi.IOpenApiMediaType;
#endif

namespace Swashbuckle.AspNetCore.ApiTesting;

public sealed class JsonContentValidator : IContentValidator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Swashbuckle.AspNetCore.ApiTesting.ContentDoesNotMatchSpecException.ContentDoesNo
Swashbuckle.AspNetCore.ApiTesting.HttpHeadersExtensions
Swashbuckle.AspNetCore.ApiTesting.IContentValidator
Swashbuckle.AspNetCore.ApiTesting.IContentValidator.CanValidate(string mediaType) -> bool
Swashbuckle.AspNetCore.ApiTesting.IContentValidator.Validate(Microsoft.OpenApi.OpenApiMediaType mediaTypeSpec, Microsoft.OpenApi.OpenApiDocument openApiDocument, System.Net.Http.HttpContent content) -> void
Swashbuckle.AspNetCore.ApiTesting.IJsonValidator
Swashbuckle.AspNetCore.ApiTesting.IJsonValidator.CanValidate(Microsoft.OpenApi.IOpenApiSchema schema) -> bool
Swashbuckle.AspNetCore.ApiTesting.IJsonValidator.Validate(Microsoft.OpenApi.IOpenApiSchema schema, Microsoft.OpenApi.OpenApiDocument openApiDocument, Newtonsoft.Json.Linq.JToken instance, out System.Collections.Generic.IEnumerable<string> errorMessages) -> bool
Expand All @@ -44,7 +43,6 @@ Swashbuckle.AspNetCore.ApiTesting.JsonBooleanValidator.Validate(Microsoft.OpenAp
Swashbuckle.AspNetCore.ApiTesting.JsonContentValidator
Swashbuckle.AspNetCore.ApiTesting.JsonContentValidator.CanValidate(string mediaType) -> bool
Swashbuckle.AspNetCore.ApiTesting.JsonContentValidator.JsonContentValidator() -> void
Swashbuckle.AspNetCore.ApiTesting.JsonContentValidator.Validate(Microsoft.OpenApi.OpenApiMediaType mediaTypeSpec, Microsoft.OpenApi.OpenApiDocument openApiDocument, System.Net.Http.HttpContent content) -> void
Swashbuckle.AspNetCore.ApiTesting.JsonNullValidator
Swashbuckle.AspNetCore.ApiTesting.JsonNullValidator.CanValidate(Microsoft.OpenApi.IOpenApiSchema schema) -> bool
Swashbuckle.AspNetCore.ApiTesting.JsonNullValidator.JsonNullValidator() -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Swashbuckle.AspNetCore.ApiTesting.IContentValidator.Validate(Microsoft.OpenApi.OpenApiMediaType mediaTypeSpec, Microsoft.OpenApi.OpenApiDocument openApiDocument, System.Net.Http.HttpContent content) -> void
Swashbuckle.AspNetCore.ApiTesting.JsonContentValidator.Validate(Microsoft.OpenApi.OpenApiMediaType mediaTypeSpec, Microsoft.OpenApi.OpenApiDocument openApiDocument, System.Net.Http.HttpContent content) -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Swashbuckle.AspNetCore.ApiTesting.IContentValidator.Validate(Microsoft.OpenApi.IOpenApiMediaType mediaTypeSpec, Microsoft.OpenApi.OpenApiDocument openApiDocument, System.Net.Http.HttpContent content) -> void
Swashbuckle.AspNetCore.ApiTesting.JsonContentValidator.Validate(Microsoft.OpenApi.IOpenApiMediaType mediaTypeSpec, Microsoft.OpenApi.OpenApiDocument openApiDocument, System.Net.Http.HttpContent content) -> void
4 changes: 4 additions & 0 deletions src/Swashbuckle.AspNetCore.ApiTesting/ResponseValidator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Collections.Specialized;
using Microsoft.OpenApi;

#if NET11_0_OR_GREATER
using OpenApiMediaType = Microsoft.OpenApi.IOpenApiMediaType;
#endif

namespace Swashbuckle.AspNetCore.ApiTesting;

public sealed class ResponseValidator(IEnumerable<IContentValidator> contentValidators)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,28 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.OpenApi" VersionOverride="2.4.1" />
<PackageReference Include="Microsoft.OpenApi" VersionOverride="2.7.0" />
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" VersionOverride="8.0.5" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" VersionOverride="9.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" VersionOverride="10.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net11.0' ">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" VersionOverride="11.0.0-preview.2.26159.112" />
<PackageReference Update="Microsoft.OpenApi" VersionOverride="3.4.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
<AdditionalFiles Include="PublicAPI\PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI\PublicAPI.Unshipped.txt" />
</ItemGroup>
<ItemGroup Condition="Exists('PublicAPI\$(TargetFramework)')">
<AdditionalFiles Include="PublicAPI\$(TargetFramework)\PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI\$(TargetFramework)\PublicAPI.Unshipped.txt" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Shared\JsonSchemaTypes.cs" Link="JsonSchemaTypes.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@
<ProjectReference Include="..\Swashbuckle.AspNetCore.SwaggerGen\Swashbuckle.AspNetCore.SwaggerGen.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" VersionOverride="8.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" VersionOverride="9.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" VersionOverride="10.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net11.0' ">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" VersionOverride="11.0.0-preview.2.26159.112" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
<AdditionalFiles Include="PublicAPI\PublicAPI.Shipped.txt" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

<!-- Embed compressed file using SDK task-->
<PropertyGroup>
<_SdkTasksTFM Condition=" '$(MSBuildRuntimeType)' == 'Core'">net10.0</_SdkTasksTFM>
<_SdkTasksTFM Condition=" '$(MSBuildRuntimeType)' == 'Core'">net11.0</_SdkTasksTFM>
<_SdkTasksTFM Condition=" '$(MSBuildRuntimeType)' != 'Core'">net472</_SdkTasksTFM>
</PropertyGroup>
<UsingTask TaskName="Microsoft.NET.Sdk.BlazorWebAssembly.GzipCompress" AssemblyFile="$(MicrosoftNETBuildTasksDirectoryRoot)../../Microsoft.NET.Sdk.BlazorWebAssembly/tools/$(_SdkTasksTFM)/Microsoft.NET.Sdk.BlazorWebAssembly.Tasks.dll" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.OpenApi" VersionOverride="2.4.1" />
<PackageReference Include="Microsoft.OpenApi" VersionOverride="2.7.0" />
Comment thread
martincostello marked this conversation as resolved.
Outdated
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net11.0' ">
<PackageReference Update="Microsoft.OpenApi" VersionOverride="3.4.0" />
Comment thread
martincostello marked this conversation as resolved.
Outdated
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ internal static bool IsFromForm(this ApiParameterDescription apiParameter)
{
bool isEnhancedModelMetadataSupported = true;

#if NET9_0_OR_GREATER
if (AppContext.TryGetSwitch("Microsoft.AspNetCore.Mvc.ApiExplorer.IsEnhancedModelMetadataSupported", out var isEnabled))
{
isEnhancedModelMetadataSupported = isEnabled;
}
#endif

var source = apiParameter.Source;
var elementType = isEnhancedModelMetadataSupported ? apiParameter.ModelMetadata?.ElementType : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,11 @@ private OpenApiRequestBody GenerateRequestBodyFromBodyParameter(
(contentType) => new OpenApiMediaType
{
Schema = schema
}),
}
#if NET11_0_OR_GREATER
as IOpenApiMediaType
#endif
),
};
}

Expand Down Expand Up @@ -909,7 +913,11 @@ private OpenApiRequestBody GenerateRequestBodyFromFormParameters(
(entry) => entry.Key,
(entry) => new OpenApiEncoding { Style = ParameterStyle.Form }
) ?? []
})
}
#if NET11_0_OR_GREATER
as IOpenApiMediaType
#endif
)
};
}

Expand Down Expand Up @@ -1013,11 +1021,7 @@ private OpenApiResponse GenerateResponse(
string statusCode,
ApiResponseType apiResponseType)
{
string description = null;

#if NET10_0_OR_GREATER
description = apiResponseType.Description;
#endif
string description = apiResponseType.Description;

if (string.IsNullOrEmpty(description))
{
Expand Down Expand Up @@ -1063,7 +1067,13 @@ private static IEnumerable<string> InferResponseContentTypes(ApiDescription apiD
.Distinct()];
}

private OpenApiMediaType CreateResponseMediaType(Type modelType, SchemaRepository schemaRepository)
private
#if NET11_0_OR_GREATER
IOpenApiMediaType
#else
OpenApiMediaType
#endif
CreateResponseMediaType(Type modelType, SchemaRepository schemaRepository)
{
return new OpenApiMediaType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

<!-- Embed compressed files using SDK task -->
<PropertyGroup>
<_SdkTasksTFM Condition=" '$(MSBuildRuntimeType)' == 'Core'">net10.0</_SdkTasksTFM>
<_SdkTasksTFM Condition=" '$(MSBuildRuntimeType)' == 'Core'">net11.0</_SdkTasksTFM>
<_SdkTasksTFM Condition=" '$(MSBuildRuntimeType)' != 'Core'">net472</_SdkTasksTFM>
</PropertyGroup>

Expand Down
Loading
Loading