如何在OpenAPI(Swagger)2.0中将字段标记为已弃用?

83

我有以下模式定义:

swagger: '2.0'
...
definitions:
  Service:
    type: object
    properties:
      serviceId:
        type: string
        description: Device or service identification number
        example: 1111111111      
      location:
        type: string
        description: Location of the service
        example: '400 Street name, City State postcode, Country'

我想将location字段标记为已弃用,有什么方法可以实现吗?

2个回答

115

在 OpenAPI 3.0 中,可以将模式和模式属性标记为deprecated

openapi: 3.0.1
...
components:
  schemas:
    Service:
      type: object
      properties:
        location:
          type: string
          description: Location of the service
          example: '400 Street name, City State postcode, Country'
          deprecated: true    # <---------

如果您使用的是OpenAPI 2.0(Swagger 2.0),您可以做的唯一事情就是在属性 description 中口头记录弃用信息。


30
根据文档,只需使用deprecated属性即可。
paths:
  /pet/findByTags:
    get:
      deprecated: true

10
他要求的是“属性”,而不是端点。@Helen给出了正确的答案:在OpenAPI 2.0中不可能实现。 - Samoht
1
@Samoht,虽然您说得没错,但这并没有回答问题,谷歌会将此作为“swagger service deprecated”的顶部结果显示。 - tharkay

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接