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");

2021-03-23_12h14_44.png

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
  • 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(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(mvcBuilder =>
                {
                    mvcBuilder.Services.AddControllersWithViews()
                    .AddMvcOptions(o =>
                    {
                        o.Conventions.Add(new SwaggerFilePickerConvention());
                    });
                });
            }
    
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on April 10, 2025, 12:38