Abp: Can we hide ABP related HTTP API endpoints if desired?

Created on 27 Apr 2020  路  3Comments  路  Source: abpframework/abp

Even for an empty project, we have the following pre-defined HTTP endpoints:

image

We may want to disable these endpoints (not only hide from swagger, but completely disable them). So, we need to provide an option for it.

abp-framework effort-2 enhancement high

Most helpful comment

I am hiding the abp endpoints on Swagger UI by adding a [ShowInSwagger] attribute to the controllers I want to see, then using this in my host module:

public class ShowInSwaggerAttributeFilter : IDocumentFilter
{
    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
    {
        var filteredApis = context.ApiDescriptions.Where(a => a.CustomAttributes().Any(x => 
            x.GetType() == typeof(ShowInSwaggerAttribute)));

        foreach (var path in swaggerDoc.Paths.ToList())
        {
            if (filteredApis.All(x => ("/" + x.RelativePath) != path.Key))
                swaggerDoc.Paths.Remove(path.Key);
        }
    }
}

All 3 comments

I am hiding the abp endpoints on Swagger UI by adding a [ShowInSwagger] attribute to the controllers I want to see, then using this in my host module:

public class ShowInSwaggerAttributeFilter : IDocumentFilter
{
    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
    {
        var filteredApis = context.ApiDescriptions.Where(a => a.CustomAttributes().Any(x => 
            x.GetType() == typeof(ShowInSwaggerAttribute)));

        foreach (var path in swaggerDoc.Paths.ToList())
        {
            if (filteredApis.All(x => ("/" + x.RelativePath) != path.Key))
                swaggerDoc.Paths.Remove(path.Key);
        }
    }
}

How do I prevent the execution of certain methods and tell ABP to ignore them when creating endpoints (by convention)?

it is greate enhancement, recently I am looking for it .

some pre-built in apis I do not want to be exposed

Was this page helpful?
0 / 5 - 0 ratings