2017-03-31 67 views
3

我們有一個用Java編寫的(用Wildfly託管的)其他API。我們的服務以kubernetes(GKE)運行。我們希望利用雲端點來跟蹤API的使用情況和響應速度。這個API並不是什麼新東西,我們一直在運送與它交互多年的軟件。它也相當大(數千種公共方法)。我們的API有Swagger文檔,並且沒有驗證錯誤。當我嘗試使用我們的Swagger時:谷歌雲終端機構陣列

gcloud beta service-management deploy swagger.yaml 

這並不成功。我碰到下面的錯誤重複237次:

ERROR: unknown location: http: body field path 'body' must be a non-repeated message. 

我已經跟蹤它到237種方法,包括在身體參數JSON數組。在我們的API中,這些是接受或返回對象列表的方法。 有什麼辦法可以讓我接受service-management deploy?改變我們的API不是一種選擇,但我們真的希望能夠使用端點。

例如,這種方法簽名:

@PUT 
@Path ("/foobars/undelete") 
@Consumes (MediaType.APPLICATION_JSON) 
@Produces (MediaType.APPLICATION_JSON) 
@ApiOperation (value = "Undelete foobars") 
@ApiResponses (value = 
{ 
    @ApiResponse (
     code    = 200, 
     message   = "foobars undeleted", 
     response   = FooBar.class, 
     responseContainer = "List" 
    ) , @ApiResponse (
     code    = 206, 
     message   = "Not all foobars undeleted", 
     response   = FooBar.class, 
     responseContainer = "List" 
    ) , @ApiResponse (
     code    = 410, 
     message   = "Not found" 
    ) , @ApiResponse (
     code    = 500, 
     message   = "Server Error" 
    ) 
}) 
public Response undeleteFooBars (@ApiParam (value = "FooBar ID List") List<UUID> entityIds) 

生成此招搖片段:

"/foobars/undelete": 
    put: 
     tags: 
     - foo 
     summary: Undelete FooBars 
     description: '' 
     operationId: undeleteFooBars 
     consumes: 
     - application/json 
     produces: 
     - application/json 
     parameters: 
     - in: body 
     name: body 
     description: FooBar ID List 
     required: false 
     schema: 
      type: array 
      items: 
      type: string 
      format: uuid 
     responses: 
     '200': 
      description: Foo Bars undeleted 
      schema: 
      type: array 
      items: 
       "$ref": "#/definitions/FooBar" 
     '206': 
      description: Not all FooBars undeleted 
      schema: 
      type: array 
      items: 
       "$ref": "#/definitions/FooBar" 
     '410': 
      description: Not found 
     '500': 
      description: Server Error 

回答

2

我曾與端點,完全相同的問題也似乎不能認爲傳遞一個對象數組作爲主體參數有效。我通過使用通用對象和體面的描述來解決這個問題。描述不會以編程方式修復任何內容,但使用通用對象允許端點工作,並且描述爲API的使用者提供了預期內容的信息。

parameters: 
    - in: body 
    name: body 
    description: Array of FooBar objects 
    required: false 
    schema: 
     type: object 

這恕我直言,似乎是在端點隊的疏忽爲使用對象的數組,在格蘭體符合OpenAPI的規範之內罰款和各種工具的工作原理是http://editor.swagger.io/