From fd80e44fdb8fb2d9eca57304d36f370e6796c338 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 30 Aug 2023 11:14:34 +0800 Subject: [PATCH] Revert "Optimize hide abp end points" Reverts abpframework/abp#17151 --- .../AbpSwashbuckleDocumentFilter.cs | 53 ++----------------- 1 file changed, 4 insertions(+), 49 deletions(-) diff --git a/framework/src/Volo.Abp.Swashbuckle/Volo/Abp/Swashbuckle/AbpSwashbuckleDocumentFilter.cs b/framework/src/Volo.Abp.Swashbuckle/Volo/Abp/Swashbuckle/AbpSwashbuckleDocumentFilter.cs index c4c9c86c7f..b6dc661410 100644 --- a/framework/src/Volo.Abp.Swashbuckle/Volo/Abp/Swashbuckle/AbpSwashbuckleDocumentFilter.cs +++ b/framework/src/Volo.Abp.Swashbuckle/Volo/Abp/Swashbuckle/AbpSwashbuckleDocumentFilter.cs @@ -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(); - 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 GetSchemaIdList(OpenApiPathItem pathItem, IDictionary schemas) - { - var selectedSchemas = new HashSet(); - var schemaIds = new HashSet(); - - 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 MakeListSchemaId(OpenApiSchema schema, IDictionary contextSchemas) - { - var schemasId = new HashSet(); - 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; - } -} \ No newline at end of file +}