我已经为不需要请求正文的GET请求编写了一个大摇大摆的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 = ...