OpenAPITools / OpenAPITools/openapi-generator

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

Open
#12,726 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

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

Inspect the Spring codegen templates for query-parameter bean validation and the proposed beanValidationHeaderParams.mustache template. Compare the generated output for a header schema with a pattern, then verify that the generated Spring request header includes the corresponding Pattern validation annotation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
backend-api-design, tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.