我有一个简单的端点,我想用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)
总结 以上是内存溢出为你收集整理的java-swagger-maven-plugin不为单个请求映射生成“paths”元素全部内容,希望文章能够帮你解决java-swagger-maven-plugin不为单个请求映射生成“paths”元素所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)