2017-08-16 121 views
0

我是Spring REST Docs的新手,並使用最新的1.2.1.Release。我有工作RESTful控制器,我有一堆工作測試。現在我正在介紹文檔方面,以便爲即將登場的新開發人員記錄這些文檔。Spring REST Docs生成空索引文件

我已經pom.xml中配置這樣的:

<dependency> 
     <groupId>org.springframework.restdocs</groupId> 
     <artifactId>spring-restdocs-mockmvc</artifactId> 
     <version>1.2.1.RELEASE</version> 
     <scope>test</scope> 
    </dependency> 

和這裏就是構建插件是:

<properties> 
    <snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory> 
</properties> 

<build> 

    <outputDirectory>target/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory> 
    <plugins> 

     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>buildnumber-maven-plugin</artifactId> 
      <version>1.4</version> 
      <executions> 
       <execution> 
        <phase>validate</phase> 
        <goals> 
         <goal>create</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <doCheck>false</doCheck> 
       <doUpdate>false</doUpdate> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>3.1.0</version> 
      <configuration> 
       <archive> 
        <manifest> 
         <addDefaultImplementationEntries>true</addDefaultImplementationEntries> 
        </manifest> 
        <manifestEntries> 
         <Git-Revision>${buildNumber}</Git-Revision> 
        </manifestEntries> 
       </archive> 
       <archiveClasses>true</archiveClasses> 
       <webResources> 
        <!-- in order to interpolate version from pom into appengine-web.xml --> 
        <resource> 
         <directory>${basedir}/src/main/webapp/WEB-INF</directory> 
         <filtering>true</filtering> 
         <targetPath>WEB-INF</targetPath> 
        </resource> 
       </webResources> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.20</version> 
      <configuration> 
       <includes> 
        <include>**/*Documentation.java</include> 
       </includes> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.asciidoctor</groupId> 
      <artifactId>asciidoctor-maven-plugin</artifactId> 
      <version>1.5.5</version> 
      <executions> 
       <execution> 
        <id>generate-docs</id> 
        <phase>prepare-package</phase> 
        <goals> 
         <goal>process-asciidoc</goal> 
        </goals> 
        <configuration> 
         <backend>html</backend> 
         <doctype>book</doctype> 
         <sourceDocumentName>index.adoc</sourceDocumentName> 
         <attributes> 
          <snippets>${snippetsDirectory}</snippets> 
         </attributes> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

     <plugin> 
      <artifactId>maven-resources-plugin</artifactId> 
      <version>3.0.2</version> 
      <executions> 
       <execution> 
        <id>copy-resources</id> 
        <phase>prepare-package</phase> 
        <goals> 
         <goal>copy-resources</goal> 
        </goals> 
        <configuration> 
         <outputDirectory> ${project.build.outputDirectory}/static/docs 
         </outputDirectory> 
         <resources> 
          <resource> 
           <directory> ${project.build.directory}/generated-docs 
           </directory> 
          </resource> 
         </resources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

    </plugins> 
</build> 

而且,我有工作,測試和下/目標我看到用幾個* .adoc文件創建的一些目錄。這很棒。

我有一個/src/main/asciidoc/index.adoc創建,當我做我的構建它是成功的。 index.adoc文件中沒有任何內容,是否必須存在? 因此,一個成功的構建之後,我得到很多 「ADOC」 下的文件:
/MyApp的平臺-WS /目標/生成-片段

我也得到一個文件下 「的index.html」:/ MYAPP -platform-ws/target/generated-docs 但是裏面沒有任何東西......

我有幾個其他控制器,每個控制器都有幾個我將要記錄的方法。這很好。但是,我想找到一些方法,我可以創建多個adoc文件的多個html文件。

Spring REST Docs對我來說確實是新的,我只是想了很多新東西,所以我可以將它發佈到我的團隊。

任何幫助將不勝感激!謝謝!

===============更新1.0 =================

所以,我之前添加的這個插件'asciidoctor'插件。

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.20</version> 
      <configuration> 
       <includes> 
        <include>**/*Documentation.java</include> 
       </includes> 
      </configuration> 
     </plugin> 

是的,我必須包括版本,因爲否則我會得到一個錯誤,這是不存在的,但它仍然是一個成功的構建。但是,現在我的測試都不會運行。

我也改變了我的index.adoc包括以下內容:

[[overview-headers]] 
== Headers 
Every response has the following header(s): 
<h>Organizations</h> 
include::{snippets}/orgs/response-headers.adoc[] 
include::{snippets}/orgs/portal/response-headers.adoc[] 

所以,因爲測試沒有運行,它不添加這些文件。 我也懷疑'response-headers.adoc'也沒有被生成。 測試運行時,我得到了片段。

我想我會在正確的軌道上,如果我可以再次運行測試。我根本沒有跳過測試。

===============更新2.0 =================

我改變了萬無一失的插件實際工作與測試我有:

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.20</version> 
      <configuration> 
       <includes> 
        <include>**/*Test.java</include> 
       </includes> 
      </configuration> 
     </plugin> 

因爲我所有的測試,最終在/*Test.java
所以,這讓我所有的測試執行。

因爲我得到了* .adoc文件不翼而飛的消息,我仔細檢查了該

<properties> 
    <snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory> 
</properties> 

是設置正確的,但我並沒有意識到這一點已被拆掉,所以我重新添加它,我停止收到錯誤消息。

我不記得是否提到過它,但我在index.adoc中添加了詳細信息,然後我終於能夠獲得一個生成的index.html,其中包含內容。

我現在只需要學習更多的AsciiDoctor,我可以更新所有POSTS和PUT以及GET的index.adoc。

回答

0

經過如上詳述的實驗後,我終於得到了這個工作。我只需要配置正確,最後它就可以工作。我現在創建了index.adoc文件和一個使用內容創建的index.html文件。

我現在只需要學習更多的AsciiDoctor,我可以更新所有POSTS和PUT以及GET的index.adoc。