【问题标题】:Swagger setting path parameter data typeSwagger 设置路径参数数据类型
【发布时间】:2020-11-30 19:54:06
【问题描述】:

我正在尝试将路径参数设置如下

@PUT
    @Path("{myParam}/myEndpoint")
    @ApiOperation(value = SwaggerApiConst.EVENT)
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiImplicitParams({
        @ApiImplicitParam(dataType = "long", name = "myParam", paramType = "path")
       })
    public Response group( @PathParam("myParam") Long myParam, SomeObj someObj) {

试图将 parentAlarm 的数据类型设置为 long,但它在 swagger.json 文件中显示为整数。

'/myApi/{myParam}/myEndpoint':
    put:
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - type: integer
          name: myEndpoint
          in: path
          required: true
        - name: body
          in: body
          required: true
          schema:
            $ref: '#/definitions/SomeObj'

使用的swagger版本是

<swagger.version>1.5.0</swagger.version>

@ApiImplicitParam 在这里似乎没有效果。有替代品吗?

【问题讨论】:

    标签: java annotations swagger openapi


    【解决方案1】:

    Swagger 仅支持整数和数字数据类型。 Long 指定为 int64,整数指定为 int32。您可以在此处阅读有关数据类型的更多信息 - https://swagger.io/docs/specification/data-models/data-types/

    【讨论】:

    • 但是有没有办法在输出中显示 int64 ?如下使用 ApiImplicitParam 或任何其他注释:“type”:“integer”,“format”:“int64”
    • 这适用于我使用 springfox-swagger 2.9.1。 ApiImplicitParams 和 ApiParam 显示格式 - "type":"integer","format":"int64"。也许您应该尝试使用更高版本的 swagger。
    猜你喜欢
    • 1970-01-01
    • 2020-07-26
    • 2015-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 2019-06-11
    相关资源
    最近更新 更多