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

7rtdyuoh  于 2023-03-08  发布在  其他
关注(0)|答案(2)|浏览(315)

我有以下模式定义:

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字段注解为deprecated。有什么方法可以做到吗?

6pp0gazn

6pp0gazn1#

在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中口头记录弃用。

7fyelxc5

7fyelxc52#

根据documentation,使用deprecated属性就足够了:

paths:
  /pet/findByTags:
    get:
      deprecated: true

相关问题