Skip to content

Commit

Permalink
modify json format
Browse files Browse the repository at this point in the history
modify json format
  • Loading branch information
leelance committed Jun 21, 2017
1 parent 93af7ce commit 7cf0bad
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions spring-boot-springfox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.0</version>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.0</version>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-staticdocs</artifactId>
<version>2.6.0</version>
<version>2.6.1</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<script src='/api/lib/jsoneditor.min.js' type='text/javascript'></script>
<script src='/api/lib/marked.js' type='text/javascript'></script>
<script src='/api/lib/swagger-oauth.js' type='text/javascript'></script>
<script src='/api/lang/zh-cn.js' type='text/javascript'></script>

<script src='/api/js/springfox.js' type='text/javascript'></script>
</head>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"swagger":"2.0","info":{"description":"Spring-boot-Springfox Example","version":"2.0","title":"Document Api","contact":{"name":"lance","url":"https://github.com/leelance","email":"[email protected]"},"license":{"name":"Apache License Version 2.0"}},"host":"localhost","basePath":"/","tags":[{"name":"home-controller","description":"Home Controller"},{"name":"index-controller","description":"Index Controller"},{"name":"fox-controller","description":"Fox Controller"}],"paths":{"/api/v1.0/delete/{id}":{"get":{"tags":["index-controller"],"summary":"delete","operationId":"deleteUsingGET_1","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"id","in":"path","description":"id","required":true,"type":"integer","format":"int32"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}}}}},"/api/v1.0/detail/id_{id}":{"get":{"tags":["index-controller"],"summary":"detail","operationId":"detailUsingGET","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"id","in":"path","description":"id","required":true,"type":"integer","format":"int32"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}}}}},"/api/v1.0/home/delete/{id}":{"get":{"tags":["home-controller"],"summary":"delete","operationId":"deleteUsingGET","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"id","in":"path","description":"id","required":true,"type":"integer","format":"int32"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}}}},"delete":{"tags":["fox-controller"],"summary":"remove","operationId":"removeUsingDELETE","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"id","in":"path","description":"id","required":true,"type":"integer","format":"int32"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}}}}},"/api/v1.0/home/findAll":{"get":{"tags":["fox-controller"],"summary":"findAll","operationId":"findAllUsingGET","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"params","in":"query","description":"params","required":false,"type":"object"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}}}}},"/api/v1.0/home/list":{"get":{"tags":["home-controller"],"summary":"list","operationId":"listUsingGET","consumes":["application/json"],"produces":["*/*"],"responses":{"200":{"description":"OK","schema":{"type":"string"}}}}},"/api/v1.0/home/save":{"post":{"tags":["home-controller"],"summary":"save","operationId":"saveUsingPOST","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"id","in":"query","required":false,"type":"integer","format":"int32"},{"name":"text","in":"query","required":false,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}}}}},"/api/v1.0/home/view":{"get":{"tags":["fox-controller"],"summary":"view","operationId":"viewUsingGET","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"name","in":"query","description":"name","required":true,"type":"string"},{"name":"address","in":"query","description":"address","required":true,"type":"array","items":{"type":"string"},"collectionFormat":"multi"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}}}}},"/api/v1.0/list":{"get":{"tags":["index-controller"],"summary":"list","operationId":"listUsingGET_1","consumes":["application/json"],"produces":["*/*"],"responses":{"200":{"description":"OK","schema":{"type":"string"}}}}},"/api/v1.0/save":{"post":{"tags":["index-controller"],"summary":"save","operationId":"saveUsingPOST_1","consumes":["application/json"],"produces":["*/*"],"parameters":[{"name":"id","in":"query","required":false,"type":"integer","format":"int32"},{"name":"text","in":"query","required":false,"type":"string"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}}}}}}}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
Expand All @@ -29,7 +29,7 @@

@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes={SimpleApplication.class, SwaggerConfig.class})
@SpringBootTest(classes={SimpleApplication.class, SwaggerConfig.class})
public class Swagger2MarkupTest {
@Autowired
private WebApplicationContext context;
Expand Down Expand Up @@ -79,10 +79,11 @@ public void createSpringfoxSwaggerJson() throws Exception {
.andExpect(MockMvcResultMatchers.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)){
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger1.json"), StandardCharsets.UTF_8)){
writer.write(swaggerJson);
}
}
Expand Down

0 comments on commit 7cf0bad

Please sign in to comment.