An endpoint changed from accepting a single id parameter
- name: id
in: query
schema:
$ref: "#/components/schemas/id"
to accepting an array:
- name: id
in: query
schema:
type: array
items:
$ref: "#/components/schemas/id"
with id defined as:
id:
type: string
pattern: "^[1-9][0-9]{0,9}$"
description: Identifies a Location within the EDDI API (has no wider interpretation).
example: "1"
but it seems, pattern validation was lost along the way. After reading contents of https://github.com/OpenAPITools/openapi-generator/issues/4947, I tried to implement it this way:
- name: id
in: query
schema:
type: array
items:
type: object
properties:
item:
$ref: "#/components/schemas/id"
And the generated Id object even has the @Pattern(regexp="^[1-9][0-9]{0,9}$") on getter and @Valid on it's only field: private @Valid String item;, but validation seem not to be invoked by Jersey: constraints list is empty in org.hibernate.validator.internal.engine.ValidatorImpl#validateMetaConstraints. Looks like in order to have the object validated I need to make OpenApiGenerator to put @Valid constraint on the query parameter in the auto-generated interface...
Is there a way to enforce validation defined in OpenApi spec on Jersey/Jetty without writing the code to validate parameters on the backend manually?
P.S. As it is written in the bug (the link above), defining array items as string won't produce @Valid ad @Pattern annotations
- name: id
in: query
schema:
type: array
items:
type: string
properties:
item:
$ref: "#/components/schemas/id"
P.P.S OpenApiGenerator version: 4.3.1, Jersey version=2.29.1, Jetty version=9.4.6.v20170531