{
  "openapi": "3.0.3",
  "info": {
    "title": "Vocabulary Size Test Public API",
    "version": "1.0.0",
    "description": "Public endpoints and dynamic services for vocabulary-test.com. Enables user authentication, score synchronization, interactive word list exports, email report delivery, and vocabulary-centric integrations with AI search engines, ChatGPT Custom GPTs, and Claude Projects."
  },
  "servers": [
    {
      "url": "https://vocabulary-test.com",
      "description": "Production Server"
    }
  ],
  "paths": {
    "/api/openapi.json": {
      "get": {
        "summary": "Retrieve the OpenAPI Specification",
        "description": "Returns the OpenAPI 3.0 JSON document describing all public endpoints.",
        "responses": {
          "200": {
            "description": "Valid OpenAPI specification JSON",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/words/sample": {
      "get": {
        "summary": "Retrieve Sample Vocabulary Words",
        "description": "Returns a randomized or filtered set of words from the vocabulary-test.com word banks (Native and Learner tracks). Perfect for micro-quizzes, lexical checks, and flashcard integrations in ChatGPT / Claude.",
        "parameters": [
          {
            "name": "track",
            "in": "query",
            "description": "Lexical track to sample from ('native' or 'learner')",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["native", "learner"]
            }
          },
          {
            "name": "difficulty",
            "in": "query",
            "description": "Difficulty rating (1-5 for native track, 1-6 for learner track corresponding to CEFR levels A1-C2)",
            "required": false,
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of words to return (default is 5, maximum is 20)",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 5,
              "maximum": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A list of sample words",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Word"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/auth": {
      "post": {
        "summary": "User Authentication & Sign-in",
        "description": "Signs in an existing user by email or registers a new user if the email does not exist.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email"],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "Unique email address of the user"
                  },
                  "name": {
                    "type": "string",
                    "description": "Display name of the user"
                  },
                  "joined": {
                    "type": "string",
                    "description": "ISO date string representing when the user registered"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User profile with history and saved words retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          }
        }
      }
    },
    "/api/sync": {
      "post": {
        "summary": "Synchronize User History and Saved Words",
        "description": "Saves or merges the user's test scores history and list of saved vocabulary words.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email"],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "history": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "List of test attempts taken by the user"
                  },
                  "savedWords": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Word"
                    },
                    "description": "List of vocabulary words bookmarked by the user"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User database record successfully updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          }
        }
      }
    },
    "/api/send-email": {
      "post": {
        "summary": "Send Detailed HTML Vocabulary Report",
        "description": "Dispatches a beautifully-styled, academic HTML email summary of the test results and vocabulary list to any specified email inbox.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "words"],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email",
                    "description": "Inbox address to send the report to"
                  },
                  "words": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Word"
                    },
                    "description": "Array of vocabulary words to display in the email"
                  },
                  "subject": {
                    "type": "string",
                    "description": "Custom subject line for the email report"
                  },
                  "track": {
                    "type": "string",
                    "enum": ["native", "learner"],
                    "description": "Assessment track that was taken"
                  },
                  "estimate": {
                    "type": "integer",
                    "description": "Estimated vocabulary size (word family count)"
                  },
                  "levelName": {
                    "type": "string",
                    "description": "Detailed tier level description (e.g. 'Advanced', 'C1')"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Email successfully dispatched or simulated in mock mode",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "id": {
                      "type": "string"
                    },
                    "mocked": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/stats": {
      "get": {
        "summary": "Retrieve Platform Analytics",
        "description": "Aggregates site metrics across the database, yielding total user registration count, test completions, and average vocabulary size.",
        "responses": {
          "200": {
            "description": "Aggregation of site-wide metrics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "totalUsers": { "type": "integer" },
                    "recentUsers": { "type": "integer" },
                    "activeUsers": { "type": "integer" },
                    "totalTests": { "type": "integer" },
                    "nativeTests": { "type": "integer" },
                    "learnerTests": { "type": "integer" },
                    "avgVocab": { "type": "integer" },
                    "avgTestsPerUser": { "type": "string" },
                    "totalSavedWords": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Word": {
        "type": "object",
        "required": ["word", "correct", "distractors"],
        "properties": {
          "word": {
            "type": "string",
            "description": "The lexical item / vocabulary word"
          },
          "difficulty": {
            "type": "integer",
            "description": "Difficulty rank of the word"
          },
          "pos": {
            "type": "string",
            "description": "Part of speech abbreviation (e.g. 'adj.', 'v.', 'n.')"
          },
          "pron": {
            "type": "string",
            "description": "Phonetic pronunciation guide"
          },
          "correct": {
            "type": "string",
            "description": "The accurate definition of the word"
          },
          "distractors": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Plausible but incorrect distractors for test-takers"
          },
          "track": {
            "type": "string",
            "enum": ["native", "learner"],
            "description": "The assessment track this word belongs to"
          }
        }
      },
      "User": {
        "type": "object",
        "required": ["email", "history", "savedWords"],
        "properties": {
          "email": {
            "type": "string",
            "format": "email"
          },
          "name": {
            "type": "string"
          },
          "joined": {
            "type": "string"
          },
          "history": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "savedWords": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Word"
            }
          }
        }
      }
    }
  }
}
