Skip to content

Applying validation rules does not take into account groups on rules #2792

Closed
@mc1arke

Description

@mc1arke

Describe the bug

When using a jaxarta.validation.constraints.* annotation, a user can specify a 'groups' field on the annotation which causes that validation to only be applied if the validator has been configured to apply that group. If no groups are specified on the annotation then the annotation is applied for all inputs. springdoc-openapi is currently not checking for the presence of groups so it setting the limits from the validation globally, even where the validation would not apply to some requests.

To Reproduce
With an endpoint and model definition of

	@GetMapping("/grouped-nullable")
	public void validationNotNullWithNonActiveGroup(@RequestBody RequestContent requestContent) {

	}

	public interface ValidationGroup {
		
	}

	public record RequestContent(
			@NotNull(groups = ValidationGroup.class) String value
	) {

	}

the project currently generates a JSON definition with the following parameters

        "parameters": [
          {
            "name": "requestContent",
            "in": "query",
            "required": true,
            "schema": {
              "$ref": "#/components/schemas/RequestContent"
            }
          }

Expected behavior
Given no groups are known to be active, any validation that has groups specified should be presumed to be inactive and therefore not be applied to the model, e.g.

        "parameters": [
          {
            "name": "requestContent",
            "in": "query",
            "required": false,
            "schema": {
              "$ref": "#/components/schemas/RequestContent"
            }
          }

The same applies for other annotations, e.g.@Min, @Max, @Pattern etc.

Ideally, it would be useful to be able to configure the generator to have a set of group combinations to match to, defaulting to the 'empty' group to ensure validations that are applied to all requests are the only ones specified in the request

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions