Skip to content

Aresxue/swagger-dubbo-project

Repository files navigation

Swagger Dubbo

  • swagger document for dubbo

  • support swagger-annotations v2 and v3

  • such as io.swagger.v3.oas.annotations.media.Schema and io.swagger.annotations.ApiModel

    recommend use v3

Version

swagger-dubbo version dubbo version support custom registration dubbo services
4.0.0 2.7.x yes

Maven

<dependency>
      <artifactId>swagger-dubbo</artifactId>
	  <groupId>cn.ares.api</groupId>
	  <version>${swagger-dubbo-project.version}</version>
</dependency>

Integration

use @EnableDubboSwagger enable swagger-dubbo

@SpringBootApplication
@EnableDubboSwagger
public class Application {

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

Swagger Html

swagger-ui can be integrated within any container that can host pages

api-docs: http://ip:port/context/swagger-dubbo/api-docs

ui: http://ip:port/context/doc-dubbo.html image.png

Configuration Item Description

swagger:
  dubbo:
     enable: true
     context-path: ares
     doc: swagger-dubbo
     group: dubbo interface document
     application:
       groupId: cn.ares.api
       artifactId: swagger-dubbo
       version: 1.0.0

Cross Domain

@Component
public class CorsFilter implements Filter {

  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    HttpServletResponse res = (HttpServletResponse) response;
    res.addHeader("Access-Control-Allow-Credentials", "true");
    res.addHeader("Access-Control-Allow-Origin", "*");
    res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
    res.addHeader("Access-Control-Allow-Headers",
        "Content-Type,X-CAF-Authorization-Token,sessionToken,X-TOKEN");
    if ("OPTIONS".equals(((HttpServletRequest) request).getMethod())) {
      response.getWriter().println("ok");
      return;
    }
    chain.doFilter(request, response);
  }

  @Override
  public void destroy() {
  }

  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
  }
}

Remark

About

swagger doc for dubbo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published