{
  "openapi": "3.1.0",
  "info": {
    "title": "subhbits API",
    "description": "Public API for subhbits — a tech blog by Subhro Kar covering modern web development, software engineering, and building things that matter. Provides blog content via GraphQL, newsletter subscriptions, and contact form submissions.",
    "version": "1.0.0",
    "contact": {
      "name": "Subhro Kar",
      "email": "hi@subhbits.com",
      "url": "https://subhbits.com/about"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://subhbits.com/terms"
    }
  },
  "servers": [
    {
      "url": "http://localhost:3000",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/graphql": {
      "get": {
        "operationId": "graphql-introspect",
        "summary": "GraphQL introspection",
        "description": "Perform GraphQL introspection queries via GET. Returns the full schema including types and queries.",
        "tags": [
          "GraphQL"
        ],
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "required": true,
            "description": "GraphQL query string",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "GraphQL response",
            "content": {
              "application/graphql+json": {
                "schema": {
                  "$ref": "#/components/schemas/GraphQLResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "graphql-query",
        "summary": "Execute GraphQL queries",
        "description": "Execute GraphQL queries and mutations. Supports all blog content queries including posts, series, tags, and semantic search.",
        "tags": [
          "GraphQL"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GraphQLRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "GraphQL response",
            "content": {
              "application/graphql+json": {
                "schema": {
                  "$ref": "#/components/schemas/GraphQLResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/contact": {
      "post": {
        "operationId": "submit-contact",
        "summary": "Submit a contact message",
        "description": "Submit a contact form message. Sends a notification email and auto-reply to the submitter.",
        "tags": [
          "Contact"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Message submitted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Unique submission identifier"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/newsletter": {
      "post": {
        "operationId": "subscribe-newsletter",
        "summary": "Subscribe to the newsletter",
        "description": "Subscribe an email address to the newsletter. Sends a confirmation email. The subscription is pending until confirmed.",
        "tags": [
          "Newsletter"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SubscribeInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Subscription created (pending confirmation)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "email": {
                          "type": "string",
                          "format": "email"
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "pending"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation error or already subscribed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/newsletter/confirm": {
      "get": {
        "operationId": "confirm-newsletter",
        "summary": "Confirm newsletter subscription",
        "description": "Confirm a pending newsletter subscription using the token sent in the confirmation email. Redirects to the newsletter page on success.",
        "tags": [
          "Newsletter"
        ],
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "Confirmation token from the subscription email",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirects to /newsletter?newsletter=confirmed on success"
          },
          "400": {
            "description": "Invalid or expired token"
          }
        }
      }
    },
    "/api/newsletter/unsubscribe": {
      "get": {
        "operationId": "unsubscribe-newsletter",
        "summary": "Unsubscribe from newsletter",
        "description": "Unsubscribe from the newsletter using the token from any newsletter email. Redirects to the newsletter page on success.",
        "tags": [
          "Newsletter"
        ],
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "Unsubscribe token from the newsletter email",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirects to /newsletter?newsletter=unsubscribed on success"
          },
          "400": {
            "description": "Invalid token"
          }
        }
      }
    },
    "/api/markdown/{path}": {
      "get": {
        "operationId": "get-markdown-content",
        "summary": "Get page content as Markdown",
        "description": "Retrieve page content as Markdown for AI agent consumption. Supports homepage, blog index, individual posts, and about page.",
        "tags": [
          "Content"
        ],
        "parameters": [
          {
            "name": "path",
            "in": "path",
            "required": false,
            "description": "Page path (e.g., 'blog', 'blog/my-post-slug', 'about')",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Markdown content",
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ContactInput": {
        "type": "object",
        "required": [
          "name",
          "email",
          "message"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "description": "Sender name"
          },
          "email": {
            "type": "string",
            "format": "email",
            "description": "Sender email address"
          },
          "subject": {
            "type": "string",
            "maxLength": 200,
            "description": "Optional message subject"
          },
          "message": {
            "type": "string",
            "minLength": 10,
            "maxLength": 5000,
            "description": "Message body"
          }
        }
      },
      "SubscribeInput": {
        "type": "object",
        "required": [
          "email"
        ],
        "properties": {
          "email": {
            "type": "string",
            "format": "email",
            "description": "Email address to subscribe"
          },
          "name": {
            "type": "string",
            "maxLength": 100,
            "description": "Optional subscriber name"
          },
          "source": {
            "type": "string",
            "maxLength": 50,
            "default": "blog",
            "description": "Subscription source tracking"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                },
                "description": "Field-level validation errors keyed by field name"
              }
            ],
            "description": "Error detail — either a plain message string or an object of field-level errors"
          }
        }
      },
      "GraphQLRequest": {
        "type": "object",
        "required": [
          "query"
        ],
        "properties": {
          "query": {
            "type": "string",
            "description": "GraphQL query or mutation string"
          },
          "variables": {
            "type": "object",
            "additionalProperties": true,
            "description": "Query variables"
          },
          "operationName": {
            "type": "string",
            "description": "Operation name for multi-operation documents"
          }
        }
      },
      "GraphQLResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "additionalProperties": true
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string"
                },
                "locations": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "line": {
                        "type": "integer"
                      },
                      "column": {
                        "type": "integer"
                      }
                    }
                  }
                },
                "path": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "GraphQL",
      "description": "Blog content API — query posts, series, tags, and perform semantic search"
    },
    {
      "name": "Contact",
      "description": "Contact form submission"
    },
    {
      "name": "Newsletter",
      "description": "Newsletter subscription management — subscribe, confirm, unsubscribe"
    },
    {
      "name": "Content",
      "description": "Markdown content negotiation for AI agents and programmatic access"
    }
  ]
}