openapi: 3.0.3
info:
  title: Skills Management API
  description: REST API for managing Claude Code skills
  version: 1.0.0
servers:
  - url: https://skills.srk9.io
    description: Production
  - url: http://localhost:8787
    description: Development

paths:
  /health:
    get:
      summary: Health check
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                  timestamp:
                    type: string

  /skills:
    get:
      summary: List all skills
      responses:
        '200':
          description: List of skills
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Skill'
    post:
      summary: Add a skill
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SkillInput'
      responses:
        '201':
          description: Skill created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Skill'

  /skills/{uid}:
    get:
      summary: Get skill by UID
      parameters:
        - name: uid
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Skill found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Skill'
        '404':
          description: Not found
    put:
      summary: Update skill
      parameters:
        - name: uid
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SkillUpdate'
      responses:
        '200':
          description: Skill updated
        '404':
          description: Not found
    delete:
      summary: Delete skill
      parameters:
        - name: uid
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Deleted
        '404':
          description: Not found

  /skills/category/{category}:
    get:
      summary: Get skills by category
      parameters:
        - name: category
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Skills in category
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Skill'

  /stats:
    get:
      summary: Get statistics
      responses:
        '200':
          description: Stats
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SkillStats'

  /sync:
    post:
      summary: Sync skills from CLI
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SyncRequest'
      responses:
        '200':
          description: Sync result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SyncResponse'

components:
  schemas:
    Skill:
      type: object
      properties:
        uid:
          type: string
        name:
          type: string
        category:
          type: string
        description:
          type: string
        content:
          type: string
        format:
          type: string
          enum: [flat, legacy]
        source:
          type: string
          enum: [claude-code, claude-desktop]
        references:
          type: object
          additionalProperties:
            type: string
        last_sync:
          type: string
        content_hash:
          type: string

    SkillInput:
      type: object
      required: [name, category, description, content, format, source]
      properties:
        name:
          type: string
        category:
          type: string
        description:
          type: string
        content:
          type: string
        format:
          type: string
          enum: [flat, legacy]
        source:
          type: string
          enum: [claude-code, claude-desktop]
        references:
          type: object
          additionalProperties:
            type: string

    SkillUpdate:
      type: object
      properties:
        name:
          type: string
        category:
          type: string
        description:
          type: string
        content:
          type: string
        format:
          type: string
          enum: [flat, legacy]
        source:
          type: string
          enum: [claude-code, claude-desktop]

    SkillStats:
      type: object
      properties:
        total:
          type: integer
        by_category:
          type: object
          additionalProperties:
            type: integer
        by_format:
          type: object
          properties:
            flat:
              type: integer
            legacy:
              type: integer
        by_source:
          type: object
          properties:
            claude-code:
              type: integer
            claude-desktop:
              type: integer
        last_sync:
          type: string
          nullable: true

    SyncRequest:
      type: object
      required: [skills, source]
      properties:
        skills:
          type: array
          items:
            $ref: '#/components/schemas/SkillInput'
        source:
          type: string
          enum: [claude-code, claude-desktop]

    SyncResponse:
      type: object
      properties:
        success:
          type: boolean
        synced:
          type: integer
        added:
          type: integer
        updated:
          type: integer
        removed:
          type: integer
        skills:
          type: array
          items:
            $ref: '#/components/schemas/Skill'