2012-08-16 14 views
0

當運行maven插件發佈的docs目標時,我遇到了「沒有支持多維數組」的錯誤。有沒有辦法可以避免它轟炸過程(即爲API生成其他文檔)?是否有解決api類中的多維數組(文檔maven目標)的解決方法?

我已經嘗試了@ org.codehaus.enunciate.doc.ExcludeFromDocumentation方法返回具有雙數組的類。 我試過@ org.codehaus.enunciate.XmlTransient與雙數組的類。

我已經在闡明文檔中看到了那些隻影響它們是否顯示在文檔上而不是編譯的文檔。

我很高興聽到您有任何想法!

謝謝。

編輯: 我可以做的最好的事情是將項目轉儲到臨時目錄,將所有不需要到達api的模塊翻出來,使用雙數組刪除類,並替換REST api的java方法的那部分簽名與字符串。這使我至少可以通過聲明創建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 /公司/業務/用戶/休息:

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> 
+0

沒有項目的細節和更多的細節,很難猜測出什麼問題。 – khmarbaise 2012-08-17 21:06:31

+0

好吧,我已經添加了一個簡單的示例項目,演示了我試圖繞過的已知行爲。 – 2012-08-20 04:56:24

+0

爲什麼你有一個位於Maven項目之外的配置文件?對我來說看起來很奇怪 – khmarbaise 2012-08-20 06:56:22

回答

0

如果您不需要該方法的XML支持,則可以在從@Consumes和@Produces中刪除MediaType.APPLICATION_XML後,執行JSON並刪除@XmlRootElement註釋。

如果您仍想支持XML,則可以進行一些增強以支持僅序列化的更改,例如使logs屬性XML爲瞬態並將數組作爲序列化時間進行封裝。這將具有Enunciate能夠記錄它的額外好處,而不是一些帶外文檔。例如: -

@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; 
} 
0

字正腔圓文檔一代倖存當我用List<String[]>類型,而不是String[][]。據我記得生成的JSON/XML示例和xsd似乎有問題。

相關問題