簡體   English   中英

用於多值地圖Jersey的Swagger API? 可能嗎?

[英]Swagger API for MultivaluedMap Jersey? Is it possible?

是否有可能做API文檔的注解MultivaluedMap使用揚鞭澤西PARAM?

我有一小段這樣的代碼:

/**
 * Method which serves requests of adding {@link StudentGroup} to DB
 * 
 * @param name
 * @param description
 * @return {@link Response}
 * @throws RestServiceException
 */
 @POST
 @Path("/add")
 public Response addStudentGroup(MultivaluedMap<String, String> formParams) throws 
     RestServiceException {
     String name = formParams.getFirst("name");
     String description = formParams.getFirst("description");
     String studentIds = formParams.getFirst("studentIds");

     (...)

}

我想使用@ApiParam使用Swagger和Swagger UI生成帶有文檔數據的JSON

如果我將@ApiParam放在@ApiParam MultivaluedMap<String, String> formParams之前它不起作用。 Swagger無法列出任何參數。

看起來這是Swagger中的一個錯誤 - 我也得到了這種行為。 使用具有兩個類型參數的其他泛型類(如@ApiParam()HashMap)可以正常工作。 可能它會拋出解析器。

我在Swagger bug跟蹤系統為此了一個問題

您也可以在他們的Google群組中詢問他們或者在Freenode #swagger的IRC上找到他們。

目前不支持,但正如Eyal所說,在github問題上打開了一張票,它可能相當容易實現。

我可以像這樣解決這個問題。 我們可以利用Swagger API提供的@APIImplicitParams annoatation來列出MultiValueMap的所有表單元素,並在MultiValueMap本身上使用@APIignore。 嘗試下面的代碼行的東西是否有效。 祝好運。 :)

@ApiOperation(value = "Create a new 'Student' object")
@ApiImplicitParams({
      @ApiImplicitParam(name = "X-ClientId", value = "X-ClientId", required = true, dataType = "String", paramType = "header"),
      @ApiImplicitParam(name = "id", value = "Enter an ID for the student.", dataTypeClass = String.class, paramType = "query"),
      @ApiImplicitParam(name = "name", value = "Enter a Name for the Student.", dataTypeClass = String.class, paramType = "query")
  })
  ResponseEntity addStudent(
      @NotBlank @RequestHeader(value = X_CLIENTID) String headerXclient,
      @ApiIgnore @RequestParam MultiValueMap<String, String> requestParams) {
          StudentRequest request = new StudentRequest(requestParams);

          (... Your Code Implementation ...)
      };

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM