{
  "openapi": "3.1.0",
  "info": {
    "title": "kodepos-api",
    "version": "1.0.0",
    "description": "Read-only public API for Indonesian regions and postal codes."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Contoh respons",
                    "value": {
                      "status": "ok"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "tags": [
          "System"
        ]
      }
    },
    "/api/v1/provinces": {
      "get": {
        "summary": "List provinces",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "Jakarta"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100,
              "example": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProvinceList"
                },
                "examples": {
                  "sample": {
                    "summary": "Contoh respons",
                    "value": {
                      "data": [
                        {
                          "id": 5,
                          "name": "Aceh",
                          "code": "AC"
                        }
                      ],
                      "meta": {
                        "page": 1,
                        "limit": 1,
                        "total": 38
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "tags": [
          "Provinces"
        ]
      }
    },
    "/api/v1/provinces/{id}": {
      "get": {
        "summary": "Get province by id",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "example": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Province"
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Contoh respons",
                    "value": {
                      "data": {
                        "id": 1,
                        "name": "DKI Jakarta",
                        "code": "JK"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "tags": [
          "Provinces"
        ]
      }
    },
    "/api/v1/regencies": {
      "get": {
        "summary": "List regencies",
        "parameters": [
          {
            "name": "province_id",
            "in": "query",
            "schema": {
              "type": "integer",
              "example": 1
            }
          },
          {
            "name": "province",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "Jakarta"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "Pusat"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100,
              "example": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RegencyList"
                },
                "examples": {
                  "sample": {
                    "summary": "Contoh respons",
                    "value": {
                      "data": [
                        {
                          "id": 6,
                          "province_id": 1,
                          "name": "Kabupaten Adm. Kep. Seribu",
                          "province": "DKI Jakarta"
                        }
                      ],
                      "meta": {
                        "page": 1,
                        "limit": 1,
                        "total": 6
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "tags": [
          "Regencies"
        ]
      }
    },
    "/api/v1/regencies/{id}": {
      "get": {
        "summary": "Get regency by id",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "example": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Regency"
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Contoh respons",
                    "value": {
                      "data": {
                        "id": 1,
                        "province_id": 1,
                        "name": "Kota Administrasi Jakarta Pusat",
                        "province": "DKI Jakarta"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "tags": [
          "Regencies"
        ]
      }
    },
    "/api/v1/districts": {
      "get": {
        "summary": "List districts",
        "parameters": [
          {
            "name": "regency_id",
            "in": "query",
            "schema": {
              "type": "integer",
              "example": 1
            }
          },
          {
            "name": "regency",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "Pusat"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "Gambir"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100,
              "example": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DistrictList"
                },
                "examples": {
                  "sample": {
                    "summary": "Contoh respons",
                    "value": {
                      "data": [
                        {
                          "id": 5,
                          "regency_id": 1,
                          "name": "Cempaka Putih",
                          "regency": "Kota Administrasi Jakarta Pusat",
                          "province": "DKI Jakarta"
                        }
                      ],
                      "meta": {
                        "page": 1,
                        "limit": 1,
                        "total": 8
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "tags": [
          "Districts"
        ]
      }
    },
    "/api/v1/districts/{id}": {
      "get": {
        "summary": "Get district by id",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "example": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/District"
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Contoh respons",
                    "value": {
                      "data": {
                        "id": 1,
                        "regency_id": 1,
                        "name": "Gambir",
                        "regency": "Kota Administrasi Jakarta Pusat",
                        "province": "DKI Jakarta"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "tags": [
          "Districts"
        ]
      }
    },
    "/api/v1/villages": {
      "get": {
        "summary": "List villages",
        "parameters": [
          {
            "name": "district_id",
            "in": "query",
            "schema": {
              "type": "integer",
              "example": 1
            }
          },
          {
            "name": "district",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "Gambir"
            }
          },
          {
            "name": "regency",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "Pusat"
            }
          },
          {
            "name": "province",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "Jakarta"
            }
          },
          {
            "name": "postal_code",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "10110"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "Gambir"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100,
              "example": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VillageList"
                },
                "examples": {
                  "sample": {
                    "summary": "Contoh respons",
                    "value": {
                      "data": [
                        {
                          "id": 5,
                          "district_id": 1,
                          "regency_id": 1,
                          "province_id": 1,
                          "name": "Cideng",
                          "postal_code": "10150",
                          "district": "Gambir",
                          "regency": "Kota Administrasi Jakarta Pusat",
                          "province": "DKI Jakarta"
                        }
                      ],
                      "meta": {
                        "page": 1,
                        "limit": 1,
                        "total": 6
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "tags": [
          "Villages"
        ]
      }
    },
    "/api/v1/villages/{id}": {
      "get": {
        "summary": "Get village by id",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "example": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Village"
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Contoh respons",
                    "value": {
                      "data": {
                        "id": 1,
                        "district_id": 1,
                        "regency_id": 1,
                        "province_id": 1,
                        "name": "Gambir",
                        "postal_code": "10110",
                        "district": "Gambir",
                        "regency": "Kota Administrasi Jakarta Pusat",
                        "province": "DKI Jakarta"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "tags": [
          "Villages"
        ]
      }
    },
    "/api/v1/postal-codes/{code}": {
      "get": {
        "summary": "Lookup villages by postal code",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "example": "10110"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Village"
                      }
                    }
                  }
                },
                "examples": {
                  "sample": {
                    "summary": "Contoh respons",
                    "value": {
                      "data": [
                        {
                          "id": 1,
                          "district_id": 1,
                          "regency_id": 1,
                          "province_id": 1,
                          "name": "Gambir",
                          "postal_code": "10110",
                          "district": "Gambir",
                          "regency": "Kota Administrasi Jakarta Pusat",
                          "province": "DKI Jakarta"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "tags": [
          "Postal Codes"
        ]
      }
    },
    "/download/kodepos.csv": {
      "get": {
        "summary": "Download official CSV dump",
        "description": "Bulk download of all 85595 villages with hierarchy and postal codes. Use this for mass needs instead of scraping pages.",
        "tags": [
          "Villages"
        ],
        "responses": {
          "200": {
            "description": "CSV file, 9 columns, served as attachment kodepos.csv.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string",
                  "example": "province_id,province,regency_id,regency,district_id,district,village_id,village,postal_code"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Meta": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer",
            "example": 1
          },
          "limit": {
            "type": "integer",
            "example": 50
          },
          "total": {
            "type": "integer",
            "example": 38
          }
        }
      },
      "Province": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "DKI Jakarta"
          },
          "code": {
            "type": "string",
            "example": "JK"
          }
        }
      },
      "ProvinceList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Province"
            }
          },
          "meta": {
            "$ref": "#/components/schemas/Meta"
          }
        }
      },
      "Regency": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "province_id": {
            "type": "integer"
          },
          "name": {
            "type": "string",
            "example": "Kota Administrasi Jakarta Pusat"
          },
          "province": {
            "type": "string",
            "example": "DKI Jakarta"
          }
        }
      },
      "RegencyList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Regency"
            }
          },
          "meta": {
            "$ref": "#/components/schemas/Meta"
          }
        }
      },
      "District": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "regency_id": {
            "type": "integer"
          },
          "name": {
            "type": "string",
            "example": "Gambir"
          },
          "regency": {
            "type": "string"
          },
          "province": {
            "type": "string"
          }
        }
      },
      "DistrictList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/District"
            }
          },
          "meta": {
            "$ref": "#/components/schemas/Meta"
          }
        }
      },
      "Village": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "district_id": {
            "type": "integer"
          },
          "regency_id": {
            "type": "integer",
            "example": 1
          },
          "province_id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "Gambir"
          },
          "postal_code": {
            "type": "string",
            "example": "10110"
          },
          "district": {
            "type": "string"
          },
          "regency": {
            "type": "string"
          },
          "province": {
            "type": "string"
          }
        }
      },
      "VillageList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Village"
            }
          },
          "meta": {
            "$ref": "#/components/schemas/Meta"
          }
        }
      }
    },
    "responses": {
      "NotFound": {
        "description": "Not found",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "RateLimited": {
        "description": "Too many requests (100 req/min/IP)",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "string"
            }
          },
          "X-RateLimit-Limit": {
            "schema": {
              "type": "string"
            }
          },
          "X-RateLimit-Remaining": {
            "schema": {
              "type": "string"
            }
          },
          "X-RateLimit-Reset": {
            "schema": {
              "type": "string"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "integer",
                      "example": 429
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Provinces"
    },
    {
      "name": "Regencies"
    },
    {
      "name": "Districts"
    },
    {
      "name": "Villages"
    },
    {
      "name": "Postal Codes"
    },
    {
      "name": "System"
    }
  ]
}