Skip to content

Lack of Friendly Support for Parameter Validation Grouping #4928

@lisi9988

Description

@lisi9988

🚀 Feature Request: Improve Support for Parameter Validation Grouping

Currently, Swagger and SpringDoc lack native support for parameter validation grouping, which could be very useful for many developers by reducing the need for multiple DTOs.


✅ Proposed Enhancement

Please consider adding a groups parameter to the following annotations:

In @Schema annotation:

/**
 * Valid group
 */
Class<?>[] groups() default {};

In @Operation annotation:

/**
 * Valid group
 */
Class<?> groups() default Void.class;

📌 Example OpenAPI Output

API Operation with Groups

{
  "paths": {
    "/user": {
      "put": {
        "summary": "Update user",
        "operationId": "update",
        "groups": "Update"
      },
      "post": {
        "summary": "Add user",
        "operationId": "add",
        "groups": "Create"
      }
    }
  }
}

DTO Schema with Groups

{
  "components": {
    "schemas": {
      "UserDto": {
        "type": "object",
        "description": "User - Request Data Carrier",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int32",
            "description": "Primary Key ID",
            "groups": [
              "HiddenCreate",
              "Update"
            ]
          },
          "name": {
            "type": "string",
            "description": "Name",
            "groups": [
              "HiddenQuery",
              "Create",
              "Update",
              "HiddenDelete"
            ]
          }
        }
      }
    }
  }
}

💡 UI Behavior Suggestion

In the UI (e.g., Knife4j or Swagger UI), fields should be dynamically displayed or hidden based on the current operation's validation group. This includes showing whether a field is required, optional, or hidden in that context.


🧑‍💻 My Implementation

I previously implemented this feature for JDK8 and re-implemented it again after upgrading to JDK17. I'd love to see official support for this.


📎 Related Topics

  • JSR-380 Bean Validation 2.0 (supports validation groups)
  • Spring Validation
  • Swagger / SpringDoc integration improvements

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions