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

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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
        });
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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());
                    });
                });
            }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.