Search code examples
javamavenjax-rsquarkusopenapi-generator

COMPILATION ERROR : package XXX does not exist


I am using the open-api generator plugin in my java project.

For more information about the plugin, see homepage and the generator jaxrs-spec i use.

Files are generated under the source folder i specified, but, when i'm implementing thoses files in my project (like a generated interface), maven compiler plugin fail during the compile goal.

Here is the complete error stack trace when i'm using mvn clean compile command :

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/****/nba-pistache/src/main/java/com/example/controller/BasicAuth.java:[3,23] package com.example.api does not exist
[ERROR] /C:/Users/****/nba-pistache/src/main/java/com/example/controller/BasicAuth.java:[13,26] cannot find symbol
  symbol:   class RestResourceRoot
  location: package com.example
[ERROR] /C:/Users/****/nba-pistache/src/main/java/com/example/controller/BasicAuth.java:[13,1] static import only from classes and interfaces
[ERROR] /C:/Users/****/nba-pistache/src/main/java/com/example/controller/BasicAuth.java:[16,35] cannot find symbol
  symbol: class UsersApi
[ERROR] /C:/Users/****/nba-pistache/src/main/java/com/example/controller/BasicAuth.java:[15,7] cannot find symbol
  symbol: variable APPLICATION_PATH

these files are generated in my /target folder. As you can see on the following screen : enter image description here

Here is a part of my pom.xml where i registered the openapi-generator-maven-plugin in the <build> section :

  <plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>6.2.1</version>
    <executions>
      <execution>
        <goals>
          <goal>generate</goal>
        </goals>
        <configuration>
          <inputSpec>${project.basedir}/src/main/resources/pistache-api.yaml</inputSpec>
          <generatorName>jaxrs-spec</generatorName>
          <apiPackage>com.example.api</apiPackage>
          <modelPackage>
            com.example.api.model
          </modelPackage>
          <configOptions>
            <useSwaggerAnnotations>false</useSwaggerAnnotations>
            <library>quarkus</library>
            <interfaceOnly>true</interfaceOnly>
            <dateLibrary>java8</dateLibrary>
            <useTags>true</useTags>
            <useBeanValidation>false</useBeanValidation>
            <returnResponse>true</returnResponse>
          </configOptions>
        </configuration>
      </execution>
    </executions>
  </plugin>

Here is my controller src/main/java/com/example/controller/BasicAuth.java in which I implement the generated interface and in which the errors are located:

package com.example.controller;

import com.example.api.UsersApi;
import com.example.client.RestClientBasicAuth;
import com.example.config.BasicUserConfig;
import org.eclipse.microprofile.rest.client.inject.RestClient;


import javax.inject.Inject;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

import static com.example.RestResourceRoot.APPLICATION_PATH;

@Path(APPLICATION_PATH)
public class BasicAuth implements UsersApi {

    @Override
    public Response retrievePwdGet() {
       // my custom implementation 
    }
}

Here is the interface target/generated-sources/openapi/src/gen/java/com/example/api/UsersApi.java :

package com.example.api;


import javax.ws.rs.*;
import javax.ws.rs.core.Response;


import java.io.InputStream;
import java.util.Map;
import java.util.List;


@Path("/retrieve-pwd")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2022-12-10T18:01:45.461936200+01:00[Europe/Paris]")
public interface UsersApi {

    @GET
    @Produces({ "application/json" })
    Response retrievePwdGet();
}

I don't know what's going wrong here. My IDE does not report any errors, although I know that the IDE cannot be fully trusted.

Finally, my application can be started correctly via the IDE, but the controller endpoint for my GET method is not the one defined in the UsersApi interface. The path is not api/v1/retrieve-pwd, but api/v1.

This behavior is also strange. Maybe by overloading the method in my controller the path can be modified, but, the path is not defined on the method but on the interface.

I await your comments or feedback and thank you in advance


Solution

  • Problem was generated files : they were not compiled. This explain errors messages.

    Solution was adding a maven helper plugin :

     <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>3.2.0</version>
            <executions>
              <execution>
                <id>add-source</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>add-source</goal>
                </goals>
                <configuration>
                  <sources>
                    <source>src/main/newsrc/</source>
                  </sources>
                </configuration>
              </execution>
            </executions>
          </plugin>