{
  "openapi": "3.1.0",
  "info": {
    "title": "Fictionite API v2",
    "version": "2.0.0",
    "description": "Customer-facing author API at `api.fictionite.com/v2`.\n\nAuthenticate with a self-serve API key:\n`Authorization: Bearer ftv2_…`\n\nKeys are minted via the web dashboard (Developer → API keys). This host never uses cookies."
  },
  "servers": [
    { "url": "https://api.fictionite.com", "description": "Production" },
    { "url": "http://api.lvh.me", "description": "Local development" }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "ftv2_",
        "description": "Self-serve API key. Prefix is always `ftv2_`."
      }
    },
    "schemas": {
      "ApiError": {
        "type": "object",
        "required": ["error", "message"],
        "properties": {
          "error": { "type": "string" },
          "message": { "type": "string" }
        }
      },
      "Fiction": {
        "type": "object",
        "required": ["id","slug","url","title","status","content_type","language","word_count","created_at","updated_at"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "slug": { "type": "string" },
          "url": { "type": "string" },
          "title": { "type": "string" },
          "description": { "type": ["string","null"] },
          "elevator_pitch": { "type": ["string","null"] },
          "status": { "type": "string" },
          "content_type": { "type": "string" },
          "language": { "type": "string" },
          "word_count": { "type": "integer" },
          "next_chapter_publish_at": { "type": ["string","null"] },
          "created_at": { "type": "string" },
          "updated_at": { "type": "string" }
        }
      },
      "Chapter": {
        "type": "object",
        "required": ["id","fiction_id","title","chapter_order","word_count","status","created_at","updated_at"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "fiction_id": { "type": "string", "format": "uuid" },
          "title": { "type": "string" },
          "chapter_order": { "type": "integer" },
          "word_count": { "type": "integer" },
          "status": { "type": "string" },
          "publish_at": { "type": ["string","null"] },
          "created_at": { "type": "string" },
          "updated_at": { "type": "string" }
        }
      },
      "ChapterContent": {
        "type": "object",
        "required": ["id","fiction_id","title","chapter_order","body","word_count","updated_at"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "fiction_id": { "type": "string", "format": "uuid" },
          "title": { "type": "string" },
          "chapter_order": { "type": "integer" },
          "body": { "type": "string" },
          "word_count": { "type": "integer" },
          "updated_at": { "type": "string" }
        }
      }
    }
  },
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/v2/fictions": {
      "get": {
        "summary": "List my fictions (includes drafts)",
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Fiction" } } } } },
          "401": { "description": "Unauthenticated", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApiError" } } } }
        }
      },
      "post": {
        "summary": "Create a fiction",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "required": ["title"], "properties": {
            "title": { "type": "string" },
            "description": { "type": ["string","null"] },
            "elevator_pitch": { "type": ["string","null"] },
            "language": { "type": ["string","null"] },
            "content_type": { "type": ["string","null"], "description": "novel | short_story" }
          } } } }
        },
        "responses": {
          "200": { "description": "Created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Fiction" } } } }
        }
      }
    },
    "/v2/fictions/{id}": {
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
      "get": { "summary": "Get a fiction", "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Fiction" } } } } } },
      "patch": { "summary": "Update a fiction", "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Fiction" } } } } } },
      "delete": { "summary": "Delete a fiction", "responses": { "200": { "description": "OK" } } }
    },
    "/v2/fictions/{id}/chapters": {
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
      "get": { "summary": "List chapters", "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Chapter" } } } } } } },
      "post": { "summary": "Create a chapter", "responses": { "200": { "description": "Created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Chapter" } } } } } }
    },
    "/v2/chapters/{id}": {
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
      "get": { "summary": "Get a chapter", "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Chapter" } } } } } },
      "patch": { "summary": "Update a chapter", "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Chapter" } } } } } },
      "delete": { "summary": "Delete a chapter", "responses": { "204": { "description": "No Content" } } }
    },
    "/v2/chapters/{id}/content": {
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
      "get": { "summary": "Get chapter HTML content (latest)", "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChapterContent" } } } } } },
      "put": { "summary": "Replace chapter HTML content (latest)", "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChapterContent" } } } } } }
    }
  }
}

