How to annotate a field as deprecated in OpenAPI (Swagger) 2.0?
Asked Answered
C

2

93

I have the following schema definition:

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'

I would like to do annotate the location field as deprecated. Is there a way to do this?

Ceram answered 17/4, 2018 at 4:45 Comment(0)
M
129

The possibility to mark schemas and schema properties as deprecated was added in 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    # <---------

If you use OpenAPI 2.0 (Swagger 2.0), the only thing you can do is document the deprecation verbally in the property description.

Marchpane answered 17/4, 2018 at 8:13 Comment(0)
D
33

According to the documentation it is enough to use the deprecated attribute:

paths:
  /pet/findByTags:
    get:
      deprecated: true
Deprecatory answered 28/11, 2018 at 19:56 Comment(2)
He asked for "ttribute", not the endpoint. @Marchpane has a correct anwer: not possible in OpenAPI 2.0Starspangled
@Starspangled while you're correct that this doesn't answer the question, Google will show this as the top result for "swagger service deprecated"Siskind

© 2022 - 2024 — McMap. All rights reserved.