2015-02-23 54 views
0

你好家伙我有一个swagger-mvc(版本0.9.5)的问题。@ApiModelProperty Swagger-Mvc

我有以下restcontroller:

CanvasController.java(片段)

/** 
* The Class CanvasController. 
*/ 
@Api(description = "Operations for canvases", value="canvascontroller") 
@RestController 
@RequestMapping(value = "/api/canvas") 
public class CanvasController { 


    ... 

    @ApiResponses(value = { 
    @ApiResponse(code = 200, message = "No problem occurred.") 
    }) 
    @ApiOperation(value = "Returns all canvases.", notes = "Returns all canvases.", response = Canvas.class, responseContainer = "List") 
    @RequestMapping(value = {"/all", "", "/"}, method = {  RequestMethod.GET, RequestMethod.POST}, produces = MediaType.APPLICATION_JSON_VALUE) 
    public @ResponseBody ResponseEntity < List <Canvas>> getAll() { 
    return new ResponseEntity < List <Canvas>> (canvasService.findAll(), 
     HttpStatus.OK); 
    } 

} 

Canvas.java

package cloudincubator.canvas.db; 

import java.util.List; 

import javax.persistence.CascadeType; 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.JoinColumn; 
import javax.persistence.ManyToOne; 
import javax.persistence.OneToMany; 
import javax.persistence.Table; 
import javax.persistence.UniqueConstraint; 

import org.codehaus.jackson.annotate.JsonProperty; 

import com.fasterxml.jackson.annotation.JsonIdentityInfo; 
import com.fasterxml.jackson.annotation.ObjectIdGenerators; 
import com.wordnik.swagger.annotations.ApiModel; 
import com.wordnik.swagger.annotations.ApiModelProperty; 

/** 
* The Class Canvas. 
*/ 
@Entity 
@Table(name = "Canvas", uniqueConstraints = {@UniqueConstraint(columnNames = {"C_Id"})}) 
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@canvasId") 
@ApiModel(value = "Canvas", description = "Represents a canvas in the database.") 
public class Canvas 
{ 

    /** The {@link CanvasGroup} to which this Canvas belongs. */ 
    @ManyToOne(optional = true) 
    @JoinColumn(name = "C_Canvas_Group_Id", referencedColumnName = "CG_Id", nullable = true) 
    private CanvasGroup ccanvasgroup; 

    /** The description of this Canvas. */ 
    @Column(name = "C_Description") 
    @ApiModelProperty(value="Description") 
    @JsonProperty("TEST") 
    private String cdescription; 

    /** The x position in the CanvasGroup grid. */ 
    @Column(name = "C_GridX") 
    @ApiModelProperty(value="GridX") 
    private Integer cgridx; 

    /** The y position in the CanvasGroup grid. */ 
    @Column(name = "C_GridY") 
    @ApiModelProperty(value="GridY") 
    private Integer cgridy;  

    /** The height of this Canvas. */ 
    @Column(name = "C_Height") 
    private Integer cheight; 

    /** The path of the icon which belongs to this Canvas. */ 
    @Column(name = "C_Icon") 
    private String cicon; 

    /** The identifier of this Canvas. */ 
    @Id 
    @Column(name = "C_Id", table = "Canvas") 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long cid; 

    /** The name of this Canvas. */ 
    @Column(name = "C_Name") 
    private String cname; 

    /** The shortcut of this Canvas. */ 
    @Column(name = "C_Shortcut") 
    private String cshortcut; 

    /** The {@link Sticker Stickers} which belong to this Canvas. */ 
    @OneToMany(cascade = CascadeType.ALL, mappedBy="scanvas") 
    @Column(nullable = true)  
    private List<Sticker> cstickers; 

    /** The width of this Canvas. */ 
    @Column(name = "C_Width") 
    private Integer cwidth; 

    /** 
    * Instantiates a new Canvas. 
    */ 
    public Canvas(){} 

    /** 
    * Instantiates a new Canvas with the given identifier . 
    * 
    * @param cId : The identifier of this Canvas. 
    */ 
    public Canvas(Long cId) 
    { 
     this.cid = cId; 
    } 

    /** 
    * Instantiates a new Canvas with the given name. 
    * 
    * @param cName : The name of this Canvas. 
    */ 
    public Canvas(String cName) {  
     this.cname = cName; 
    } 

    /* (non-Javadoc) 
    * @see java.lang.Object#equals(java.lang.Object) 
    */ 
    public boolean equals(Object other) { 
     if (this == other) return true; 
     if (!(other instanceof Canvas)) return false; 

     final Canvas canvas = (Canvas) other; 

     if (!canvas.getCId().equals(getCId())) return false;   

     return true; 
    } 

    /** 
    * Gets the {@link CanvasGroup} to which this Canvas belongs. 
    * 
    * @return the {@link CanvasGroup}. 
    */ 
// @ApiModelProperty(position=1, required = true, hidden = false, dataType="cloudincubator.canvas.db.CanvasGroup") 
    public CanvasGroup getCCanvasGroup() { 
     return ccanvasgroup; 
    } 

    /** 
    * Gets the description of this Canvas. 
    * 
    * @return the description of this Canvas. 
    */ 
    public String getCDescription() { 
     return cdescription; 
    } 

    /** 
    * Gets the x position in the CanvasGroup grid of this Canvas. 
    * 
    * @return the x position in the CanvasGroup grid of this Canvas. 
    */ 
    public Integer getCGridX() { 
     return cgridx; 
    } 

    /** 
    * Gets the y position in the CanvasGroup grid of this Canvas. 
    * 
    * @return the y position in the Canvasgroup grid of this Canvas. 
    */ 
    public Integer getCGridY() { 
     return cgridy; 
    } 

    /** 
    * Gets the height of this Canvas. 
    * 
    * @return the height of this Canvas. 
    */ 
    public Integer getCHeight() { 
     return cheight; 
    } 

    /** 
    * Gets the path of the icon which belongs to this Canvas. 
    * 
    * @return the icon path of this Canvas. 
    */ 
    public String getCIcon() { 
     return cicon; 
    } 

    /** 
    * Gets the identifier of this Canvas. 
    * 
    * @return the identifier of this Canvas. 
    */ 
    public Long getCId() { 
     return cid; 
    } 

    /** 
    * Gets the name of this Canvas. 
    * 
    * @return the name of this Canvas. 
    */ 
    public String getCName() { 
     return cname; 
    } 

    /** 
    * Gets the shortcut of this Canvas. 
    * 
    * @return the shortcut of this Canvas. 
    */ 
    public String getCShortcut() { 
     return cshortcut; 
    } 

    /** 
    * Gets the {@link Sticker Stickers} which belong to this Canvas. 
    * 
    * @return the {@link Sticker Stickers} which belong to this Canvas. 
    */ 
    public List<Sticker> getCStickers() 
    { 
     return cstickers; 
    } 

    /** 
    * Gets the width of this Canvas. 
    * 
    * @return the width of this Canvas. 
    */ 
    public Integer getCWidth() { 
     return cwidth; 
    } 

    /* (non-Javadoc) 
    * @see java.lang.Object#hashCode() 
    */ 
    public int hashCode() {   
     return getCId().hashCode(); 
    } 


    /** 
    * Sets the {@link CanvasGroup} to which this Canvas belongs. 
    * 
    * @param cCanvasGroup : The {@link CanvasGroup} to set. 
    */ 
    public void setCCanvasGroup(CanvasGroup cCanvasGroup) { 
     ccanvasgroup = cCanvasGroup; 
    } 

    /** 
    * Sets the description of this Canvas. 
    * 
    * @param cDescription : The description to set. 
    */ 
    public void setCDescription(String cDescription) { 
     cdescription = cDescription; 
    } 

    /** 
    * Sets the x position in the CanvasGroup grid. 
    * 
    * @param cGridX : The x position to set. 
    */ 
    public void setCGridX(Integer cGridX) { 
     cgridx = cGridX; 
    } 

    /** 
    * Sets the y position in the CanvasGroup grid. 
    * 
    * @param cGridY : The y position to set. 
    */ 
    public void setCGridY(Integer cGridY) { 
     cgridy = cGridY; 
    } 

    /** 
    * Sets the height of this Canvas. 
    * 
    * @param cHeight : The height to set. 
    */ 
    public void setCHeight(Integer cHeight) { 
     cheight = cHeight; 
    } 

    /** 
    * Sets the icon path of this Canvas. 
    * 
    * @param cIcon : The icon path to set. 
    */ 
    public void setCIcon(String cIcon) { 
     cicon = cIcon; 
    } 

    /** 
    * Sets the identifier of this Canvas. 
    * 
    * @param cid : The identifier to set. 
    */ 
    public void setCId(Long cid) 
    { 
     this.cid = cid; 
    } 

    /** 
    * Sets the name of this Canvas. 
    * 
    * @param cName : The name to set 
    */ 
    public void setCName(String cName) { 
     cname = cName; 
    } 

    /** 
    * Sets the shortcut of this Canvas. 
    * 
    * @param cShortcut : The shortcut to set 
    */ 
    public void setCShortcut(String cShortcut) { 
     cshortcut = cShortcut; 
    } 

    /** 
    * Sets the {@link Sticker Stickers} which belong to this Canvas. 
    * 
    * @param cStickers : The list of {@link Sticker Stickers} to set. 
    */ 
    public void setCStickers(List<Sticker> cStickers) 
    { 
     this.cstickers = cStickers; 
    } 

    /** 
    * Sets the width of this Canvas. 
    * 
    * @param cWidth : The width to set. 
    */ 
    public void setCWidth(Integer cWidth) { 
     cwidth = cWidth; 
    } 
} 

招摇输出

{ 
    "apiVersion": "1.0", 
    "swaggerVersion": "1.2", 
    "basePath": "/", 
    "resourcePath": "/api/canvas", 
    "produces": [ 
     "application/json" 
    ], 
    "consumes": [ 
     "application/json" 
    ], 
    "apis": [ 
     { 
      "path": "/api/canvas", 
      "description": "getAll", 
      "operations": [ 
       { 
        "method": "GET", 
        "summary": "Returns all canvases.", 
        "notes": "Returns all canvases.", 
        "nickname": "getAll", 
        "produces": [ 
         "application/json" 
        ], 
        "consumes": [ 
         "application/json" 
        ], 
        "parameters": [], 
        "responseMessages": [ 
         { 
          "code": 200, 
          "message": "No problem occurred.", 
          "responseModel": "List" 
         }, 
         { 
          "code": 401, 
          "message": "Unauthorized" 
         }, 
         { 
          "code": 403, 
          "message": "Forbidden" 
         }, 
         { 
          "code": 404, 
          "message": "Not Found" 
         } 
        ], 
        "deprecated": "false", 
        "type": "Canvas" 
       }, 
       { 
        "method": "POST", 
        "summary": "Returns all canvases.", 
        "notes": "Returns all canvases.", 
        "nickname": "getAll", 
        "produces": [ 
         "application/json" 
        ], 
        "consumes": [ 
         "application/json" 
        ], 
        "parameters": [], 
        "responseMessages": [ 
         { 
          "code": 200, 
          "message": "No problem occurred.", 
          "responseModel": "List" 
         }, 
         { 
          "code": 201, 
          "message": "Created" 
         }, 
         { 
          "code": 401, 
          "message": "Unauthorized" 
         }, 
         { 
          "code": 403, 
          "message": "Forbidden" 
         }, 
         { 
          "code": 404, 
          "message": "Not Found" 
         } 
        ], 
        "deprecated": "false", 
        "type": "Canvas" 
       } 
      ] 
     }, 
     { 
      "path": "/api/canvas/", 
      "description": "getAll", 
      "operations": [ 
       { 
        "method": "GET", 
        "summary": "Returns all canvases.", 
        "notes": "Returns all canvases.", 
        "nickname": "getAll", 
        "produces": [ 
         "application/json" 
        ], 
        "consumes": [ 
         "application/json" 
        ], 
        "parameters": [], 
        "responseMessages": [ 
         { 
          "code": 200, 
          "message": "No problem occurred.", 
          "responseModel": "List" 
         }, 
         { 
          "code": 401, 
          "message": "Unauthorized" 
         }, 
         { 
          "code": 403, 
          "message": "Forbidden" 
         }, 
         { 
          "code": 404, 
          "message": "Not Found" 
         } 
        ], 
        "deprecated": "false", 
        "type": "Canvas" 
       }, 
       { 
        "method": "POST", 
        "summary": "Returns all canvases.", 
        "notes": "Returns all canvases.", 
        "nickname": "getAll", 
        "produces": [ 
         "application/json" 
        ], 
        "consumes": [ 
         "application/json" 
        ], 
        "parameters": [], 
        "responseMessages": [ 
         { 
          "code": 200, 
          "message": "No problem occurred.", 
          "responseModel": "List" 
         }, 
         { 
          "code": 201, 
          "message": "Created" 
         }, 
         { 
          "code": 401, 
          "message": "Unauthorized" 
         }, 
         { 
          "code": 403, 
          "message": "Forbidden" 
         }, 
         { 
          "code": 404, 
          "message": "Not Found" 
         } 
        ], 
        "deprecated": "false", 
        "type": "Canvas" 
       } 
      ] 
     } 
    ], 
    "models": { 
     "ResponseEntity": { 
      "description": "", 
      "id": "ResponseEntity", 
      "properties": { 
       "headers": { 
        "required": false, 
        "type": "HttpHeaders" 
       }, 
       "body": { 
        "required": false, 
        "type": "object" 
       }, 
       "statusCode": { 
        "enum": [ 
         "100", 
         "101", 
         "102", 
         "103", 
         "200", 
         "201", 
         "202", 
         "203", 
         "204", 
         "205", 
         "206", 
         "207", 
         "208", 
         "226", 
         "300", 
         "301", 
         "302", 
         "302", 
         "303", 
         "304", 
         "305", 
         "307", 
         "308", 
         "400", 
         "401", 
         "402", 
         "403", 
         "404", 
         "405", 
         "406", 
         "407", 
         "408", 
         "409", 
         "410", 
         "411", 
         "412", 
         "413", 
         "413", 
         "414", 
         "414", 
         "415", 
         "416", 
         "417", 
         "418", 
         "419", 
         "420", 
         "421", 
         "422", 
         "423", 
         "424", 
         "426", 
         "428", 
         "429", 
         "431", 
         "500", 
         "501", 
         "502", 
         "503", 
         "504", 
         "505", 
         "506", 
         "507", 
         "508", 
         "509", 
         "510", 
         "511" 
        ], 
        "required": false, 
        "type": "string" 
       } 
      } 
     }, 
     "Canvas": { 
      "description": "Represents a canvas in the database.", 
      "id": "Canvas", 
      "properties": {} 
     }, 
     "Void": { 
      "description": "", 
      "id": "Void", 
      "properties": {} 
     } 
    } 
} 

我的问题是THA t swagger不会从canvas类中返回api模型属性,如你在swagger输出中看到的那样 我希望你们可以帮助我。

在此先感谢。

+0

我看到一些问题。一个你的动作只能用get来注释。其次,您可以尝试的一件事是在'''@ ApiOperation''注释中删除''''response'''''''responseContainer'''属性,看看它是否有帮助。我怀疑这可能是一个错误 – 2015-02-23 22:10:00

+0

感谢您的答复。不幸的是,我已经尝试删除响应和responseContainer,但它不成功。 – Hans 2015-02-23 22:48:30

回答

1

问题的原因是:在其他java文件中存在具有相同名称的注释。您可以在@ApiModel("Name")中查找,并查看注释是否存在于其他文件中。

相关问题