{
  "openapi": "3.1.0",
  "info": {
    "title": "Bounded Expense Ledger",
    "version": "1.0.0",
    "description": "Handwritten design contract; not generated or runtime verified. Local teaching example; no authentication."
  },
  "paths": {
    "/expenses": {
      "post": {
        "operationId": "create_expense",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExpenseInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Expense"
                }
              }
            }
          },
          "409": {
            "description": "duplicate_reference or ledger_full",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "storage_busy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "list_expenses",
        "responses": {
          "200": {
            "description": "Ascending id; at most 100 rows",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "maxItems": 100,
                  "items": {
                    "$ref": "#/components/schemas/Expense"
                  }
                }
              }
            }
          },
          "503": {
            "description": "storage_busy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/expenses/{expense_id}": {
      "get": {
        "operationId": "get_expense",
        "parameters": [
          {
            "name": "expense_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 2147483647
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Expense"
                }
              }
            }
          },
          "404": {
            "description": "not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "storage_busy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "delete_expense",
        "parameters": [
          {
            "name": "expense_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 2147483647
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted; empty response body"
          },
          "404": {
            "description": "not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "storage_busy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ExpenseInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "reference",
          "category",
          "cents"
        ],
        "properties": {
          "reference": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,40}$"
          },
          "category": {
            "type": "string",
            "enum": [
              "food",
              "travel",
              "other"
            ]
          },
          "cents": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000000
          }
        }
      },
      "Expense": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "reference",
          "category",
          "cents"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "minimum": 1,
            "maximum": 2147483647
          },
          "reference": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,40}$"
          },
          "category": {
            "type": "string",
            "enum": [
              "food",
              "travel",
              "other"
            ]
          },
          "cents": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000000
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "detail"
        ],
        "additionalProperties": false,
        "properties": {
          "detail": {
            "type": "string",
            "enum": [
              "invalid_request",
              "duplicate_reference",
              "ledger_full",
              "storage_busy",
              "not_found"
            ]
          }
        }
      }
    }
  }
}
