Skip to content

[REQ] [SPRING] Add support for request parameter pattern validation #12726

Open
@LubomirS

Description

@LubomirS

Is your feature request related to a problem? Please describe.

Open api v3 spec allows defining patterns in schemas, which includes places like pathParams, queryParams and headerParams. There already is support for pattern validation in both pathParams and queryParams, however, this validation cannot be used for headers.
Example:

{
  "name": "patternHeader",
  "in": "header",
  "required": true,
  "schema": {
    "pattern": "[0-9]+",
    "type": "string"
  }
}

In Spring, request header would be annotated with javax.validation.constraints.Pattern, like so:

@RequestHeader(value = "patternHeader") @Pattern(regexp = "[0-9]+") String patternHeader

which will validate if the request header matches the regex "[0-9]+".

Describe the solution you'd like

I would propose to add this feature by adding the beanValidationHeaderParams mustache file for Spring codegen, similarly how it's done with query params.

Describe alternatives you've considered

I don't think there is a better alternative solution to support this validation.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions