{
  "openapi": "3.1.0",
  "info": {
    "title": "Tishi Notes API",
    "version": "1.0.0",
    "description": "Read and write the Tishi and Moss blogs. Reading published posts needs no key. Writing needs a Bearer key: scope `write` creates and edits drafts; scope `publish` also publishes, edits live posts and archives. Follow the house rules at /developers: no invented facts, plain words, sources for quotations."
  },
  "servers": [
    {
      "url": "https://tishilabs.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "PostInput": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$",
            "maxLength": 80
          },
          "lang": {
            "type": "string",
            "enum": [
              "zh",
              "en"
            ]
          },
          "site": {
            "type": "string",
            "enum": [
              "tishi",
              "moss"
            ],
            "default": "tishi"
          },
          "title": {
            "type": "string",
            "maxLength": 160
          },
          "summary": {
            "type": "string",
            "maxLength": 400
          },
          "body": {
            "type": "string",
            "description": "Markdown. Raw HTML is shown as text."
          },
          "category": {
            "type": "string",
            "enum": [
              "company",
              "product",
              "essay",
              "research",
              "engineering"
            ]
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 40
            },
            "maxItems": 12
          },
          "author": {
            "type": "string"
          },
          "cover": {
            "type": "string",
            "description": "https URL or a site path such as /media/p-build.jpg"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "published",
              "archived"
            ],
            "default": "draft"
          },
          "publishedAt": {
            "type": "string",
            "format": "date",
            "description": "A future date keeps a published post hidden until that day."
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/posts": {
      "get": {
        "summary": "List posts",
        "parameters": [
          {
            "name": "site",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "tishi",
                "moss",
                "all"
              ]
            }
          },
          {
            "name": "lang",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "zh",
                "en"
              ]
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 200
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "published",
                "draft",
                "archived",
                "any"
              ]
            },
            "description": "Anything but published needs a key."
          }
        ],
        "responses": {
          "200": {
            "description": "Posts without bodies"
          }
        }
      },
      "post": {
        "summary": "Create a post (draft by default)",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PostInput",
                "required": [
                  "slug",
                  "lang",
                  "title",
                  "body"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "401": {
            "description": "No or bad key"
          },
          "403": {
            "description": "Key may not publish"
          },
          "409": {
            "description": "Slug exists in that language"
          },
          "422": {
            "description": "Invalid fields"
          }
        }
      }
    },
    "/api/v1/posts/{slug}": {
      "parameters": [
        {
          "name": "slug",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "lang",
          "in": "query",
          "schema": {
            "type": "string",
            "enum": [
              "zh",
              "en"
            ],
            "default": "zh"
          }
        }
      ],
      "get": {
        "summary": "Read one post with its Markdown body",
        "responses": {
          "200": {
            "description": "The post"
          },
          "404": {
            "description": "Not found"
          }
        }
      },
      "patch": {
        "summary": "Update fields or status",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PostInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          }
        }
      },
      "delete": {
        "summary": "Archive a post",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Archived"
          }
        }
      }
    }
  }
}