GoogleCloudPlatform / endpoints-framework-maven-plugin

Apache License 2.0
5 stars 13 forks source link

[Bug] Unable to generate open api spec #30

Closed frankyn closed 7 years ago

frankyn commented 7 years ago

Hi,

I'm working with the endpoints framework maven plugin to generate an open api spec. When I attempt to use the plugin with this sample (https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appengine/endpoints-frameworks-v2/backend) I get a missing class error:

Endpoints Tool Error: java.lang.reflect.InvocationTargetException: Type com.google.api.server.spi.auth.EspAuthenticator not present 

I was able to solve it by providing the expected dependency to the maven plugin shown below.

Question, should a user have to provide the plugin with additional dependencies as shown below?. For more context here's the full version of the pom.xml.

           <plugin>
               <groupId>com.google.cloud.tools</groupId>
               <artifactId>endpoints-framework-maven-plugin</artifactId>
               <version>1.0.0</version>
               <configuration>
                   <!-- plugin configuration -->
                   <hostname>${endpoints.project.id}.appspot.com</hostname>
               </configuration>
               <dependencies>
                 <dependency>
                     <groupId>com.google.endpoints</groupId>
                     <artifactId>endpoints-management-control-appengine-all</artifactId>
                     <version>1.0.4</version>
                 </dependency>
               </dependencies>
           </plugin>
loosebazooka commented 7 years ago

@tangiel

frankyn commented 7 years ago

I created a branch with this issue for reproduction: https://github.com/frankyn/java-docs-samples/tree/openapi-issue/appengine/endpoints-frameworks-v2/backend

tangiel commented 7 years ago

Running with mvn -X shows this fragment:

[INFO] Endpoints Tool params : [get-openapi-doc, -o, /usr/local/google/home/tangd/code/frankyn/java-docs-samples/appengine/endpoints-frameworks-v2/backend/target/openapi-docs/openapi.json, -cp, [/usr/local/google/home/tangd/code/frankyn/java-docs-samples/appengine/endpoints-frameworks-v2/backend/target/echo-1.0-SNAPSHOT/WEB-INF/classes, /usr/local/google/home/tangd/.m2/repository/com/google/endpoints/endpoints-framework/2.0.7/endpoints-framework-2.0.7.jar, /usr/local/google/home/tangd/.m2/repository/com/google/guava/guava/19.0/guava-19.0.jar, /usr/local/google/home/tangd/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.6.4/jackson-annotations-2.6.4.jar, /usr/local/google/home/tangd/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.6.4/jackson-core-2.6.4.jar, /usr/local/google/home/tangd/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.6.4/jackson-databind-2.6.4.jar, /usr/local/google/home/tangd/.m2/repository/com/google/http-client/google-http-client-jackson2/1.21.0/google-http-client-jackson2-1.21.0.jar, /usr/local/google/home/tangd/.m2/repository/com/google/http-client/google-http-client/1.21.0/google-http-client-1.21.0.jar, /usr/local/google/home/tangd/.m2/repository/org/apache/httpcomponents/httpclient/4.0.1/httpclient-4.0.1.jar, /usr/local/google/home/tangd/.m2/repository/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar, /usr/local/google/home/tangd/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar, /usr/local/google/home/tangd/.m2/repository/commons-codec/commons-codec/1.3/commons-codec-1.3.jar, /usr/local/google/home/tangd/.m2/repository/com/google/api-client/google-api-client/1.21.0/google-api-client-1.21.0.jar, /usr/local/google/home/tangd/.m2/repository/com/google/oauth-client/google-oauth-client/1.21.0/google-oauth-client-1.21.0.jar, /usr/local/google/home/tangd/.m2/repository/com/google/api-client/google-api-client-appengine/1.21.0/google-api-client-appengine-1.21.0.jar, /usr/local/google/home/tangd/.m2/repository/com/google/oauth-client/google-oauth-client-appengine/1.21.0/google-oauth-client-appengine-1.21.0.jar, /usr/local/google/home/tangd/.m2/repository/com/google/oauth-client/google-oauth-client-servlet/1.21.0/google-oauth-client-servlet-1.21.0.jar, /usr/local/google/home/tangd/.m2/repository/com/google/http-client/google-http-client-jdo/1.21.0/google-http-client-jdo-1.21.0.jar, /usr/local/google/home/tangd/.m2/repository/com/google/api-client/google-api-client-servlet/1.21.0/google-api-client-servlet-1.21.0.jar, /usr/local/google/home/tangd/.m2/repository/javax/jdo/jdo2-api/2.3-eb/jdo2-api-2.3-eb.jar, /usr/local/google/home/tangd/.m2/repository/javax/transaction/transaction-api/1.1/transaction-api-1.1.jar, /usr/local/google/home/tangd/.m2/repository/com/google/http-client/google-http-client-appengine/1.21.0/google-http-client-appengine-1.21.0.jar, /usr/local/google/home/tangd/.m2/repository/com/google/code/findbugs/jsr305/3.0.1/jsr305-3.0.1.jar, /usr/local/google/home/tangd/.m2/repository/io/swagger/swagger-models/1.5.9/swagger-models-1.5.9.jar, /usr/local/google/home/tangd/.m2/repository/org/slf4j/slf4j-api/1.6.3/slf4j-api-1.6.3.jar, /usr/local/google/home/tangd/.m2/repository/io/swagger/swagger-annotations/1.5.9/swagger-annotations-1.5.9.jar, /usr/local/google/home/tangd/.m2/repository/io/swagger/swagger-core/1.5.9/swagger-core-1.5.9.jar, /usr/local/google/home/tangd/.m2/repository/org/apache/commons/commons-lang3/3.2.1/commons-lang3-3.2.1.jar, /usr/local/google/home/tangd/.m2/repository/com/fasterxml/jackson/datatype/jackson-datatype-joda/2.4.5/jackson-datatype-joda-2.4.5.jar, /usr/local/google/home/tangd/.m2/repository/joda-time/joda-time/2.2/joda-time-2.2.jar, /usr/local/google/home/tangd/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.4.5/jackson-dataformat-yaml-2.4.5.jar, /usr/local/google/home/tangd/.m2/repository/org/yaml/snakeyaml/1.12/snakeyaml-1.12.jar, /usr/local/google/home/tangd/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar, /usr/local/google/home/tangd/.m2/repository/org/slf4j/slf4j-nop/1.7.21/slf4j-nop-1.7.21.jar, /usr/local/google/home/tangd/.m2/repository/com/google/endpoints/endpoints-management-control-appengine-all/1.0.4/endpoints-management-control-appengine-all-1.0.4.jar, /usr/local/google/home/tangd/.m2/repository/com/google/appengine/appengine-api-1.0-sdk/1.9.54/appengine-api-1.0-sdk-1.9.54.jar, /usr/local/google/home/tangd/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar, /usr/local/google/home/tangd/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar]:/usr/local/google/home/tangd/code/frankyn/java-docs-samples/appengine/endpoints-frameworks-v2/backend/target/echo-1.0-SNAPSHOT/WEB-INF/classes, -w, /usr/local/google/home/tangd/code/frankyn/java-docs-samples/appengine/endpoints-frameworks-v2/backend/src/main/webapp, -h, spec-test-ruby-samples.appspot.com]

I don't know enough about Maven, but perhaps it is passing in the classpath incorrectly? The tool is expecting it to be formatted in the traditional class path format, so separated by : or ; depending on platform.

loosebazooka commented 7 years ago

That output is confusing because we are converting it using the path separator : https://github.com/GoogleCloudPlatform/endpoints-framework-maven-plugin/blob/master/src/main/java/com/google/cloud/tools/maven/endpoints/framework/OpenApiDocsMojo.java#L66

Lemme see if I messed something up.

loosebazooka commented 7 years ago

What exactly is this dependency for endpoints-management-control-appengine-all I can't seem to find it being brought in transitively though any of the other endpoints dependencies?

tangiel commented 7 years ago

It's decoupled from the endpoints-framework artifacts. It's brought in because it has the EspAuthenticator class and two filters for web.xml.

loosebazooka commented 7 years ago

So this is almost expected behavior?

Do we just need to update the docs to mention that one would need to include this dependency if using EspAuthenticator? Or should we just make it part of the plugin (for both maven AND gradle) classpath by default?

frankyn commented 7 years ago

Following @loosebazooka: @tangiel are there other dependencies under com.google.endpoints that should be included beyond the example presented?

This doesn't really look clean and it begs the question why these dependencies are included in endpoints-framework-tools dependency.

loosebazooka commented 7 years ago

Agree with @frankyn here, @tangiel what are all the necessary dependencies to get it to cover all generation depedencies, I'll add them to the plugin dependencies.

tangiel commented 7 years ago

@loosebazooka the tool and plugin should not have to depend on something that is in the user app's classpath. I think one issue is that the action depend on package, and also -w isn't specified, now that I think of it. So the issue is not with -cp but the lack of -w.

loosebazooka commented 7 years ago

gotcha, lemme play around with frank's sample and try to find out why the maven plugin code isn't pulling in that dependency. Also, @frankyn do you see this issue in gradle?

frankyn commented 7 years ago

No the issue doesn't exist using the Gradle plugin. The sample I shared also support the OpenApi generation plugin its build.gradle. It's documented in the README.md.

Thanks @loosebazooka and @tangiel!

loosebazooka commented 7 years ago

okay, then this is probably on me fixing a bug in the plugin.