-
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
swagger-dubbo version | dubbo version | support custom registration dubbo services |
---|---|---|
4.0.0 | 2.7.x | yes |
<dependency>
<artifactId>swagger-dubbo</artifactId>
<groupId>cn.ares.api</groupId>
<version>${swagger-dubbo-project.version}</version>
</dependency>
use @EnableDubboSwagger enable swagger-dubbo
@SpringBootApplication
@EnableDubboSwagger
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
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
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
@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 {
}
}
- referenced project https://github.com/Sayi/swagger-dubbo.git ideas
- method in same class if has the same name, last one is reserved, please modify method name or designation operationId
- use knife ui from project https://github.com/xiaoymin/swagger-bootstrap-ui.git