Skip to content

Commit 9b4b4b5

Browse files
committed
Server:优化返回 Swagger 文档的示例接口,直接返回字符串来替代一张表
1 parent 121afde commit 9b4b4b5

File tree

1 file changed

+65
-4
lines changed
  • APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/demo/server

1 file changed

+65
-4
lines changed

APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/demo/server/Controller.java

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@
4646
import org.springframework.web.bind.annotation.RequestBody;
4747
import org.springframework.web.bind.annotation.RequestMapping;
4848
import org.springframework.web.bind.annotation.RequestParam;
49-
import org.springframework.web.bind.annotation.ResponseBody;
5049
import org.springframework.web.bind.annotation.RestController;
5150
import org.springframework.web.client.RestTemplate;
5251

53-
import com.alibaba.fastjson.JSONArray;
5452
import com.alibaba.fastjson.JSONObject;
5553

5654
import apijson.demo.server.model.BaseModel;
@@ -987,6 +985,7 @@ public String delegate(@RequestParam("$_delegate_url") String url, @RequestBody
987985
headers.add(name, request.getHeader(name));
988986
}
989987

988+
@SuppressWarnings("unchecked")
990989
List<String> cookie = session == null ? null : (List<String>) session.getAttribute("Cookie");
991990
if (cookie != null && cookie.isEmpty() == false) {
992991
List<String> c = headers.get("Cookie");
@@ -1019,9 +1018,71 @@ public String delegate(@RequestParam("$_delegate_url") String url, @RequestBody
10191018
return entity.getBody();
10201019
}
10211020

1021+
1022+
/**Swagger 文档 Demo,供 APIAuto 测试导入 Swagger 文档到数据库用
1023+
* @return
1024+
*/
10221025
@GetMapping("v2/api-docs")
1023-
public JSONObject swaggerAPIDocs() {
1024-
return new DemoParser().parseResponse(new JSONRequest("Swagger", new JSONRequest())).getJSONObject("Swagger");
1026+
public String swaggerAPIDocs() {
1027+
return "{\n"+
1028+
" \"paths\": {\n"+
1029+
" \"/user/list\": {\n"+
1030+
" \"get\": {\n"+
1031+
" \"summary\": \"用户列表\",\n"+
1032+
" \"parameters\": [\n"+
1033+
" {\n"+
1034+
" \"name\": \"pageSize\",\n"+
1035+
" \"description\": \"每页数量\",\n"+
1036+
" \"default\": 10\n"+
1037+
" },\n"+
1038+
" {\n"+
1039+
" \"name\": \"page\",\n"+
1040+
" \"default\": 1\n"+
1041+
" },\n"+
1042+
" {\n"+
1043+
" \"name\": \"searchKey\",\n"+
1044+
" \"description\": \"搜索关键词\",\n"+
1045+
" \"default\": \"a\"\n"+
1046+
" }\n"+
1047+
" ]\n"+
1048+
" }\n"+
1049+
" },\n"+
1050+
" \"/user\": {\n"+
1051+
" \"get\": {\n"+
1052+
" \"summary\": \"用户详情\",\n"+
1053+
" \"parameters\": [\n"+
1054+
" {\n"+
1055+
" \"name\": \"id\",\n"+
1056+
" \"description\": \"主键\",\n"+
1057+
" \"default\": 82001\n"+
1058+
" }\n"+
1059+
" ]\n"+
1060+
" }\n"+
1061+
" },\n"+
1062+
" \"/comment/post\": {\n"+
1063+
" \"post\": {\n"+
1064+
" \"summary\": \"新增评论\",\n"+
1065+
" \"parameters\": [\n"+
1066+
" {\n"+
1067+
" \"name\": \"userId\",\n"+
1068+
" \"description\": \"用户id\",\n"+
1069+
" \"default\": 82001\n"+
1070+
" },\n"+
1071+
" {\n"+
1072+
" \"name\": \"momentId\",\n"+
1073+
" \"description\": \"动态id\",\n"+
1074+
" \"default\": 15\n"+
1075+
" },\n"+
1076+
" {\n"+
1077+
" \"name\": \"conent\",\n"+
1078+
" \"description\": \"内容\",\n"+
1079+
" \"default\": \"测试评论\"\n"+
1080+
" }\n"+
1081+
" ]\n"+
1082+
" }\n"+
1083+
" }\n"+
1084+
" }\n"+
1085+
"}";
10251086
}
10261087

10271088
}

0 commit comments

Comments
 (0)