Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Show/hide API end-points in Swagger UI #4139


User avatar
0
walkerscott created

Hi.

We have a project that is in ABP ASP.NET MVC 5 using Swashbuckle 5.0 for Swagger UI implementation. We follow the steps in this documentation ([https://aspnetboilerplate.com/Pages/Documents/Swagger-UI-Integration#aspnet-5x])) as the guide for implementing swagger and we successfully accessed /swagger/ui/index.

From the image below, we want to show only the Account and OrderUpload endpoint, hiding all default endpoints.

We followed the documentation in [https://aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API]) to just create specific endpoints only but we're unsuccessful. We encountered problems on using #2 to #4 approach. The only working is #1 that creates all endpoints.

public override void Initialize()
{
    IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

    //-- APPROACH [#1](https://support.aspnetzero.com/QA/Questions/1)
    //Automatically creates Web API controllers for all application services of the application
    DynamicApiControllerBuilder
        .ForAll<IApplicationService>(typeof(DC4ApplicationModule).Assembly, "app")
        .Build();

    //-- APPROACH [#2](https://support.aspnetzero.com/QA/Questions/2)
    DynamicApiControllerBuilder
        .For<IApplicationService>("app")
        .ForMethod("Clear").DontCreateAction()
        .ForMethod("ClearAll").DontCreateAction()
        .Build();

    //-- APPROACH [#3](https://support.aspnetzero.com/QA/Questions/3)
    DynamicApiControllerBuilder
        .ForAll<IApplicationService>(typeof(DC4ApplicationModule).Assembly, "app")
        .ForMethod(builder =>
        {
            if (builder.Method.IsDefined(typeof(MyIgnoreApiAttribute)))
            {
                builder.DontCreate = true;
            }
        })
        .Build();

    //-- APPROACH [#4](https://support.aspnetzero.com/QA/Questions/4)
    DynamicApiControllerBuilder
        .For<IApplicationService>("app")
        .ForMethod("UploadOrders").WithVerb(HttpVerb.Post)
        .Build();

    Configuration.Modules.AbpWebApi().HttpConfiguration.Filters.Add(new HostAuthenticationFilter("Bearer"));
    ConfigureSwaggerUi();
}

For approach #2 and #4, this was the encountered error:

For approach #3, the ForMethod is not available as a definition.

We are thinking that we need to map the correct path put it in "app" in this line of code to access the two controllers (Account and OrderUpload) on WebApi project to use the approaches above.

.ForAll<IApplicationService>(typeof(DC4ApplicationModule).Assembly, "app")

How can we show/hide API end-points using the ABP and user based permissions?


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @walkerscott,

    Have you tried Swashbuckle's document filters ? I think it is what you are looking for <a class="postlink" href="https://github.com/domaindrivendev/Swashbuckle#documentfilter">https://github.com/domaindrivendev/Swas ... mentfilter</a>.