导出后的样式
分析
1,swagger2 页面展示实际就是将返回的包含所有接口的json数据(在swagger界面,打开浏览器控制台即可看到该json数据)进行解析,并渲染到页面上。
2,按照java面向对象思路分析,上述表格即为一个接口(一个单元),一共三个对象:Table.java、Request.java、Response.java。
3,将原始swagger2的json数据进行解析、封装成上述三个java对象,然后再通过html渲染即可形成web版API文档。
4,将web版API文档另存为doc文件,即生成了api-doc文件。
实现
1,创建三个java对象
Table.java
package com.eden.yang.apidoc.vo;
import java.util.List;
/**
* @FileName Table.java
* @Description:
*
* @Date 2019年3月18日 下午3:55:27
* @author Eden
* @version 1.0
*/
public class Table {
/**
* 大标题
*/
private String title;
/**
* 小标题
*/
private String tag;
/**
* url
*/
private String url;
/**
* 响应参数格式
*/
private String responseForm;
/**
* 请求方式
*/
private String requestType;
/**
* 请求体
*/
private List<Request> requestList;
/**
* 返回体
*/
private List<Response> responseList;
/**
* 请求参数
*/
private String requestParam;
/**
* 返回值
*/
private String responseParam;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getResponseForm() {
return responseForm;
}
public void setResponseForm(String responseForm) {
this.responseForm = responseForm;
}
public String getRequestType() {
return requestType;
}
public void setRequestType(String requestType) {
this.requestType = requestType;
}
public List<Request> getRequestList() {
return requestList;
}
public void setRequestList(List<Request> requestList) {
this.requestList = requestList;
}
public List<Response> getResponseList() {
return responseList;
}
public void setResponseList(List<Response> responseList) {
this.responseList = responseList;
}
public String getRequestParam() {
return requestParam;
}
public void setRequestParam(String requestParam) {
this.requestParam = requestParam;
}
public String getResponseParam() {
return responseParam;
}
public void setResponseParam(String responseParam) {
this.responseParam = responseParam;
}
}
Request.java
package com.eden.yang.apidoc.vo;
/**
* @FileName Request.java
* @Description:
*
* @Date 2019年3月18日 下午3:56:29
* @author Eden
* @version 1.0
*/
public class Request {
/**
* 请求参数
*/
private String description;
/**
* 参数名
*/
private String name;
/**
* 数据类型
*/
private String type;
/**
* 参数类型
*/
private String paramType;
/**
* 是否必填
*/
private Boolean require;
/**
* 说明
*/
private String remark;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public St