Support for regex constraints in HideAbpEndpoints method

pull/15722/head
Engincan VESKE 3 years ago
parent dd45cb1b34
commit 2ea6597098

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
@ -11,6 +12,8 @@ public class AbpSwashbuckleDocumentFilter : IDocumentFilter
{
protected virtual string[] ActionUrlPrefixes { get; set; } = new[] { "Volo." };
protected virtual string RegexConstraintPattern => @":regex\(([^()]*)\)";
public virtual void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
var actionUrls = context.ApiDescriptions
@ -35,14 +38,21 @@ public class AbpSwashbuckleDocumentFilter : IDocumentFilter
return route;
}
route = Regex.Replace(route, RegexConstraintPattern, "");
while (route.Contains(':'))
{
var startIndex = route.IndexOf(":", StringComparison.Ordinal);
var endIndex = route.IndexOf("}", StringComparison.Ordinal);
var endIndex = route.IndexOf("}", startIndex);
if (startIndex == -1 || endIndex == -1)
if (endIndex == -1)
{
return route;
break;
}
return route.Remove(startIndex, (endIndex - startIndex));
route = route.Remove(startIndex, (endIndex - startIndex));
}
return route;
}
}
Loading…
Cancel
Save