Coder Social home page Coder Social logo

huan-swagger's Introduction

huan-swagger

项目描述

由于考虑到大家的使用情况,结合网上 swagger-ui-layer的封装情况 现把 swagger-layui 分为 微服务版,单服务版。目前只支持 RestController

1)微服务版本:微服务与 layui 分离,layui 部署到新服务器上,供各个服务使用

    demo例子:http://106.12.9.238:8080/webjars/swagger-ui/index.html#106.12.9.238:8081

2)单服务版本:layui 部署在服务上,即插即用,非常方便

项目结构

huan-swagger-core swagger核心组件封装

swagger-ui-layer 单服务版本:供单服务即插即用

huan-swagger-ui 微服务版本:swagger UI页面,作为一个第三方服务来渲染接口,用来渲染远程服务器的接口说明 (aa.com)

spring-boot-demo swagger 微服务测试页面 (bb.com)

spring-mvc-demo swagger spring mvc单服务测试页面 (bb.com)

微服务访问形式:http://aa.com/webjars/swagger-ui/index.html#http://bb.com

微服务demo实例:http://106.12.9.238:8080/webjars/swagger-ui/index.html#106.12.9.238:8081

使用说明(spring boot)

一、微服务版本:

1、部署到服务器上:huan-swagger-ui项目

2、微服务项目修改

1) pom依赖

   <dependency>
       <groupId>com.github.huanshare</groupId>
       <artifactId>huan-swagger-core</artifactId>
       <version>1.0.1</version>
   </dependency>

2) spring boot项目启动项添加:

@EnableHuanSwagger

3) application.yml配置 (可选项配置)

 # Swagger设置  enable 默认为true,为false时,关闭接口展示
 swagger:
   enable: true,
   version: 版本号
   title: 项目标题
   description: 项目描述
   contact:
     name: 用户名
     url: url地址
     mail: 邮箱

3、页面访问:UI服务器地址/webjars/swagger-ui/index.html#API-服务器地址

4、具体使用方式,请参考 huan-swagger-test

二、单服务版本:

1、服务项目修改

1) pom依赖

 <dependency>
   <groupId>com.github.huanshare</groupId>
   <artifactId>swagger-ui-layer</artifactId>
   <version>1.0.0</version>
 </dependency>

2) spring boot项目启动项添加:

     @EnableHuanSwagger

3) application.yml配置 (可选项配置)

  # Swagger设置  enable 默认为true,为false时,关闭接口展示
  swagger:
    enable: true,
    version: 版本号
    title: 项目标题
    description: 项目描述
    contact:
      name: 用户名
      url: url地址
      mail: 邮箱

3、页面访问:UI服务器地址/api-doc.html

三、修改首页图标:根目录/logo.png(将图片地址映射到根目录下进行访问)

使用说明(spring mvc)

1、微服务版本:API需要在 添加pom依赖,需要手动解决跨域问题,具体可参考 spring-mvc-demo中的CORSFilter与web.xml中的跨域配置, 可参考 spring-mvc-demo---》CORSFilter

1) pom依赖

    <dependency>
       <groupId>com.github.huanshare</groupId>
       <artifactId>huan-swagger-core</artifactId>
       <version>1.0.1</version>
   </dependency>

2) Bean注入,Filter配置

    @Configuration
    @EnableHuanSwagger
    @EnableWebMvc
    public class CORSFilter implements Filter {
    
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
            HttpServletResponse response = (HttpServletResponse) res;
            response.setHeader("Access-Control-Allow-Origin", "*");
            response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
            response.setHeader("Access-Control-Max-Age", "3600");
            response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
            chain.doFilter(req, res);
        }
    }

3) web.xml中配置过滤器

    <filter>
        <filter-name>cors</filter-name>
        <filter-class>com.huanshare.springMvcDemo.config.CORSFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>cors</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

2、单服务版本:添加pom依赖,注入各种Bean,可参考 spring-mvc-demo --》MySwaggerConfig

1) pom依赖

    <dependency>
      <groupId>com.github.huanshare</groupId>
      <artifactId>swagger-ui-layer</artifactId>
      <version>1.0.0</version>
    </dependency>

2) Bean注入

        @Configuration
        @EnableHuanSwagger
        @EnableWebMvc
        public class MySwaggerConfig {
        }

3、修改首页图标:根目录/logo.png(将图片地址映射到根目录下进行访问)

特点

原来看过其他小伙伴的源码,页面交互不算太理想

无论单机版还是微服务版,整体UI在小伙伴基础上做了一些修改,整体内容进行了封装,不需要配置一些额外的选项,即插即用,非常方便

微服务版:实现了API与UI的分离,但是需要为UI单独部署一套服务器,增加了其他成本;如果微服务多的话,这也算是个不错的方案

单服务版:简单配置,即插即用,非常方便

    小伙伴的地址(https://github.com/ohcomeyes/swagger-ui-layer )

huan-swagger's People

Contributors

huanshare avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.