使用@ApiMethod

时间:2015-11-16 23:08:32

标签: java documentation-generation jsondoc

我很确定我在这里遗漏了一些明显的东西,但出于某种原因,当我尝试运行'mvn jsondoc:generate -X'命令时,我不断收到'java.lang.annotation.AnnotationTypeMismatchException'错误

完整错误如下所示:

java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation element public abstract java.lang.String[] org.jsondoc.core.annotation.ApiMethod.path() (Found data of type class java.lang.String[/users/{jsonRepresentation}])
	at sun.reflect.annotation.AnnotationTypeMismatchExceptionProxy.generateException(AnnotationTypeMismatchExceptionProxy.java:57)
	at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:83)
	at com.sun.proxy.$Proxy25.path(Unknown Source)
	at org.jsondoc.core.scanner.builder.JSONDocApiMethodDocBuilder.build(JSONDocApiMethodDocBuilder.java:22)
	at org.jsondoc.core.scanner.DefaultJSONDocScanner.initApiMethodDoc(DefaultJSONDocScanner.java:68)
	at org.jsondoc.core.scanner.AbstractJSONDocScanner.getApiMethodDoc(AbstractJSONDocScanner.java:163)
	at org.jsondoc.core.scanner.AbstractJSONDocScanner.getApiMethodDocs(AbstractJSONDocScanner.java:154)
	at org.jsondoc.core.scanner.AbstractJSONDocScanner.getApiDoc(AbstractJSONDocScanner.java:141)
	at org.jsondoc.core.scanner.AbstractJSONDocScanner.getApiDocs(AbstractJSONDocScanner.java:124)
	at org.jsondoc.core.scanner.AbstractJSONDocScanner.getApiDocsMap(AbstractJSONDocScanner.java:222)
	at org.jsondoc.core.scanner.AbstractJSONDocScanner.getJSONDoc(AbstractJSONDocScanner.java:106)
	at org.jsondoc.JSONDocMojo.execute(JSONDocMojo.java:100)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

我不明白错误的这一部分:

'为注释元素找到错误输入的数据public abstract java.lang.String [] org.jsondoc.core.annotation.ApiMethod.path()'

因为根据文档(http://jsondoc.org/annotations.html#apimethod),'path'应该是String而不是String []?所以它让我很困惑。

我的'UserResource'类看起来像这样:

@Api(name="User Resource", description = "Resource for user Login")
public class UserResource extends ServerResource {

    @ApiMethod(
            path = "/users/{jsonRepresentation}",
            description = "test",
            produces = { "application/*+json" },
            consumes = { "application/*+json" },
            verb=ApiVerb.POST)

    @ApiErrors(apierrors = { @ApiError(code = "3000", description = "City already existing"), @ApiError(code = "9000", description = "Illegal argument") })
    @Post("json")
    public @ApiResponseObject Representation login(@ApiParam(name="jsonRepresentation", paramType = ApiParamType.PATH) JsonRepresentation jsonRepresentation) {

        Representation representation = null;

        try {
            JSONObject jsonObject = jsonRepresentation.getJsonObject();

            String username = jsonObject.getString("username");
            String password = jsonObject.getString("password");

            if (username.equals("test") && password.equals("test")) {
                User foundUser = new User();

                foundUser.setEmail("testEmail@email.com");
                foundUser.setPassword("testPassword");
                foundUser.setUsername("testUsername");

                representation = new JacksonRepresentation<User>(foundUser);
            } else {
                representation = new JacksonRepresentation<Status>(Status.CLIENT_ERROR_UNAUTHORIZED);
            }

        } catch (JSONException jsonException) {

        }

        return representation;
    }
}

我已经在这个工作了几个小时了,我有点迷茫,我不知道我在这里做错了什么。我很确定它与@ApiMethod有关,因为我还在没有@ApiMethod的情况下生成了文档,它似乎运行正常。

哦,我的pom.xml包含这个:

 <build>
        <pluginManagement>
            <plugins>
              <plugin>
                    <groupId>org.jsondoc</groupId>
                    <artifactId>jsondoc-maven-plugin</artifactId>
                    <version>1.2.9</version>
                    <configuration>
                        <version>1.1</version>
                        <basePath>http://localhost:8182</basePath>
                        <packages>
                            <package>com.quieazy.api</package>
                            <package>org.jsondoc.sample.controller</package>
                            <package>org.jsondoc.sample.pojo</package>
                        </packages>
                        <outputFile>/tmp/jsondoc.json</outputFile>
                        <scanner>org.jsondoc.core.scanner.DefaultJSONDocScanner</scanner>
                        <playgroundEnabled>true</playgroundEnabled> <!-- optional -->
                        <displayMethodAs>URI</displayMethodAs> <!-- optional -->
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

我的pom.xml设置可能有问题吗?

提前致谢。

0 个答案:

没有答案