Revert "Optimize hide abp end points"

Reverts abpframework/abp#17151
pull/17510/head
maliming 1 year ago
parent 4127eae194
commit fd80e44fdb

@ -13,7 +13,7 @@ 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
@ -28,29 +28,8 @@ public class AbpSwashbuckleDocumentFilter : IDocumentFilter
swaggerDoc
.Paths
.RemoveAll(path => !actionUrls.Contains(path.Key));
var actionSchemas = new HashSet<string>();
actionSchemas.UnionWith(swaggerDoc.Paths.Select(path => new { path = path.Value, schemas = swaggerDoc.Components.Schemas }).SelectMany(x => GetSchemaIdList(x.path, x.schemas)));
swaggerDoc.Components.Schemas.RemoveAll(schema => !actionSchemas.Contains(schema.Key));
}
protected virtual HashSet<string> GetSchemaIdList(OpenApiPathItem pathItem, IDictionary<string, OpenApiSchema> schemas)
{
var selectedSchemas = new HashSet<OpenApiSchema>();
var schemaIds = new HashSet<string>();
selectedSchemas.UnionWith(pathItem.Parameters.Select(parameter => parameter.Schema));
selectedSchemas.UnionWith(pathItem.Parameters.SelectMany(parameter => parameter.Content.Select(x => x.Value.Schema)));
selectedSchemas.UnionWith(pathItem.Operations.Values.SelectMany(c => c.Responses.SelectMany(x => x.Value.Content.Values.Select(x => x.Schema))));
selectedSchemas.UnionWith(pathItem.Operations.Values.SelectMany(c => c.Parameters.Select(x => x.Schema)));
foreach (var schema in selectedSchemas)
{
schemaIds.UnionWith(MakeListSchemaId(schema, schemas));
}
return schemaIds;
}
protected virtual string? RemoveRouteParameterConstraints(ActionDescriptor actionDescriptor)
{
var route = actionDescriptor.AttributeRouteInfo?.Template?.EnsureStartsWith('/').Replace("?", "");
@ -70,34 +49,10 @@ public class AbpSwashbuckleDocumentFilter : IDocumentFilter
{
break;
}
route = route.Remove(startIndex, endIndex - startIndex);
route = route.Remove(startIndex, (endIndex - startIndex));
}
return route;
}
private HashSet<string> MakeListSchemaId(OpenApiSchema schema, IDictionary<string, OpenApiSchema> contextSchemas)
{
var schemasId = new HashSet<string>();
if (schema != null)
{
if (schema.Reference != null)
{
schemasId.Add(schema.Reference.Id);
foreach (var sc in contextSchemas.Where(x => x.Key == schema.Reference.Id).Select(x => x.Value))
{
foreach (var property in sc.Properties.Values)
{
schemasId.UnionWith(MakeListSchemaId(property, contextSchemas));
}
}
}
if (schema.Items != null)
{
schemasId.UnionWith(MakeListSchemaId(schema.Items, contextSchemas));
}
}
return schemasId;
}
}
}

Loading…
Cancel
Save