Swagger - 为什么 Swagger 在我没有为请求主体字段编写注释时创建请求主体字段?

Swagger - Why is Swagger creating a request body field when I have not written an annotation for one?

我已经为不需要请求正文的 GET 请求写了一个 swagger ui。我没有使用 @RequestBody 注释,那么为什么 Swagger 在 ui 上显示请求正文字段?即使我将其留空,它也会导致我的 API 请求失败并出现以下错误:TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

我明白为什么会出现这个错误,swagger 创建的 curl 有一个 -d 选项。但是我怎样才能关闭它?

我使用的唯一注释是 @Get@Path@Operation@ApiResponses@Parameters

简而言之,我如何告诉 swagger 我不需要请求正文?

如果您没有注释方法的某些参数,它会自动被视为请求正文。如果您不想这样做,则必须将其显式注释为其他内容或使用 @ApiParam(hidden = true):

之类的内容对其进行注释以忽略参数
  // example usage of Swagger with Akka HTTP
  @ApiOperation(
    httpMethod = "GET",
    response   = classOf[ApiResponseX],
    value      = "docs"
  )
  @ApiImplicitParams(
    Array(
      new ApiImplicitParam(
        name      = "id",
        dataType  = "string",
        paramType = "query",
        value     = "id docs"
      )
    )
  )
  def fetchX(
    // even if this value has custom handling I have to explicitly ignore it,
    // to not make it into a request body
    @ApiParam(hidden = true) id: UUID
  ): Route = ...