swagger-api / swagger-api/swagger-core

Lack of Friendly Support for Parameter Validation Grouping

Open
#4,928 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

🚀 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the @Schema and @Operation annotation definitions and the linked knife4j-jakarta-group implementation. Check how validation groups would map to the proposed OpenAPI output and whether the suggested UI behavior is within this project's scope. Done would require an agreed design for annotation support, generated output, and UI integration.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.