openapi: 3.1.0
info:
  title: Local culture catalog
  version: 1.0.0
servers:
  - url: https://catalog.example.test/v1
paths:
  /works:
    get:
      operationId: listWorks
      summary: Search catalog works
      parameters:
        - name: q
          in: query
          required: false
          schema:
            type: string
            minLength: 2
        - name: type
          in: query
          required: false
          schema:
            type: string
            enum: [painting, sculpture, photograph]
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 50
            default: 20
      responses:
        "200":
          description: Filtered collection
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/WorkCollection"
        "400":
          description: Invalid query parameter
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Problem"
  /works/{work_id}:
    get:
      operationId: getWork
      summary: Get a work
      parameters:
        - name: work_id
          in: path
          required: true
          schema:
            type: string
            pattern: "^wrk-[0-9]+$"
      responses:
        "200":
          description: Work found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Work"
        "404":
          description: Work not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Problem"
components:
  schemas:
    Work:
      type: object
      required: [id, title, type]
      properties:
        id:
          type: string
        title:
          type: string
        type:
          type: string
          enum: [painting, sculpture, photograph]
        author:
          type: [string, "null"]
        year:
          type: [integer, "null"]
    WorkCollection:
      type: object
      required: [items, total]
      properties:
        items:
          type: array
          items:
            $ref: "#/components/schemas/Work"
        total:
          type: integer
          minimum: 0
    Problem:
      type: object
      required: [code, message]
      properties:
        code:
          type: string
        message:
          type: string
