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

时间:2018-04-17 04:45:40

标签: swagger swagger-2.0 openapi

我有以下架构定义:

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 个答案:

答案 0 :(得分:9)

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

答案 1 :(得分:0)

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

/pet/findByTags:
get:
  deprecated: true