使用应用程序发布Spring-RestDocs HTML文档



我有带有Spring-restDocs的Spring-Boot应用程序,我想在该应用程序中创建端点以生成生成的文档。通过生成的HTML文档(通过asciidoctor(暴露端点的最佳方法是什么?

i可以将index.html包含在jar-file中,但真的不知道如何创建端点,以消耗html并在外面曝光。这是在测试阶段和build-jar阶段之前生成的HTML。

官方文档:您可以将创建到静态网站创建的HTML文档发布,也可以将其包装并从应用程序本身提供服务。

例如。我在'build/asctiidoctor/html5'文件夹中有index.html,要创建将返回该index.html的控制器。

根据文档,您可以将构建系统(Maven,Gradle(配置为静态内容,以将HTML打包到Spring-Boot Jar中,以便通过Spring Boot'自动'p>如果Gradle 4.6和Spring Boot 2.0.0.Release:

bootJar {
    dependsOn asciidoctor 
    from ("${asciidoctor.outputDir}/html5") { 
        into 'static/docs'
    }
}

然后可以通过'localhost:<your-port>/<your-context-path/docs/index.html

在本地验证它

使用url http://localhost:8081/docs/api-guide.html在本地访问API指南,添加以下插件:

           <plugin>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <version>${asciidoctor-maven-plugin.version}</version>
            <executions>
                <execution>
                    <id>generate-docs</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>process-asciidoc</goal>
                    </goals>
                    <configuration>
                        <backend>html</backend>
                        <doctype>book</doctype>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.restdocs</groupId>
                    <artifactId>spring-restdocs-asciidoctor</artifactId>
                    <version>${spring-restdocs.version}</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>${maven-resources-plugin.version}</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>post-integration-test</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>`

从ASCIIDOC中生成HTML后,只需将HTML文件复制到target/generated-docs中(请参阅https://spring.io/guides/guides/gs/testing-restdocs/(。然后,Spring-boot将在端点&lt; ...>/doc/index.html。

您可以将maven-resources-plugin用于此作业。

最新更新