80

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?

Helen
  • 87,344
  • 17
  • 243
  • 314
saeedj
  • 2,179
  • 9
  • 25
  • 38

2 Answers2

110

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.

Helen
  • 87,344
  • 17
  • 243
  • 314
28

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

paths:
  /pet/findByTags:
    get:
      deprecated: true
Helen
  • 87,344
  • 17
  • 243
  • 314
Tomas
  • 1,531
  • 1
  • 16
  • 22
  • 10
    He asked for "ttribute", not the endpoint. @Helen has a correct anwer: not possible in OpenAPI 2.0 – Samoht Jan 18 '19 at 11:03
  • 1
    @Samoht while you're correct that this doesn't answer the question, Google will show this as the top result for "swagger service deprecated" – tharkay Aug 16 '21 at 12:13