Skip to content

Support .NET 10 #3283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 121 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
18458de
Support .NET 10
martincostello Mar 30, 2025
26d6b70
Fix test
martincostello Mar 30, 2025
f2cf1e5
Remove obsolete method
martincostello Mar 30, 2025
7011bbc
Update to ASP.NET Core 10 preview 2
martincostello Apr 2, 2025
032b1cb
Merge branch 'master' into dotnet-vnext
martincostello Apr 2, 2025
6637563
Merge branch 'master' into dotnet-vnext
martincostello Apr 2, 2025
f3728d0
Add TODO
martincostello Apr 2, 2025
f515b0b
Partially fix security requirement issue
martincostello Apr 3, 2025
b33f174
Fix test
martincostello Apr 3, 2025
2744775
Fix test
martincostello Apr 3, 2025
833b8c5
Fix type tests
martincostello Apr 3, 2025
8ae0a45
Fix missing descriptions
martincostello Apr 3, 2025
f4eb187
Refactor fix
martincostello Apr 3, 2025
4b7dc56
Merge branch 'master' into dotnet-vnext
martincostello Apr 6, 2025
ae594aa
Merge branch 'master' into dotnet-vnext
martincostello Apr 7, 2025
5b363fd
Fix package reference
martincostello Apr 7, 2025
fefa371
Fix xUnit1051 warnings
martincostello Apr 7, 2025
1b9a9f2
Merge branch 'master' into dotnet-vnext
martincostello Apr 8, 2025
e5bbb15
Merge branch 'master' into dotnet-vnext
martincostello Apr 10, 2025
e854705
Merge branch 'master' into dotnet-vnext
martincostello Apr 10, 2025
12d5cc8
Update to ASP.NET Core 10 preview 3 (#3361)
martincostello Apr 10, 2025
16ff516
Update NuGet packages
martincostello Apr 10, 2025
e59480c
Link to issue
martincostello Apr 11, 2025
0219d47
Fix typo
martincostello Apr 11, 2025
a0bf6d1
Fix tag serialization
martincostello Apr 12, 2025
2ac06c1
Merge branch 'master' into dotnet-vnext
martincostello Apr 14, 2025
3d5a1ce
Fix merge
martincostello Apr 14, 2025
a4fd764
Add issue reference
martincostello Apr 14, 2025
e4d7a34
Remove TODO
martincostello Apr 14, 2025
bb986ca
Fix formatting
martincostello Apr 14, 2025
dd0e1f7
Merge branch 'master' into dotnet-vnext
martincostello Apr 14, 2025
b873904
Merge branch 'master' into dotnet-vnext
martincostello Apr 23, 2025
5cdb231
Merge branch 'master' into dotnet-vnext
martincostello Apr 25, 2025
21acf10
Prepare for .NET 10 preview 4 (#3388)
martincostello Apr 29, 2025
ae180ee
Fix nullability for null schema Type
martincostello Apr 29, 2025
0cc8097
Re-enable MyGet
martincostello May 1, 2025
a12688c
Merge branch 'master' into dotnet-vnext
martincostello May 1, 2025
18f1466
Fix rebase
martincostello May 1, 2025
5b00492
Skip failing tets
martincostello May 1, 2025
90b940b
Update MyGet publish URL
martincostello May 1, 2025
43f208a
Re-disable MyGet publishing
martincostello May 1, 2025
2057457
Merge branch 'master' into dotnet-vnext
martincostello May 1, 2025
cce51db
Merge branch 'master' into dotnet-vnext
martincostello May 9, 2025
4d7db8e
Update to Microsoft.OpenApi 2.0.0 preview 17
martincostello Apr 29, 2025
d02ee7d
Fix API baselines
martincostello Apr 29, 2025
6e096dc
Skip failing tests
martincostello Apr 29, 2025
c5285f2
Use SerializeAs
martincostello Apr 29, 2025
989863b
Fix build
martincostello Apr 29, 2025
7cf5e82
Apply suggestions from code review
martincostello May 13, 2025
876741f
Fix build
martincostello May 15, 2025
966cc92
Disable failing tests
martincostello May 15, 2025
139e858
Fix MergeWith
martincostello May 15, 2025
91b6649
Publish packages
martincostello May 15, 2025
2645264
Merge branch 'master' into dotnet-vnext
martincostello May 15, 2025
d16dbd7
Fix tests
martincostello May 16, 2025
9c3bb78
Remove workaround
martincostello May 16, 2025
d6100d5
Merge branch 'master' into dotnet-vnext
martincostello May 16, 2025
0406f22
Re-enable tests
martincostello May 16, 2025
83d3a2b
Merge branch 'master' into dotnet-vnext
martincostello May 20, 2025
bde75c6
Merge branch 'master' into dotnet-vnext
martincostello May 20, 2025
c1f0749
Re-enable MyGet publishing
martincostello May 23, 2025
116b045
Merge branch 'master' into dotnet-vnext
martincostello May 23, 2025
cb0fb56
Merge branch 'master' into dotnet-vnext
martincostello May 23, 2025
a32f475
Merge branch 'master' into dotnet-vnext
martincostello Jun 1, 2025
b979c15
Apply review suggestions
martincostello Jun 1, 2025
a2e4986
Workaround VS issue
martincostello Jun 1, 2025
5a0d266
Fix culture-insensitive handling of numbers with [Range] (#3426)
bkoelman Jun 1, 2025
9e17d0b
Merge branch 'master' into dotnet-vnext
martincostello Jun 1, 2025
ec4d970
Refactor method
martincostello Jun 1, 2025
9e6dedf
Fix range parsing
martincostello Jun 1, 2025
f5b2e11
Sort AnyOf and OneOf
martincostello Jun 1, 2025
22652de
Merge branch 'master' into dotnet-vnext
martincostello Jun 1, 2025
6c30f2c
Update issue number
martincostello Jun 1, 2025
62a266e
Merge branch 'master' into dotnet-vnext
martincostello Jun 3, 2025
3f8f0a7
Merge branch 'master' into dotnet-vnext
martincostello Jun 4, 2025
07f125a
Merge branch 'master' into dotnet-vnext
martincostello Jun 4, 2025
2a48fa2
Merge branch 'master' into dotnet-vnext
martincostello Jun 5, 2025
529a324
Refactor [Range] handling
martincostello Jun 5, 2025
6c17312
Add test cases for `[Range]`
martincostello Jun 6, 2025
dd8b516
Refactor method to avoid round-trip
martincostello Jun 6, 2025
24f5cd2
Tweak comment
martincostello Jun 6, 2025
619465e
Fix comment
martincostello Jun 6, 2025
6009837
Fix conversion
martincostello Jun 6, 2025
80a519b
Merge branch 'master' into dotnet-vnext
martincostello Jun 6, 2025
5015ee3
Merge branch 'master' into dotnet-vnext
martincostello Jun 6, 2025
98247b3
Merge branch 'master' into dotnet-vnext
martincostello Jun 7, 2025
3ecf154
Update snapshot
martincostello Jun 7, 2025
675a1c1
Update .NET SDK to 10.0.100-preview.5.25277.114 (#3451)
github-actions[bot] Jun 10, 2025
9564222
Bump Microsoft.OpenApi
martincostello Jun 10, 2025
28bca91
Fix build
martincostello Jun 10, 2025
3123fe1
Fix line endings
martincostello Jun 10, 2025
c3b594e
Merge branch 'master' into dotnet-vnext
martincostello Jun 11, 2025
ed9499c
Validate TypedResults is supported for ASP.NET Core 10 (#3455)
jgarciadelanoceda Jun 12, 2025
3c96b7d
Support [ProducesResponseType], [Produces], and [ProducesDefaultRespo…
jgarciadelanoceda Jun 13, 2025
df4712f
Merge branch 'master' into dotnet-vnext
martincostello Jun 13, 2025
c800e7c
Remove workarounds
martincostello Jun 13, 2025
da8103e
Apply suggestions from code review
martincostello Jun 13, 2025
4b1799a
Merge branch 'master' into dotnet-vnext
martincostello Jun 13, 2025
bba77f5
Fix build
martincostello Jun 13, 2025
57f9e26
Merge branch 'master' into dotnet-vnext
martincostello Jun 13, 2025
45fcad8
Fix package version
martincostello Jun 13, 2025
eb96005
Update PublicAPI baselines
martincostello Jun 13, 2025
08c3a6a
Merge branch 'master' into dotnet-vnext
martincostello Jun 14, 2025
12836cb
Merge branch 'master' into dotnet-vnext
martincostello Jul 7, 2025
fb14623
Update _SdkTasksTFM
martincostello Jul 7, 2025
3b15eda
Merge branch 'master' into dotnet-vnext
martincostello Jul 8, 2025
7cd4979
Merge branch 'master' into dotnet-vnext
martincostello Jul 8, 2025
807b811
Merge branch 'master' into dotnet-vnext
martincostello Jul 8, 2025
cdfe74a
Merge branch 'master' into dotnet-vnext
martincostello Jul 8, 2025
c8e5aef
Merge branch 'master' into dotnet-vnext
martincostello Jul 9, 2025
c2bb204
Update to ASP.NET Core 10 preview.6 (#3479)
martincostello Jul 15, 2025
dce8eef
Update Microsoft.OpenApi to 2.0.0
martincostello Jul 15, 2025
440bfbb
Merge branch 'master' into dotnet-vnext
martincostello Jul 18, 2025
32aa034
Remove WithOpenApi usage
martincostello Jul 18, 2025
30b1f06
Merge branch 'master' into dotnet-vnext
martincostello Jul 23, 2025
041171b
Merge branch 'master' into dotnet-vnext
martincostello Jul 24, 2025
c358213
Remove redundant references
martincostello Jul 24, 2025
96d68e9
Add UI tests for SwaggerUI and Redoc
martincostello Jul 29, 2025
a1aea94
Merge branch 'master' into dotnet-vnext
martincostello Jul 29, 2025
9eff208
Merge branch 'master' into dotnet-vnext
martincostello Aug 7, 2025
3d2aaec
Update allowed licenses
martincostello Aug 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
84 changes: 42 additions & 42 deletions .github/workflows/ossf-scorecard.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
name: ossf-scorecard
on:
push:
branches: [ master ]
schedule:
- cron: '0 8 * * MON'
workflow_dispatch:
permissions: read-all
jobs:
analysis:
name: analysis
runs-on: ubuntu-latest
permissions:
id-token: write
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Run analysis
name: ossf-scorecard

on:
push:
branches: [ master ]
schedule:
- cron: '0 8 * * MON'
workflow_dispatch:

permissions: read-all

jobs:
analysis:
name: analysis
runs-on: ubuntu-latest

permissions:
id-token: write
security-events: write

steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: Run analysis
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
with:
publish_results: true
results_file: results.sarif
results_format: sarif
- name: Upload artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: SARIF
path: results.sarif
retention-days: 5
- name: Upload to code-scanning
with:
publish_results: true
results_file: results.sarif
results_format: sarif

- name: Upload artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: SARIF
path: results.sarif
retention-days: 5

- name: Upload to code-scanning
uses: github/codeql-action/upload-sarif@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19
with:
sarif_file: results.sarif
with:
sarif_file: results.sarif
10 changes: 9 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
TODO Fix warning from Swashbuckle.AspNetCore with dotnet pack
-->
<NoWarn>$(NoWarn);NU5128</NoWarn>
<!-- TODO Remove once .NET 10 is stable -->
<NoWarn>$(NoWarn);NU5104</NoWarn>
<NuGetAuditMode>direct</NuGetAuditMode>
<!--
TODO Go through the code and add nullable annotations
Expand All @@ -40,7 +42,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseArtifactsOutput>true</UseArtifactsOutput>
<VersionPrefix>8.1.5</VersionPrefix>
<VersionPrefix>9.0.0</VersionPrefix>
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
</PropertyGroup>
<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' != '' AND '$(DEPENDABOT_JOB_ID)' == '' ">
Expand All @@ -67,4 +69,10 @@
<Include>[Swashbuckle.*]*</Include>
<Threshold></Threshold>
</PropertyGroup>
<!-- HACK Workaround for https://github.com/dotnet/sdk/issues/48391 -->
<ItemGroup>
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-8g4q-xg66-9fp4" />
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-hh2w-p6rv-4g7w" />
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-5crp-9r3c-p9vr" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.32" />
<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.OpenApi" Version="8.0.16" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0-preview.4.25258.110" />
<PackageVersion Include="Microsoft.AspNetCore.Razor.Design" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Routing" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.StaticFiles" Version="2.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.32" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="4.14.0" />
<PackageVersion Include="Microsoft.Extensions.FileProviders.Embedded" Version="2.1.1" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.23" />
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="1.6.23" />
<PackageVersion Include="Microsoft.OpenApi" Version="2.0.0-preview.17" />
<PackageVersion Include="Microsoft.OpenApi.YamlReader" Version="2.0.0-preview.17" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="NSwag.MSBuild" Version="14.4.0" />
<PackageVersion Include="ReportGenerator" Version="5.4.7" />
<PackageVersion Include="System.Text.Json" Version="4.6.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.0" />
<PackageVersion Include="Verify.XunitV3" Version="30.3.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.0" />
Expand Down
2 changes: 1 addition & 1 deletion docs/configure-and-customize-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class Product
```csharp
public class ProductSchemaFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
{
schema.Example = new OpenApiObject
{
Expand Down
5 changes: 3 additions & 2 deletions docs/configure-and-customize-swaggergen.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,12 @@ to inform the AutoRest tool how enums should be modelled when it generates the A
```csharp
public class AutoRestSchemaFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
{
var type = context.Type;
if (type.IsEnum)
{
schema.Extensions ??= [];
schema.Extensions.Add(
"x-ms-enum",
new OpenApiObject
Expand Down Expand Up @@ -708,7 +709,7 @@ so you will need [a special JsonConverter, as shown in the .NET documentation](h
```csharp
public class DictionaryTKeyEnumTValueSchemaFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
{
// Only run for fields that are a Dictionary<Enum, TValue>
if (!context.Type.IsGenericType || !context.Type.GetGenericTypeDefinition().IsAssignableFrom(typeof(Dictionary<,>)))
Expand Down
5 changes: 3 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"sdk": {
"version": "9.0.300",
"version": "10.0.100-preview.4.25258.110",
"allowPrerelease": false,
"rollForward": "latestMajor"
"rollForward": "latestMajor",
"paths": [ ".dotnet", "$host$" ]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)..\..\src\Swashbuckle.AspNetCore.Swagger\Swashbuckle.AspNetCore.Swagger.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down
21 changes: 12 additions & 9 deletions perf/Swashbuckle.AspNetCore.Benchmarks/XmlCommentsBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public void Setup()
using var xmlStream = new MemoryStream();
xmlDocument.Save(xmlStream);
xmlStream.Seek(0, SeekOrigin.Begin);

var xPathDocument = new XPathDocument(xmlStream);
var members = XmlCommentsDocumentHelper.CreateMemberDictionary(xPathDocument);

// Document
_document = new OpenApiDocument();
Expand All @@ -83,21 +85,21 @@ public void Setup()
null,
null);

_documentFilter = new XmlCommentsDocumentFilter(xPathDocument);
_documentFilter = new XmlCommentsDocumentFilter(members, new());

// Operation
_operation = new OpenApiOperation();
var methodInfo = typeof(FakeConstructedControllerWithXmlComments)
.GetMethod(nameof(FakeConstructedControllerWithXmlComments.ActionWithSummaryAndResponseTags));

var apiDescription = ApiDescriptionFactory.Create(methodInfo: methodInfo, groupName: "v1", httpMethod: "POST", relativePath: "resource");
_operationFilterContext = new OperationFilterContext(apiDescription, null, null, methodInfo);
_operationFilter = new XmlCommentsOperationFilter(xPathDocument);
_operationFilterContext = new OperationFilterContext(apiDescription, null, null, null, methodInfo);
_operationFilter = new XmlCommentsOperationFilter(members, new());

// Parameter
_parameter = new()
{
Schema = new()
Schema = new OpenApiSchema()
{
Type = JsonSchemaTypes.String,
Description = "schema-level description",
Expand All @@ -106,8 +108,9 @@ public void Setup()

var propertyInfo = typeof(XmlAnnotatedType).GetProperty(nameof(XmlAnnotatedType.StringProperty));
var apiParameterDescription = new ApiParameterDescription();
_parameterFilterContext = new ParameterFilterContext(apiParameterDescription, null, null, propertyInfo: propertyInfo);
_parameterFilter = new XmlCommentsParameterFilter(xPathDocument);
var xmlDocMembers = XmlCommentsDocumentHelper.CreateMemberDictionary(xPathDocument);
_parameterFilterContext = new ParameterFilterContext(apiParameterDescription, null, null, null, propertyInfo: propertyInfo);
_parameterFilter = new XmlCommentsParameterFilter(xmlDocMembers, new());

// Request Body
_requestBody = new OpenApiRequestBody
Expand All @@ -116,7 +119,7 @@ public void Setup()
{
["application/json"] = new()
{
Schema = new()
Schema = new OpenApiSchema()
{
Type = JsonSchemaTypes.String,
},
Expand All @@ -131,8 +134,8 @@ public void Setup()
{
ParameterDescriptor = new ControllerParameterDescriptor { ParameterInfo = parameterInfo }
};
_requestBodyFilterContext = new RequestBodyFilterContext(bodyParameterDescription, null, null, null);
_requestBodyFilter = new XmlCommentsRequestBodyFilter(xPathDocument);
_requestBodyFilterContext = new RequestBodyFilterContext(bodyParameterDescription, null, null, null, null);
_requestBodyFilter = new XmlCommentsRequestBodyFilter(xmlDocMembers, new());
}

[Benchmark]
Expand Down
26 changes: 26 additions & 0 deletions src/Shared/JsonExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Text.Json;
using System.Text.Json.Nodes;

namespace Swashbuckle.AspNetCore;

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)
{
var json = value.ToJsonString(Options);

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

return json;
}
}
16 changes: 9 additions & 7 deletions src/Shared/JsonSchemaTypes.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Microsoft.OpenApi.Models;

namespace Swashbuckle.AspNetCore;

internal static class JsonSchemaTypes
{
public const string Array = "array";
public const string Boolean = "boolean";
public const string Integer = "integer";
public const string Number = "number";
public const string Null = "null";
public const string Object = "object";
public const string String = "string";
public static readonly JsonSchemaType Array = JsonSchemaType.Array;
public static readonly JsonSchemaType Boolean = JsonSchemaType.Boolean;
public static readonly JsonSchemaType Integer = JsonSchemaType.Integer;
public static readonly JsonSchemaType Number = JsonSchemaType.Number;
public static readonly JsonSchemaType Null = JsonSchemaType.Null;
public static readonly JsonSchemaType Object = JsonSchemaType.Object;
public static readonly JsonSchemaType String = JsonSchemaType.String;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,32 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
}

private static void ApplySwaggerTagAttribute(
OpenApiDocument swaggerDoc,
OpenApiDocument document,
string controllerName,
IEnumerable<object> customAttributes)
{
var swaggerTagAttribute = customAttributes
.OfType<SwaggerTagAttribute>()
.FirstOrDefault();

if (swaggerTagAttribute == null)
if (swaggerTagAttribute is null)
{
return;
}

swaggerDoc.Tags.Add(new OpenApiTag
var tag = document.Tags.FirstOrDefault((p) => p?.Name == controllerName);

if (tag is null)
{
tag = new() { Name = controllerName };
document.Tags.Add(tag);
}

tag.Description ??= swaggerTagAttribute.Description;

if (swaggerTagAttribute.ExternalDocsUrl is { } url)
{
Name = controllerName,
Description = swaggerTagAttribute.Description,
ExternalDocs = (swaggerTagAttribute.ExternalDocsUrl != null)
? new OpenApiExternalDocs { Url = new Uri(swaggerTagAttribute.ExternalDocsUrl) }
: null
});
tag.ExternalDocs ??= new OpenApiExternalDocs { Url = new(url) };
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.References;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace Swashbuckle.AspNetCore.Annotations;
Expand Down Expand Up @@ -71,7 +72,7 @@ private static void ApplySwaggerOperationAttribute(

if (swaggerOperationAttribute.Tags is { } tags)
{
operation.Tags = [.. tags.Select(tagName => new OpenApiTag { Name = tagName })];
operation.Tags = [.. tags.Select(tagName => new OpenApiTagReference(tagName))];
}
}

Expand Down Expand Up @@ -115,17 +116,19 @@ private static void ApplySwaggerResponseAttributes(

operation.Responses[statusCode] = response;

if (swaggerResponseAttribute.ContentTypes is { } contentTypes)
if (response is OpenApiResponse concrete &&
swaggerResponseAttribute.ContentTypes is { } contentTypes)
{
response.Content.Clear();
concrete.Content?.Clear();
concrete.Content ??= [];

foreach (var contentType in contentTypes)
{
var schema = (swaggerResponseAttribute.Type != null && swaggerResponseAttribute.Type != typeof(void))
? context.SchemaGenerator.GenerateSchema(swaggerResponseAttribute.Type, context.SchemaRepository)
: null;

response.Content.Add(contentType, new OpenApiMediaType { Schema = schema });
concrete.Content.Add(contentType, new OpenApiMediaType { Schema = schema });
}
}
}
Expand Down
Loading
Loading