Code Monkey home page Code Monkey logo

swagger-dubbo's Introduction

swagger-dubbo

Build Status

Dubbo |ˈdʌbəʊ| 是阿里巴巴提供的分布式框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案。
Swagger围绕着OpenAPI规范,提供了一套设计、构建、文档化rest api的开源工具。

Swagger-dubbo致力于dubbo与swagger文档的集成,并且为dubbo提供rest风格的http调用方案。适用于dubbo服务接口调试、接口http请求模拟、单机验证等场景。

Swagger-UI

快速集成

所有集成都是基于spring配置。swagger v2.0、dubbo2.5.3+。

  1. Maven依赖
<dependency>
  <groupId>com.deepoove</groupId>
  <artifactId>swagger-dubbo</artifactId>
  <version>1.0.3-alpha</version>
</dependency>
  1. 启用swagger-dubbo

使用注解 @EnableDubboSwagger开启dubbo的swagger文档。

package com.deepoove.swagger.dubbo.example;

import org.springframework.context.annotation.Configuration;
import com.deepoove.swagger.dubbo.annotations.EnableDubboSwagger;

@Configuration
@EnableDubboSwagger
public class SwaggerDubboConfig {

}

在spring xml配置中,打开Configuration注解,声明SwaggerDubboConfig。

<context:annotation-config />
<bean class="com.deepoove.swagger.dubbo.example.SwaggerDubboConfig" />
  1. 配置swagger-dubbo

新增property文件swagger-dubbo.properties

在spring xml配置中,加载配置文件。

<context:property-placeholder location="classpath*:swagger-dubbo.properties" />

配置项说明:

#doc地址,默认为http://ip:port/context/swagger-dubbo/swagger.json
#swagger.dubbo.doc=swagger-dubbo
#http请求地址,默认为http://ip:port/h/com.XXX.XxService/method
#swagger.dubbo.http=h

#dubbo 服务版本号
swagger.dubbo.application.version = 1.0
#dubbo服务groupId
swagger.dubbo.application.groupId = com.deepoove
#dubbo服务artifactId
swagger.dubbo.application.artifactId = dubbo.api

#是否启用swagger-dubbo,默认为true
#swagger.dubbo.enable = true
  1. 启动web容器,浏览器访问 http://ip:port/context/swagger-dubbo/swagger.json

示例与集成swagger-ui

示例参见swagger-dubbo-example。

如何集成swagger-ui,参见官方文档 GitHub Swagger UI

swagger-dubbo集成注意事项

  • 对于服务接口方法重载,为了在http请求中唯一确认一个方法,需要使用注解@ApiOperation(nickname = "byArea"),通过nickname标记唯一路径(如果不填写,将只显示一个方法)。此时,rest的请求地址为:http://ip:port/h/com.XXX.XxService/method/byArea Stackoverflow:重载的方法能够映射到同一URL地址吗

  • Object对象作为http请求参数为json string格式。格式不正确会导致解析错误。下一版本考虑参数json格式可视化。 Stackoverflow:POST的方法能够接收多个参数吗?

  • swagger注解既可以写在接口上,也可以写在实现类上。

  • 原生类型作为http请求参数为必填。

swagger-dubbo's People

Contributors

sayi avatar

Watchers

 avatar  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.