如何注释OpenAPI(Swagger)2.0中不推荐使用的字段?

sae*_*edj 13 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'
Run Code Online (Sandbox Code Playgroud)

我想对location已弃用的字段进行注释。有没有办法做到这一点?

Hel*_*len 17

deprecated在OpenAPI 3.0中添加了标记架构和架构属性的可能性:

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    # <---------
Run Code Online (Sandbox Code Playgroud)

如果您使用OpenAPI 2.0(Swagger 2.0),则唯一可以做的就是在属性中以口头形式记录弃用情况description


Tom*_*mas 13

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

/pet/findByTags:
get:
  deprecated: true
Run Code Online (Sandbox Code Playgroud)

  • 他要求的是“ttribute”,而不是终点。@Helen 有一个正确的答案:在 OpenAPI 2.0 中不可能 (7认同)
  • @Samoht,虽然你是正确的,这不能回答问题,但 Google 会将其显示为“swagger service deprecated”的最佳结果 (2认同)