加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java-swagger-maven-plugin不为单个请求映射生成“paths”元素

发布时间:2020-12-15 01:34:32 所属栏目:大数据 来源:网络整理
导读:我有一个简单的端点,我想用swagger-maven-plugin处理.生成的swagger.conf不能反映单个@ApiOperations的正确“paths:”. api的根是“/ api”,我想将GET和PUT的端点添加到“/ api / cluster”.相反,swagger.json输出的“paths:”子句是“/ api”. 这是.java

我有一个简单的端点,我想用swagger-maven-plugin处理.生成的swagger.conf不能反映单个@ApiOperations的正确“paths:”. api的根是“/ api”,我想将GET和PUT的端点添加到“/ api / cluster”.相反,swagger.json输出的“paths:”子句是“/ api”.

这是.java源代码,类上有@Api(value =“/ api”)和@RequestMapping(value =“/ api”),带有@RequestMapping(value =“/ cluster”)的入口点:

ClusterManagerController.java:

    package com.vmturbo.clustermgr;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.Path;
import java.io.OutputStream;
import java.util.Map;
import java.util.Set;

/**
 * REST endpoint for ClusterMgr,exposing APIs for component status,component configuration,node configuration.
 **/
@Component
@RestController
@Api(value = "/api",description = "Methods for managing the Ops Manager Cluster")
@RequestMapping(value="/api",produces = {MediaType.APPLICATION_JSON_VALUE,MediaType.TEXT_PLAIN_VALUE})
public class ClusterMgrController {

    @Autowired
    private ClusterMgrService clusterMgrService;

    /**
     * Get a dump of the current Cluster Configuration
     *
     * @return a {@link com.vmturbo.clustermgr.ClusterMgrService.ClusterConfiguration} object containing known components,* components associated with each node,and property key/value maps for each component.
     */
    @ApiOperation(value = "Get a dump of the current cluster configuration")
    @RequestMapping(path = "/cluster",method = RequestMethod.GET)
    @ResponseBody
    public ClusterMgrService.ClusterConfiguration getClusterConfiguration() {
        return clusterMgrService.getClusterConfiguration();
    }

    /**
     * Replace the current Cluster Configuration with a new one.
     *
     * @return the new Cluster configuration,read back from the key/value store.
     */
    @ApiOperation(value = "Replace the current Cluster Configuration with a new one.")
    @RequestMapping(path = "/cluster",method = RequestMethod.PUT)
    @ResponseBody
    public ClusterMgrService.ClusterConfiguration setClusterConfiguration(
            @RequestBody ClusterMgrService.ClusterConfiguration newConfiguration) {
        return clusterMgrService.setClusterConfiguration(newConfiguration);
    }
}

并且swagger-maven-plugin的pom.xml子句如下所示:

    

生成的swagger.json显示一个端点“/ api”,带有GET和PUT子句.

{
  "swagger" : "2.0","info" : {
    "description" : "The API for configuration and control of a VMTurbo XL Ops Manager Cluster","version" : "v1","title" : "ClusterMgr REST API"
  },"basePath" : "/","tags" : [ {
    "name" : "api","description" : "Methods for managing the Ops Manager Cluster"
  } ],"schemes" : [ "http","https" ],"paths" : {
    "/api" : {
      "get" : {
        "tags" : [ "api" ],"summary" : "Get a dump of the current cluster configuration","description" : "","operationId" : "getClusterConfiguration","produces" : [ "application/json","text/plain" ],"responses" : {
          "200" : {
            "description" : "successful operation","schema" : {
              "$ref" : "#/definitions/ClusterConfiguration"
            }
          }
        }
      },"put" : {
        "tags" : [ "api" ],"summary" : "Replace the current Cluster Configuration with a new one.","operationId" : "setClusterConfiguration","parameters" : [ {
          "in" : "body","name" : "body","required" : false,"schema" : {
            "$ref" : "#/definitions/ClusterConfiguration"
          }
        } ],"schema" : {
              "$ref" : "#/definitions/ClusterConfiguration"
            }
          }
        }
      }
    }
  },"definitions" : {
    "ClusterConfiguration" : {
      "type" : "object","properties" : {
        "nodes" : {
          "type" : "object","readOnly" : true,"additionalProperties" : {
            "$ref" : "#/definitions/ComponentPropertiesMap"
          }
        }
      }
    },"ComponentPropertiesMap" : {
      "type" : "object"
    }
  }
}

最后,我的swagger-maven-plugin的pom.xml条目:

    
最佳答案
在该方法之前尝试使用以下内容

 @RequestMapping(value = "/cluster",method = RequestMethod.GET)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读