{
  "openapi": "3.1.0",
  "info": {
    "title": "markdown共有ツール API",
    "version": "1.2.0",
    "description": "Markdown本文を無期限または期限付き共有ページとして公開し、完成URLを返すAPI"
  },
  "servers": [
    {
      "url": "https://markdown.bz"
    }
  ],
  "paths": {
    "/api/v1/documents": {
      "post": {
        "summary": "Markdown共有ページの作成",
        "operationId": "publishMarkdown",
        "requestBody": {
          "required": true,
          "content": {
            "text/markdown": {
              "schema": {
                "type": "string",
                "description": "1MB以内のMarkdown本文"
              },
              "example": "# APIから公開\n\nMarkdown本文"
            },
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PublishRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "共有ページの作成完了",
            "headers": {
              "Location": {
                "description": "作成された共有ページURL",
                "schema": { "type": "string", "format": "uri" }
              }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PublishResponse" }
              }
            }
          },
          "400": {
            "description": "JSONまたは入力値が不正",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "413": {
            "description": "Markdownまたはリクエストが上限超過",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "415": {
            "description": "Content-Typeが未対応",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "429": {
            "description": "作成回数の上限超過",
            "headers": {
              "Retry-After": {
                "description": "再試行までの秒数",
                "schema": { "type": "integer" }
              }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "500": {
            "description": "公開処理の失敗",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "503": {
            "description": "公開APIの一時利用不可",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      },
      "options": {
        "summary": "CORSプリフライト",
        "responses": {
          "204": { "description": "利用可能" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PublishRequest": {
        "type": "object",
        "required": ["markdown"],
        "additionalProperties": false,
        "properties": {
          "markdown": {
            "type": "string",
            "minLength": 1,
            "description": "UTF-8で1MB以内のMarkdown本文"
          },
          "title": {
            "type": "string",
            "maxLength": 200,
            "description": "省略時は最初のMarkdown見出しを使用"
          },
          "expiryDays": {
            "type": ["integer", "null"],
            "enum": [null, 3, 7, 30, 60, 100],
            "default": null,
            "description": "nullまたは省略で無期限、整数で作成時からの表示日数"
          },
          "password": {
            "type": "string",
            "minLength": 4,
            "maxLength": 200,
            "description": "任意の閲覧パスワード"
          },
          "showTitleWhenLocked": {
            "type": "boolean",
            "default": false,
            "description": "ロック中のページとOGPにタイトルを表示するか"
          },
          "allowIndexing": {
            "type": "boolean",
            "default": false,
            "description": "Googleなどの検索結果に掲載してよい場合だけtrue。既定はfalseで、明示しない限り検索非公開。OGP・X（Twitter）Cardなどのリンクプレビューには影響しない。パスワードとは併用不可"
          }
        }
      },
      "PublishResponse": {
        "type": "object",
        "required": ["slug", "publicUrl", "expiresAt"],
        "properties": {
          "slug": { "type": "string" },
          "publicUrl": { "type": "string", "format": "uri" },
          "expiresAt": {
            "type": ["string", "null"],
            "format": "date-time",
            "description": "有限期限のISO 8601日時。無期限ではnull"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "INVALID_JSON",
                  "INVALID_REQUEST",
                  "PAYLOAD_TOO_LARGE",
                  "UNSUPPORTED_MEDIA_TYPE",
                  "RATE_LIMITED",
                  "SERVICE_UNAVAILABLE",
                  "PUBLISH_FAILED"
                ]
              },
              "message": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
