From 60c27bfbd1fbb1373c7e2fd68f0f38312564b408 Mon Sep 17 00:00:00 2001 From: Chebotov Nikolay Date: Thu, 26 Aug 2021 17:14:25 +0300 Subject: [PATCH] update: Add message template for `AppendActionCountToTagSummaryDocumentFilter` --- CHANGELOG.md | 4 +++ README.md | 4 +-- ...ndActionCountToTagSummaryDocumentFilter.cs | 25 +++++++++++++++++-- ...e.Swashbuckle.AspNetCore.Extensions.csproj | 6 ++--- ...hase.Swashbuckle.AspNetCore.Extensions.xml | 5 ++++ test/WebApi3.1-Swashbuckle/Startup.cs | 4 +-- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a00deb..6be4757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 0c272cb..502a6fe 100644 --- a/README.md +++ b/README.md @@ -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(); + options.DocumentFilter("(count: {0})"); ... }); diff --git a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/AppendActionCountToTagSummaryDocumentFilter.cs b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/AppendActionCountToTagSummaryDocumentFilter.cs index 6d01e84..209429d 100644 --- a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/AppendActionCountToTagSummaryDocumentFilter.cs +++ b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/AppendActionCountToTagSummaryDocumentFilter.cs @@ -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; @@ -10,6 +11,24 @@ namespace Unchase.Swashbuckle.AspNetCore.Extensions.Filters /// public class AppendActionCountToTagSummaryDocumentFilter : IDocumentFilter { + private readonly string _messageTemplate; + + #region Constructor + + /// + /// Constructor. + /// + 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 /// @@ -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]); + } } } } diff --git a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj index dfc3812..da18963 100644 --- a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj +++ b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj @@ -14,9 +14,9 @@ 7.3 https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/blob/master/assets/icon.png?raw=true - 2.6.6 - 2.6.6.0 - 2.6.6.0 + 2.6.7 + 2.6.7.0 + 2.6.7.0 false Unchase.Swashbuckle.AspNetCore.Extensions.xml diff --git a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.xml b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.xml index 728a4ca..79010ad 100644 --- a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.xml +++ b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.xml @@ -259,6 +259,11 @@ Document filter for appending action count to Tag summary of controllers. + + + Constructor. + + Apply filter. diff --git a/test/WebApi3.1-Swashbuckle/Startup.cs b/test/WebApi3.1-Swashbuckle/Startup.cs index b0dde90..3301ecb 100644 --- a/test/WebApi3.1-Swashbuckle/Startup.cs +++ b/test/WebApi3.1-Swashbuckle/Startup.cs @@ -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(); + options.DocumentFilter("(the count of actions: {0})"); #endregion