{
  "openapi": "3.0.3",
  "info": {
    "title": "shamsimiladi.com Calendar API",
    "version": "1.0.0",
    "description": "Free API to convert dates between the Persian (Jalali/Solar Hijri) and Gregorian calendars. Rate limit: 60 requests per minute per IP. Please credit shamsimiladi.com with a link when you use the API in public projects."
  },
  "servers": [{ "url": "https://shamsimiladi.com/api/v1" }],
  "paths": {
    "/convert": {
      "get": {
        "summary": "Convert a date",
        "parameters": [
          { "name": "from", "in": "query", "required": true, "schema": { "type": "string", "enum": ["jalali", "gregorian"] } },
          { "name": "date", "in": "query", "required": true, "schema": { "type": "string", "pattern": "^\\d{1,4}-\\d{1,2}-\\d{1,2}$" }, "example": "1405-08-05" }
        ],
        "responses": {
          "200": { "description": "Converted date", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Conversion" } } } },
          "400": { "description": "Invalid input", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/today": {
      "get": {
        "summary": "Today's date in both calendars",
        "parameters": [
          { "name": "tz", "in": "query", "required": false, "schema": { "type": "string", "default": "Asia/Tehran" }, "description": "IANA time zone that defines the current day" }
        ],
        "responses": {
          "200": { "description": "Today", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Today" } } } },
          "400": { "description": "Invalid time zone", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Names": { "type": "object", "properties": { "fa": { "type": "string" }, "de": { "type": "string" }, "en": { "type": "string" } } },
      "CalendarDate": {
        "type": "object",
        "properties": {
          "date": { "type": "string", "example": "1405-08-05" },
          "year": { "type": "integer" },
          "month": { "type": "integer" },
          "day": { "type": "integer" },
          "monthName": { "$ref": "#/components/schemas/Names" },
          "isLeapYear": { "type": "boolean", "description": "Only present on jalali" }
        }
      },
      "DateInfo": {
        "type": "object",
        "properties": {
          "jalali": { "$ref": "#/components/schemas/CalendarDate" },
          "gregorian": { "$ref": "#/components/schemas/CalendarDate" },
          "weekday": {
            "allOf": [
              { "$ref": "#/components/schemas/Names" },
              { "type": "object", "properties": { "index": { "type": "integer", "description": "0 = Sunday" } } }
            ]
          }
        }
      },
      "Conversion": {
        "allOf": [
          { "$ref": "#/components/schemas/DateInfo" },
          { "type": "object", "properties": { "input": { "type": "object", "properties": { "from": { "type": "string" }, "date": { "type": "string" } } } } }
        ]
      },
      "Today": {
        "allOf": [
          { "$ref": "#/components/schemas/DateInfo" },
          { "type": "object", "properties": { "timeZone": { "type": "string" } } }
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string", "enum": ["invalid_from", "invalid_format", "invalid_date", "out_of_range", "invalid_timezone", "not_found"] },
              "message": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
