2012-06-19 31 views
9

當前Enunciate生成REST API文檔,但響應主體不包含有關響應的JSON結構的信息。在我的理解中,如果我包含帶有Jersey到JSON序列化/反序列化的數據實體的類,則闡明將能夠生成該部分文檔。如何在由Enunciate生成的文檔中包含JSON Response Body的格式?

數據實體在不同的模塊,封裝,其來源爲字正腔圓文檔中的建議 - Multi-Module Projects

... 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-source-plugin</artifactId> 
    <version>2.1.2</version> 
    <executions> 
     <execution> 
      <id>attach-sources</id> 
      <phase>package</phase> 
      <goals> 
       <goal>jar</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
... 

這是我enunciate.xml的樣子:

<?xml version="1.0"?> 
<enunciate label="someapi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.25.xsd"> 

    <api-import pattern="com.something.business.vo.**"/> 
    <api-import pattern="com.something.business.domain.**"/> 

    <api-classes> 
     <include pattern="com.something.web.ssoApi.rest.*"/> 
     <include pattern="com.something.business.vo.**"/> 
     <include pattern="com.something.business.domain.**"/> 
    </api-classes> 

</enunciate> 

而且文檔這怎麼看起來像:

Documentation Screenshot

正如您所看到的響應正文僅包含element: (custom)

如何使其包含響應的JSON結構?

+1

似乎爲了生成數據模型部分的文檔,實體應該用'@ XmlRoolElement'註釋。這是否正確,或者我可以使用不同的註釋,以便只包含沒有XML的文檔中的JSON? –

+2

''此設置禁止生成xml示例並僅保留JSON。 –

回答

9

爲了生成數據模型部分的文檔,應該使用@XmlRootElement對實體進行註釋。

+0

完美:)謝謝 –

相關問題