是否有关于api类(docs maven目标)中多维数组的发音的解决方法?

时间:2012-08-16 16:28:20

标签: java rest maven-2 enunciate

当运行maven插件的文档目标时,我遇到错误“对多维数组没有支持”。有没有办法可以避免它轰炸过程(即为API生成其余的文档)?

我在API方法上尝试了@ org.codehaus.enunciate.doc.ExcludeFromDocumentation,返回带有double数组的类。 我已经在带有double数组的类上尝试了@ org.codehaus.enunciate.XmlTransient。

我已经在enunciate文档中看到,这些仅影响它们是否显示在文档上,而不是编译。

我很高兴听到你的任何想法!

感谢。

编辑: 我能做的最好的事情是将项目转储到临时目录,删除所有不需要访问api的模块,删除带有double数组的类,并用String替换REST api的java方法签名的那部分。这允许我至少通过enunciate创建api文档页面并通过javadoc给出描述。但是,我希望有一个更优雅的解决方案,所以如果你知道一个,请分享:)

编辑2: 示例pom:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.company.services.rest.service</groupId>
 <artifactId>service-rest-api</artifactId>
 <packaging>pom</packaging>
 <version>1.1</version>
 <name>service  REST API</name>
 <dependencies>
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>2.2.1.GA</version>
      </dependency>
      <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.4</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>jaxrs-api</artifactId>
        <version>2.2.1.GA</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <version>2.2.1.GA</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>2.2.1.GA</version>
        <exclusions>
          <exclusion>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
          </exclusion>
        </exclusions>
      </dependency>
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-multipart-provider</artifactId>
        <version>2.2.1.GA</version>
      </dependency> 
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>tjws</artifactId>
        <version>2.2.1.GA</version>
      </dependency>
  </dependencies>
  <build>
    <plugins>
     <plugin>
       <groupId>org.codehaus.enunciate</groupId>
       <artifactId>maven-enunciate-plugin</artifactId>
       <version>1.26</version>
       <configuration>
         <forceWarPackaging>false</forceWarPackaging>
         <configFile>/tmp/enunciate-work/enunciate.xml</configFile>
       </configuration>
       <executions>
         <execution>
           <goals>
             <goal>docs</goal>
           </goals>
         </execution>
       </executions>
     </plugin>
    </plugins>
  </build>

文件位于src / main / java / com / company / services / user / rest:

package com.company.services.service.rest;

import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

@Path("/")
public interface ServiceResource {
    @POST
    @Path("/statuschanges")
    @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
    @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
    public ServiceStatusChanges getServiceStatusChangeLogs(String string);
}

package com.company.services.service.rest;

import java.io.Serializable;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class ServiceStatusChanges implements Serializable {
    private static final long serialVersionUID = 1l;
    private String[][] logs;
    public ServiceStatusChanges() {}

    public ServiceStatusChanges(String[][] logs) {
        this.logs=logs;
    }

    public String[][] getLogs() {
        return logs;
    }

    public void setLogs(String[][] logs) {
        this.logs=logs;
    }
}

enunciate.xml:

<enunciate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation="
           http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">

  <modules>
      <disable-rule id="csharp.warnings"/>
      <disable-rule id="c.warnings"/>
      <disable-rule id="obj-c.warnings"/>
          <docs docsDir="api" title="REST API" includeDefaultDownloads="false" disableRestMountpoint="true">

    </docs>
    <!-- Disable all the client generation tools -->
    <basic-app disabled="true" />
    <c disabled="true" />
    <csharp disabled="true" />
    <java-client disabled="true" />
    <jaxws-client disabled="true" />
    <jaxws-ri disabled="false" />
    <jaxws-support disabled="false" />
    <jersey disabled="true" />
    <obj-c disabled="true" />
    <xml forceExampleJson="true"/>
    <jaxws disabled="false"/>
    <amf disabled="true"/>
  </modules>

</enunciate>

2 个答案:

答案 0 :(得分:0)

如果您不需要该方法的XML支持,则可以在从@Consumes和@Produces中删除MediaType.APPLICATION_XML之后执行JSON并删除@XmlRootElement注释。

如果您仍然希望支持XML,则可以进行一些增强以支持仅序列化更改,例如使logs属性XML瞬态化并将数组包装为序列化时间。这将具有Enunciate能够记录它而不是一些带外文档的额外好处。 E.g:

@XmlRootElement
public class ServiceStatusChanges implements Serializable {
    private static final long serialVersionUID = 1l;
    private String[][] logs;
    public ServiceStatusChanges() {}

    public ServiceStatusChanges(String[][] logs) {
        this.logs=logs;
    }

    @XmlTransient
    public String[][] getLogs() {
        return logs;
    }

    public void setLogs(String[][] logs) {
        this.logs=logs;
    }

    @XmlElement( name = "logs" )
    public Log[] getLogsWrapped() {
        Log[] logs = new Log[this.logs.length];
        //iterate through the logs and wrap it...
        return logs;
    }
}

您的Log课程可能如下:

@XmlRootElement
public class Log implements Serializable {
    @XmlValue
    public String value;
}

答案 1 :(得分:0)

当我使用List<String[]>类型而不是String[][]时,使用文档生成生存。据我记得生成的JSON / XML示例和xsd似乎有问题。