Swagger-codegen: [JAX-RS] Cannot run generated server with validation-api scope provided

Created on 16 Mar 2017  路  6Comments  路  Source: swagger-api/swagger-codegen

Description

When using Codegen through Swagger UI Docker container for a JAX-RS server, the README.md
states that running mvn clean package jetty:run will start the server. Running this results in:

WARNING: The following warnings have been detected: WARNING: HK2 service reification failed for [org.glassfish.jersey.server.model.ResourceMethodInvoker$Builder] with an exception:
MultiException stack 1 of 1
java.lang.NoClassDefFoundError: javax/validation/Validator

and the content is unavailable.

The generated pom.xml has:

<!-- Bean Validation API support -->
<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<scope>provided</scope>
</dependency>

Removing the provided scope fixes the issue for me.

Swagger-codegen version

I am not sure. The Docker container seems to be accessing Codegen through the network.

docker.io/swaggerapi/swagger-editor with TAG latest

Swagger declaration file content or url

The default yaml file that begins with:

# this is an example of the Uber API
# as a demonstration of an API spec in YAML

can be used to reproduce the issue.

Steps to reproduce
  1. Open the default example in Swagger UI in Docker container
  2. Generate server JAX-RS
  3. Unzip tarball and enter jaxrs-server folder
  4. Run mvn clean package jetty:run
  5. See ClassNotFound exception
  6. Attempt to access via curl http://localhost:8080/v1/swagger.json and see 503 error

  7. Edit pom.xml and remove provided from validation-api dependency

  8. Run mvn clean package jetty:run and curl http://localhost:8080/v1/swagger.json successfully.
Suggest a Fix

If validation-api is meant to be provided then the documentation needs to be updated and should include how users can provide the dependency. Otherwise, it should not be <scope>provided</scope>

Most helpful comment

Having the same issue as well, changed the provided scope to compile in order to fix it

All 6 comments

Jep, also experiencing this issue

yes, it is right!

Having the same issue as well, changed the provided scope to compile in order to fix it

If it's of any value to anyone, I used the following command (xml is xmlstarlet) to change the scope to compile:

xml ed -L -u "//*[name()='dependencies']/*[name()='dependency']/*[name()='groupId' and text()='javax.validation']/../*[name()='scope']" -v compile pom.xml

fixed in #8538

I didn't want to try snapshot release. So, I reverted to version 2.1.6 and got it working.

Was this page helpful?
0 / 5 - 0 ratings