Код IT
← Каталог

Документирование API с использованием Swagger/OpenAPI — Наследование и композиция схем

Фрагмент из «Документирование API с использованием Swagger/OpenAPI»: Наследование и композиция схем.

yaml projectencyclopedia7-08-tehnicheskoe-pismo-3 embed URL статья в энциклопедии
YAML main.yaml
components:
  schemas:
    BaseResource:
      type: object
      properties:
        id:
          type: string
          format: uuid
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    
    Task:
      allOf:
        - $ref: '#/components/schemas/BaseResource'
        - type: object
          properties:
            title:
              type: string
            status:
              type: string
              enum: [active, completed]
components:
  schemas:
    BaseResource:
      type: object
      properties:
        id:
          type: string
          format: uuid
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    
    Task:
      allOf:
        - $ref: '#/components/schemas/BaseResource'
        - type: object
          properties:
            title:
              type: string
            status:
              type: string
              enum: [active, completed]