Browse Source

文档生成

zhoutg 6 years ago
parent
commit
b80d75b655

+ 4 - 0
aipt-service/src/docs/asciidoc/index.adoc

@@ -0,0 +1,4 @@
+include::{generated}/overview.adoc[]
+include::{generated}/paths.adoc[]
+include::{generated}/security.adoc[]
+include::{generated}/definitions.adoc[]

+ 64 - 0
aipt-service/src/test/java/com/diagbot/Swagger2MarkupTest.java

@@ -0,0 +1,64 @@
+package com.diagbot;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.MvcResult;
+
+import java.io.BufferedWriter;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2019/7/23 9:22
+ */
+@WebAppConfiguration
+@RunWith(SpringRunner.class)
+@AutoConfigureRestDocs(outputDir = "build/asciidoc/snippets")
+@SpringBootTest
+@AutoConfigureMockMvc
+public class Swagger2MarkupTest {
+
+    @Autowired
+    private MockMvc mockMvc;
+
+//    @Test
+//    public void testApi() throws Exception {
+//        mockMvc.perform(get("/greeting")
+//                .accept(MediaType.APPLICATION_JSON))
+//                .andDo(document("greetingGet",
+//                        Preprocessors.preprocessResponse(Preprocessors.prettyPrint())))
+//                .andExpect(status().isOk());
+//    }
+
+    @Test
+    public void createSpringfoxSwaggerJson() throws Exception {
+
+        String outputDir = System.getProperty("io.springfox.staticdocs.outputDir");
+        MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs")
+                .accept(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk())
+                .andReturn();
+
+        MockHttpServletResponse response = mvcResult.getResponse();
+        String swaggerJson = response.getContentAsString();
+        Files.createDirectories(Paths.get(outputDir));
+        try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)) {
+            writer.write(swaggerJson);
+        }
+    }
+}