swagger 在apache CXF 中的使用——JAX-RS Swagger2Feature

简介:
The CXF Swagger2Feature allows you to generate Swagger 2.0 documents from JAX-RS service endpoints with a simple configuration.
见:http://cxf.apache.org/docs/swagger2feature.html

JAX-RS Swagger2Feature
Demo ================= The demo shows a basic usage of Swagger 2.0 API documentation with REST based Web Services using JAX-RS 2.0 (JSR-339). Swagger UI is available at: http://localhost:9000/ Building and running the demo using Maven --------------------------------------- From the base directory of this sample (i.e., where this README file is located), the Maven pom.xml file can be used to build and run the demo. Using either UNIX or Windows: mvn install mvn -Pserver (from one command line window) After the service is started, the Swagger API documents in JSON and YAML are available at http://localhost:9000/swagger.json http://localhost:9000/swagger.yaml To view the Swagger document using Swagger-UI, use your Browser to open the Swagger-UI page at http://localhost:9000/api-docs?url=/swagger.json or http://localhost:9000/api-docs?url=/swagger.yaml or access it from the CXF Services page: http://localhost:9000/services and follow a Swagger link.

例子在:https://github.com/apache/cxf/blob/master/distribution/src/main/release/samples/jax_rs/description_swagger2/src/main/java/demo/jaxrs/swagger/server/Sample.java

示意代码:

复制代码
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Path("/sample") 
@Api(value = "/sample", description = "Sample JAX-RS service with Swagger documentation")
public class Sample {
    private Map<String, Item> items;

    public Sample() {
        items = Collections.synchronizedMap(new TreeMap<String, Item>(String.CASE_INSENSITIVE_ORDER));
        items.put("Item 1", new Item("Item 1", "Value 1"));
        items.put("Item 2", new Item("Item 2", "Value 2"));
    }
        
    
    @Produces({ MediaType.APPLICATION_JSON })
    @GET
    @ApiOperation(
        value = "Get operation with Response and @Default value", 
        notes = "Get operation with Response and @Default value", 
        response = Item.class, 
        responseContainer = "List"
    )
    public Response getItems(
        @ApiParam(value = "Page to fetch", required = true) @QueryParam("page") @DefaultValue("1") int page) {

        return Response.ok(items.values()).build();
    }
}
复制代码

 













本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6297341.html,如需转载请自行联系原作者

相关文章
|
6月前
|
Java 程序员 API
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
175 1
|
6月前
|
Java API Apache
Apache CXF生成WebService的客户端
Apache CXF生成WebService的客户端
227 0
|
XML Java API
彻底了解|利用Apache CXF框架开发WebService
前言WebService是为了支持网络的机器间操作交互而设计用来开发分布式的交互操作的应用程序组件,通常被定义为一组模块化的API,他们可以通过网络进行调用,来执行远程系统的请求服务,而...
511 0
|
JSON Java 测试技术
Java单元测试之 Apache CXF Restful
对于程序员是否有必要编写test case,何时编写依然存在很多争议,各种互斥的方法论(SE/AM/XP/TDD),以及不同的开发文化,但是可以确定是编写单元测试用例有助于提高编程能力。
810 0
|
前端开发 Java Apache
bboss发布apache cxf 2.7.6服务和定义客户端服务实例可能产生冲突解决办法
bboss发布apache cxf 2.7.6服务和定义客户端服务实例放到一起可能会产生冲突并导致服务发布失败,本文介绍这个冲突的解决办法。 首先介绍一下冲突现象,假设在bboss mvc的xml配置文件中定义一个控制器,并为这个控制器注入通过org.
1321 0
|
测试技术 Apache
bboss支持最新的apache cxf v3.1.0
bboss升级cxf到最新的apache cxf 3.1.0版本,本文介绍应用和平台升级cxf引擎的方法。 1.用户首先要升级到bboss框架的最新版本,版本下载和构建方法请参考文档《bboss项目下载地址》《bboss ant构建方法》 和服务相关的主要包bboss-rpc.jar 2.cxf2.2.4升级到cxf 2.7.6方法 2.1 按照图一所示找出项目的web-inf/lib下与cxf 2.2.4相关的jar文件 找出这些文件并删除。
977 0

推荐镜像

更多