Skip to content

Commit

Permalink
Fixes an issue where single file AOT .NET 8 project does not start if…
Browse files Browse the repository at this point in the history
… swagger is registered
  • Loading branch information
Havunen committed Feb 19, 2024
1 parent fa8fab8 commit 8712c23
Show file tree
Hide file tree
Showing 17 changed files with 301 additions and 42 deletions.
15 changes: 15 additions & 0 deletions DotSwashbuckle.AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinimalAppWithHostedService
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotSwashbuckleTestBug2679", "test\WebSites\DotSwashbuckleTestBug2679\DotSwashbuckleTestBug2679.csproj", "{52B31980-FA1B-46CF-B017-B8CE3F61C7A3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication1", "test\WebSites\WebApplication1\WebApplication1.csproj", "{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -615,6 +617,18 @@ Global
{52B31980-FA1B-46CF-B017-B8CE3F61C7A3}.Release|x64.Build.0 = Release|Any CPU
{52B31980-FA1B-46CF-B017-B8CE3F61C7A3}.Release|x86.ActiveCfg = Release|Any CPU
{52B31980-FA1B-46CF-B017-B8CE3F61C7A3}.Release|x86.Build.0 = Release|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Debug|x64.ActiveCfg = Debug|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Debug|x64.Build.0 = Debug|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Debug|x86.ActiveCfg = Debug|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Debug|x86.Build.0 = Debug|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Release|Any CPU.Build.0 = Release|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Release|x64.ActiveCfg = Release|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Release|x64.Build.0 = Release|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Release|x86.ActiveCfg = Release|Any CPU
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -662,6 +676,7 @@ Global
{570CE160-C749-429C-A499-7126DC5B15F6} = {15A55F4A-FC33-4D96-BAAD-FBDCDD96D5F5}
{C760F65B-5214-4104-99B2-3671D93F6FE2} = {DB3F57FC-1472-4F03-B551-43394DA3C5EB}
{52B31980-FA1B-46CF-B017-B8CE3F61C7A3} = {DB3F57FC-1472-4F03-B551-43394DA3C5EB}
{89F2F89F-C7E6-4C4E-BA3F-CC9EBDB4A0CA} = {DB3F57FC-1472-4F03-B551-43394DA3C5EB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {36FC6A67-247D-4149-8EDD-79FFD1A75F51}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.OpenApi.Models;
using DotSwashbuckle.AspNetCore.Swagger;
using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.Extensions.Options;

namespace DotSwashbuckle.AspNetCore.SwaggerGen
{
Expand All @@ -22,20 +23,20 @@ public class SwaggerGenerator : ISwaggerProvider, IAsyncSwaggerProvider
private readonly IAuthenticationSchemeProvider _authenticationSchemeProvider;

public SwaggerGenerator(
SwaggerGeneratorOptions options,
IOptions<SwaggerGeneratorOptions> generatorOptions,
IApiDescriptionGroupCollectionProvider apiDescriptionsProvider,
ISchemaGenerator schemaGenerator)
{
_options = options ?? new SwaggerGeneratorOptions();
_options = generatorOptions.Value;
_apiDescriptionsProvider = apiDescriptionsProvider;
_schemaGenerator = schemaGenerator;
}

public SwaggerGenerator(
SwaggerGeneratorOptions options,
IOptions<SwaggerGeneratorOptions> generatorOptions,
IApiDescriptionGroupCollectionProvider apiDescriptionsProvider,
ISchemaGenerator schemaGenerator,
IAuthenticationSchemeProvider authenticationSchemeProvider) : this(options, apiDescriptionsProvider, schemaGenerator)
IAuthenticationSchemeProvider authenticationSchemeProvider) : this(generatorOptions, apiDescriptionsProvider, schemaGenerator)
{
_authenticationSchemeProvider = authenticationSchemeProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
using Microsoft.OpenApi.Models;
using System;
using DotSwashbuckle.AspNetCore.SwaggerGen.XmlComments;
using Microsoft.Extensions.Options;

namespace DotSwashbuckle.AspNetCore.SwaggerGen
{
public class XmlCommentsDocumentFilter(
SwaggerGeneratorOptions options,
IOptions<SwaggerGeneratorOptions> generatorOptions,
IReadOnlyDictionary<string, XmlCommentDescriptor> xmlMemberDescriptors
) : IDocumentFilter
{
Expand All @@ -18,7 +19,7 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
// Collect (unique) controller names and types in a dictionary
var controllerNamesAndTypes = context.ApiDescriptions
.Where(apiDesc => apiDesc.ActionDescriptor is ControllerActionDescriptor)
.GroupBy(apiDesc => options.TagsSelector(apiDesc).FirstOrDefault())
.GroupBy(apiDesc => generatorOptions.Value.TagsSelector(apiDesc).FirstOrDefault())
.Select(group => new KeyValuePair<string, Type>(group.Key, ((ControllerActionDescriptor)group.First().ActionDescriptor).ControllerTypeInfo.AsType()));

foreach (var nameAndType in controllerNamesAndTypes)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc;

/// <summary>
/// Highly contrived example to show how Swashbuckle doesn't pull in XML Doc comments
/// when referenced via the `include` tag.
/// </summary>
/// <remarks>
/// Has 2 methods - one that has the docs inline,
/// and one that has the docs referenced in a separate file.
/// </remarks>
[ApiController]
[Route("[controller]")]
public class PingController
{
/// <summary>
/// Does a ping.
/// </summary>
/// <returns>Returns a pong.</returns>
/// <remarks>XML doc comments are referenced in the same file.</remarks>
[HttpGet]
[Route("embedded")]
public string PingEmbedded() => "embedded pong";

/// <include file='./PingController.xml' path='/PingController/ReferencedPing'/>
[HttpGet]
[Route("referenced")]
public string ReferencedPing3() => "referenced pong";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<PingController>
<ReferencedPing>
<summary>Does a ping.</summary>
<returns>Returns a pong.</returns>
<remarks>XML doc comments are included from a separate file.</remarks>
</ReferencedPing>
</PingController>
Loading

0 comments on commit 8712c23

Please sign in to comment.