Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Add new attribute IgnoreApiUrlAttribute

support34c3d68cca42
diff --git a/src/Core/Grand.SharedKernel/Attributes/IgnoreApiAttribute.cs b/src/Core/Grand.SharedKernel/Attributes/IgnoreApiAttribute.cs
index 2756d4e23..e18f3568c 100644
--- a/src/Core/Grand.SharedKernel/Attributes/IgnoreApiAttribute.cs
+++ b/src/Core/Grand.SharedKernel/Attributes/IgnoreApiAttribute.cs
@@ -3,4 +3,9 @@
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Property)]
public class IgnoreApiAttribute : Attribute
{
+}
+
+[AttributeUsage(AttributeTargets.Property)]
+public class IgnoreApiUrlAttribute : Attribute
+{
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Common/ApiExplorer/MetadataApiDescriptionProvider.cs b/src/Web/Grand.Web.Common/ApiExplorer/MetadataApiDescriptionProvider.cs
index ddc227096..f9d9aecf6 100644
--- a/src/Web/Grand.Web.Common/ApiExplorer/MetadataApiDescriptionProvider.cs
+++ b/src/Web/Grand.Web.Common/ApiExplorer/MetadataApiDescriptionProvider.cs
@@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.ModelBinding;
+using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Template;
using Microsoft.Extensions.Options;
@@ -108,7 +109,7 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
foreach (var parameter in GetParameters(parameterContext,
httpMethod.Equals("GET", StringComparison.CurrentCultureIgnoreCase)))
{
- apiDescription.ParameterDescriptions.Add(parameter);
+ apiDescription.ParameterDescriptions.Add(parameter);
}
var requestMetadataAttributes = GetRequestMetadataAttributes(action);
@@ -228,6 +229,12 @@ public class MetadataApiDescriptionProvider : IApiDescriptionProvider
{
context.Results.RemoveAt(i);
}
+ else
+ {
+ if (context.Results[i].ModelMetadata is DefaultModelMetadata metadata &&
+ metadata.Attributes.Attributes.OfType<IgnoreApiUrlAttribute>().Any())
+ context.Results.RemoveAt(i);
+ }
}
// Next, we want to join up any route parameters with those discovered from the action's parameters.