Search code examples
javamavengoogle-app-enginegoogle-cloud-endpoints

mvn endpoints-framework:openApiDocs does not read parameters


I've been experimenting with GAE Endpoint framework, and on of the steps in the tutorial says to execute this maven command:

mvn endpoints-framework:openApiDocs

From what I understand, this command would produce the OpenAPI docs and the prompt the location of the file at the end. However, it seems to be unable to read the parameters that maven is passing to it, and prints the usage statement instead, like below:

[INFO] --- endpoints-framework-maven-plugin:1.0.2:openApiDocs (default-cli) @ demoapp ---
[INFO] Endpoints Tool params : [get-openapi-doc, -o, C:\projects\demoapp-backend\target\openapi-docs\openapi.json, -cp,C:\..., -w, C:\projects\demoapp-backend\src\main\webapp, -h, demo-app.appspot.com]
get-openapi-doc

Generates an OpenAPI document

Usage: <Endpoints tool> get-openapi-doc <options> <service class>...

Options:
  -cp CLASSPATH, --classpath=CLASSPATH
    Lets you specify the service class or classes from a path other than the
    default <war-directory>/WEB-INF/libs and <war-directory>/WEB-INF/classes,
    where <war-directory is the directory specified in the war option, or simply
    ./war if that option is not supplied.
  -o OUTPUT_FILE, --output=OUTPUT_FILE
    Sets the file where output will be written to. Default: ./openapi.json
  -w WAR_PATH, --war=WAR_PATH
    Sets the path to the war directory where web-appengine.xml and other
    metadata are located. Default: ./war.
  -h HOSTNAME, --hostname=HOSTNAME
    Sets the hostname for the generated document. Default is the app's default
    hostname.
  -p BASE_PATH, --path=BASE_PATH
    Sets the base path for the generated document. Default is /_ah/api.

Example:
  <Endpoints tool> get-openapi-doc com.google.devrel.samples.ttt.spi.BoardV1 com.google.devrel.samples.ttt.spi.ScoresV1

I've truncated the classpath to make reading and posting the output easier. Has anyone else encountered this problem? Some pointers would be much appreciated.


Solution

  • The problem was because the web.xml was missing the endpoint servlet mapping.

    <servlet>
            <servlet-name>EndpointsServlet</servlet-name>
            <servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
            <init-param>
                <param-name>services</param-name>
                <param-value>com.example.demoapp.Echo</param-value>
            </init-param>
    </servlet>
    

    I traced it down by making sure the pom was identical to a project where the mvn endpoints-framework:openApiDocs command was working, and from there copied over the source folder into the working project. The command failed as soon as the src folder was copied, and from there it took some clever trial and errors to figure out which of the configuration xmls that was the problem.

    Regardless, was this servlet mapping and the side-effect of it being missing documented anywhere?