Skip to content

Commit

Permalink
update: Add message template for `AppendActionCountToTagSummaryDocume…
Browse files Browse the repository at this point in the history
…ntFilter`
  • Loading branch information
unchase committed Aug 26, 2021
1 parent 2af9003 commit 60c27bf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

These are the changes to each version that has been released on the [nuget](https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions/).

## v2.6.7 `2021-08-26`

- [x] Add message template for `AppendActionCountToTagSummaryDocumentFilter`

## v2.6.6 `2021-08-26`

- [x] Add `IncludeXmlCommentsWithRemarks` improvements
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ public void ConfigureServices(IServiceCollection services)
// enable openApi Annotations
options.EnableAnnotations();

// add action count into the SwaggerTag's descriptions
// add action count (with message template) into the SwaggerTag's descriptions
// you can use it after "HidePathsAndDefinitionsByRolesDocumentFilter"
options.DocumentFilter<AppendActionCountToTagSummaryDocumentFilter>();
options.DocumentFilter<AppendActionCountToTagSummaryDocumentFilter>("(count: {0})");

...
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
Expand All @@ -10,6 +11,24 @@ namespace Unchase.Swashbuckle.AspNetCore.Extensions.Filters
/// </summary>
public class AppendActionCountToTagSummaryDocumentFilter : IDocumentFilter
{
private readonly string _messageTemplate;

#region Constructor

/// <summary>
/// Constructor.
/// </summary>
public AppendActionCountToTagSummaryDocumentFilter(string messageTemplate = "(action count: {0})")
{
_messageTemplate = messageTemplate;
if (!_messageTemplate.Contains("{0}"))
{
throw new ArgumentException("The message template must contains '{0}'.", nameof(messageTemplate));
}
}

#endregion

#region Methods

/// <summary>
Expand Down Expand Up @@ -43,7 +62,9 @@ public void Apply(OpenApiDocument openApiDoc, DocumentFilterContext context)
foreach (var tag in openApiDoc.Tags)
{
if (tag.Name == tagActionCountKey)
tag.Description += $" (action count: {tagActionCount[tagActionCountKey]})";
{
tag.Description += string.Format($" {_messageTemplate}", tagActionCount[tagActionCountKey]);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<NeutralLanguage></NeutralLanguage>
<LangVersion>7.3</LangVersion>
<PackageIconUrl>https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/blob/master/assets/icon.png?raw=true</PackageIconUrl>
<Version>2.6.6</Version>
<AssemblyVersion>2.6.6.0</AssemblyVersion>
<FileVersion>2.6.6.0</FileVersion>
<Version>2.6.7</Version>
<AssemblyVersion>2.6.7.0</AssemblyVersion>
<FileVersion>2.6.7.0</FileVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<DocumentationFile>Unchase.Swashbuckle.AspNetCore.Extensions.xml</DocumentationFile>
</PropertyGroup>
Expand Down

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

4 changes: 2 additions & 2 deletions test/WebApi3.1-Swashbuckle/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public void ConfigureServices(IServiceCollection services)
// enable openApi Annotations
options.EnableAnnotations();

// add action count into the SwaggerTag's descriptions
// add action count (with message template) into the SwaggerTag's descriptions
// you can use it after "HidePathsAndDefinitionsByRolesDocumentFilter"
options.DocumentFilter<AppendActionCountToTagSummaryDocumentFilter>();
options.DocumentFilter<AppendActionCountToTagSummaryDocumentFilter>("(the count of actions: {0})");

#endregion

Expand Down

0 comments on commit 60c27bf

Please sign in to comment.