Skip to content

Invalid ApiDescription GroupName in DocInclusionPredicate since 6.2.0 #923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
peterkiss1 opened this issue Nov 21, 2022 · 2 comments
Closed
1 task done
Assignees
Labels

Comments

@peterkiss1
Copy link

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

@commonsensesoftware
Copy link
Collaborator

Confirmed. This is a regression due to the new custom grouping feature. This will be fixed and released in the next patch ASAP. Thanks for reporting it.

@commonsensesoftware
Copy link
Collaborator

This is fixed in 6.3.x and 7.0.0-*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants