如何使用自己的 Swagger 注释?

Ale*_*row 9 java swagger swagger-ui

如何使用我自己的注释来构建 swagger ui 页面。例如,我定义了注释并使用它:

    @PUT
    @MyOwnAnnotationForAdditionalPropInSwagger(value = "Some text")
    @Path( "/{carId}" )
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(
        value = "Updates car info"
    )
    public Response patchItem(@ApiParam(value = "Fields to update") Car item) {
            /*some code*/
    }
Run Code Online (Sandbox Code Playgroud)

之后可能我应该扩展一些类swagger-core并指定扫描我的注释(@MyOwnAnnotationForAdditionalPropInSwagger)。

因此,我想在带有文本的 swagger ui 中看到额外的列。

我怎么能意识到呢?我需要扩展什么课程?

Mar*_*ark 1

swagger 2.0 支持自定义字段,早在 2013 年就有一个 Pull Request ( https://github.com/swagger-api/swagger-node/pull/47 )。

虽然添加自定义字段显然很容易,但由于它们不存在于 Swagger 2.0 规范中,因此 Swagger-UI 默认情况下不会显示它们。

为了让它发挥作用,你必须改变一些事情。

  1. 如果不存在,请在解析器实现中实现所需的注释( swagger-core或)。swagger-php
  2. 克隆并修改swagger-ui以根据需要显示您的自定义字段。

请注意,这样做实际上会违反 swagger json 模式(https://github.com/swagger-api/swagger-spec/blob/master/schemas/v2.0/schema.json)和任何第三方验证器你可能会使用失败。