Skip to content

Invalid ApiDescription GroupName in DocInclusionPredicate since 6.2.0 #923

Closed
@peterkiss1

Description

@peterkiss1

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

ApiDescription instance for the DocInclusionPredicate contains the api version string as the ApiDescription.GroupName since version 6.2.0 where this property contained the GroupName inherited from the controller (in my case no GroupName was provided for the actions only for the controllers) previously.

This breaks the default behavior described in the documentation and the result will be operation-less OpenApi definition files:

"When selecting actions for a given Swagger document, the generator invokes a DocInclusionPredicate against every ApiDescription that's surfaced by the framework. The default implementation inspects ApiDescription.GroupName and returns true if the value is either null OR equal to the requested document name."

openapi: 3.0.1
info:
  title: v1
  description: v1
  contact:
    name: Dev contact
  version: v1
paths: { }
components: { }

On the Swagger UI: "No operations defined in spec!"

Expected Behavior

This should work as it is in the documentation and as it was in version 6.1.0 and before.

Steps To Reproduce

Controllers:

    [ApiController]
    [ApiVersion("1.0")]
    [ApiExplorerSettings(GroupName = "group1")]
    [Route("api/v{version:apiVersion}/hello")]
    public class HelloWorldController : ControllerBase
    {
        [HttpGet("hello")]
        public IActionResult Hello()
        {
            return Ok("Hello world v1!");
        }
    }
    [ApiController]
    [ApiVersion("2.0")]
    [ApiExplorerSettings(GroupName = "group2")]
    [Route("api/v{version:apiVersion}/hello")]
    public class HelloWorldControllerV2 : ControllerBase
    {
        [HttpGet("hello")]
        public IActionResult Hello()
        {
            return Ok("Hello world v2!");
        }
    }

Setup

            services.AddApiVersioning(config =>
            {
                config.DefaultApiVersion = new ApiVersion(1, 0);
                config.AssumeDefaultVersionWhenUnspecified = true;
                config.ReportApiVersions = true;
            })
            .AddMvc()
            .AddApiExplorer(o =>
            {
                o.GroupNameFormat = "'v'VVV";
                o.SubstituteApiVersionInUrl = true;
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("group1", new OpenApiInfo
                {
                    Title = "v1",
                    Description = "v1",
                    Version = "v1",
                    Contact = new OpenApiContact
                    {
                        Name = "Dev contact"
                    }
                });

                c.SwaggerDoc("group2", new OpenApiInfo
                {
                    Title = "v2",
                    Description = "v2",
                    Version = "v2",
                    Contact = new OpenApiContact
                    {
                        Name = "Dev contact"
                    }
                });
            });
            app.UseSwagger(c => c.RouteTemplate = "openapi/{documentName}/schema.yaml");
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint($"/openapi/group1/schema.yaml", "v1");
                c.SwaggerEndpoint($"/openapi/group2/schema.yaml", "v2");
            });

Exceptions (if any)

No response

.NET Version

.NET 6 latest

Anything else?

TargetFramework: net6.0

Asp.Versioning.Mvc.ApiExplorer 6.3.0, 6.2.0, 6.2.1
Serilog.AspNetCore 6.0.1
Swashbuckle.AspNetCore 6.4.0
Swashbuckle.AspNetCore.Filters 7.0.6

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions