Skip to content
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

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

Closed
mc1arke opened this issue Nov 25, 2024 · 2 comments
Closed

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

mc1arke opened this issue Nov 25, 2024 · 2 comments
Labels
wontfix This will not be worked on

Comments

@mc1arke
Copy link
Contributor

mc1arke commented Nov 25, 2024

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

@bnasslahsen
Copy link
Contributor

@mc1arke,

There is no plans for this support.
Feel free to propose a PR if you feel it useful for the community, and we will have a look at it.

@bnasslahsen bnasslahsen added the wontfix This will not be worked on label Dec 8, 2024
@mc1arke
Copy link
Contributor Author

mc1arke commented Dec 8, 2024

I've opened swagger-api/swagger-core#4804 as I think changes need made in Swagger core before this can be properly supported in SpringDoc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants