Tag - swagger

swagger 微服务 MicroService    2017-07-19 22:00:07    922

简介,基于Swagger UI其实是纯static的web程序,仅仅在页面加载的时候,调用http连接,获取yaml字符串或者json字符串,这里我将yaml文件和放到静态项目中,并使用tomcat启动,下面来看看怎么做的


1、下载Swagger UI的代码:
    https://github.com/swagger-api/swagger-ui

2、从下载的代码中提取dist文件夹

3、修改dist文件夹下的index.html文件,修改代码
  <script type="text/javascript">
    $(function () {
      var url = window.location.search.match(/url=([^&]+)/);
      if (url && url.length > 1) {
        url = decodeURIComponent(url[1]);
      } else {
        url = "http://petstore.swagger.io/v2/swagger.json";
      }

  <script type="text/javascript">
    var resourceName=window.location.href.split('?')[1];
    $(function () {
      var url = window.location.search.match(/url=([^&]+)/);
      if (url && url.length > 1) {
        url = decodeURIComponent(url[1]);
      } else {
        //url = "http://petstore.swagger.io/v2/swagger.json";
        url="/yaml/"+resourceName+".yaml";
      }
4、找个tomcat,将加入了跨域配置的Java Web项目添加到webapps
    参考文章:http://blog.csdn.net/gsying1474/article/details/49664883
5、在yaml项目中,添加所有的yaml文件到yaml项目根目录下,将dis