Skip to content

The operationsConsumer in SpringdocRouteBuilder.filter() should be applied to all other operations #1538

@sohoffice

Description

@sohoffice

Describe the bug

In a functional endpoint RouterFunction, the route may have many operations that share the same filter. At the moment, the filter method is taking a operationsConsumer parameter, which is fine. However, this consumer must not require operationId, and it must be applied to the building results of other operations in the same function.

To Reproduce

Steps to reproduce the behavior:

  • What version of spring-boot you are using? 2.6.4
  • What modules and versions of springdoc-openapi are you using? springdoc-openapi-webflux-ui
  • What is the actual and the expected result using OpenAPI Description (yml or json)? The filter should not require operationId, the settings must combine, not override the builder result of other operation.
  • Provide with a sample code (HelloController) or Test that reproduces the problem
  public RouterFunction<ServerResponse> fooRoutes(FooHandler handler) {
    return route()
      .GET("/foo/{fooId}", handler::get,
        builder -> builder
          .operationId("getFoo")
          .parameter(parameterBuilder().name("fooId").in(ParameterIn.PATH))
          .response(responseBuilder()
            .responseCode("200")
            .implementation(FooOutput.class)
            .content(contentBuilder().schema(schemaBuilder().implementation(FooOutput.class)))))
      .filter(commonFilters.someFilter(), builder -> builder
        .operationId("this-should-not-be-needed")
        .parameter(parameterBuilder().name("foo-header").in(ParameterIn.HEADER)))
      .build();
  }

The generated document is as the below. The filter builder completely replaces the getFoo builder.

  /foo/{fooId}:
    get:
      operationId: this-should-not-be-needed
      parameters:
      - name: foo-header
        in: header
        schema:
          type: string

There are the below issues too:

  1. filter() method can not be placed before operations
  2. filter() method require the operationId to be supplied.

Expected behavior

I think we can either remove the mandatory operationsConsumer parameter from filter method, so that the developer can repeat them in all operations. Or better, we can implement the logic so that the operationsConsumer is applied on top of the business builder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions