Skip to content

Validation of REST input/output classes defined as dependency #9598

@mferlan

Description

@mferlan

Describe the bug
As a developer I use Hibernate Validator/Bean Validation for validating the input/output of your REST services.
But input/output of my REST services is defined in separate library (generated from RAML or OpenAPI file).

Expected behavior
When I follow validation-quickstart guide and make modification to extract my model to dependency then hibernate-validator should validate input/output of my REST services

Actual behavior
Response code 400 is returned with following message
javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.Size' validating type 'java.lang.String'. Check configuration for 'validateBook.arg0.author'

To Reproduce
Steps to reproduce the behavior:

  1. Follow validation-quickstart guide.
  2. Afterwards, a separate project validation-quickstart-model project is created
    • class Book is moved to that project.
    • added dependency to javax.validation:validation-api:jar:2.0.1.Final with scope provided
    • validation-quickstart-model installed in local repository
  3. Then in validation-quickstart project
    • added dependency to validation-quickstart-model
    • added to application.properties following
quarkus.index-dependency.validation-quickstart.group-id=org.acme
quarkus.index-dependency.validation-quickstart.artifact-id=validation-quickstart-model
  1. Open http://localhost:8080/
  2. Enter 1 for number of pages and press

Same behaviour occurs when instead of adding quarkus.index-dependency to application.properties we build validation-quickstart-model with jandex-maven-plugin:1.0.7 plugin ( using goal jandex).

The only case in which it did work was by creating empty beans.xml in validation-quickstart-model project.

Environment (please complete the following information):

  • Output of uname -a or ver:
    Linux mferlan-lap.at.local 3.10.0-1062.4.1.el7.x86_64 #1 SMP Fri Oct 18 17:15:30 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • Output of java -version:
    java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
  • Quarkus version or git rev:
    1.4.2.Final
  • Build tool (ie. output of mvnw --version or gradlew --version):
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/ferlan/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3
Java version: 1.8.0_101, vendor: Oracle Corporation, runtime: /opt/jdk1.8.0_101/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1062.4.1.el7.x86_64", arch: "amd64", family: "unix"

*** added on edit ***
Proposal for using

  • dependencies that contain a beans.xml descriptor (content is ignored),
  • dependencies that contain a Jandex index - META-INF/jandex.idx,
  • dependencies referenced by quarkus.index-dependency in application.properties,

was based on Context and Dependency Injection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions