Open Closed

Setup swagger definition convention #1082


User avatar
0
l.lemmens created
  • ABP Framework version: v4.2.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

We'd like to have different swagger files for sections of our code. I've added following items in the hostmodule to add a second swagger definition:

options.SwaggerDoc("v1-backoffice", new OpenApiInfo { Title = "DLV_TC_Platform API Backoffice", Version = "v1" });
options.SwaggerDoc("v1-frontend", new OpenApiInfo { Title = "DLV_TC_Platform API Frontend", Version = "v1" });

options.SwaggerEndpoint("/swagger/v1-backoffice/swagger.json", "DLV_TC_Platform API BackOffice");
options.SwaggerEndpoint("/swagger/v1-frontend/swagger.json", "DLV_TC_Platform API Frontend");

With this setup you get two versions but they are the same.

How can I now indicate which services may appear on which swagger? Preferably with a convention-like method, so it can be setup once and then 'forgotten'.

Kind regards Lotte


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can refer to Swashbuckle.AspNetCore's document.

    https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/README.md#generate-multiple-swagger-documents

  • User Avatar
    0
    l.lemmens created

    I have seen this and I would like a possibility to add this to a non MVC project

    // Startup.cs
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc(c =>
            c.Conventions.Add(new ApiExplorerGroupPerVersionConvention())
        );
    
        ...
    }
    

    I'm using abpio and it generates this of MVC-options:

    Configure<AbpAspNetCoreMvcOptions>(options =>
                {
                    options.ConventionalControllers.Create(typeof(DLV_TC_PlatformApplicationModule).Assembly);
                });
    

    And I cannot find any convention settings there.

    Kind regards Lotte

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi l.lemmens

    non MVC project

    API is also an MVC project.

    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        PreConfigure<IMvcBuilder>(mvcBuilder =>
        {
            //mvcBuilder.Conventions
        });
    }
    
  • User Avatar
    0
    l.lemmens created

    That got me there, thanks :)

    public override void PreConfigureServices(ServiceConfigurationContext context)
            {
                PreConfigure<IMvcBuilder>(mvcBuilder =>
                {
                    mvcBuilder.Services.AddControllersWithViews()
                    .AddMvcOptions(o =>
                    {
                        o.Conventions.Add(new SwaggerFilePickerConvention());
                    });
                });
            }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35