{
  "openapi": "3.1.0",
  "info": {
    "title": "シルギア 町字API",
    "version": "1.0.0",
    "description": "登録不要・無料の町字API。市区町村（自治体コード5桁・6桁、政令市は区）から、その市区町村の町字（大字・町・丁目など）の一覧と、読み・ローマ字・町字ID・住居表示の有無など、別のURLで小字の一覧を返します。番地・号は含みません。出典: デジタル庁「アドレス・ベース・レジストリ」（全国 町字マスター）を加工して作成（アナライズギア株式会社。デジタル庁の公式の API ではありません。元のデータは公共データ利用規約 第1.0版）。説明: https://api.shirugear.com/town/ 。v1 の中では項目を足すことはあっても、名前や意味は変えません（知らない項目は無視してください）。",
    "termsOfService": "https://api.shirugear.com/terms/",
    "contact": {
      "name": "アナライズギア株式会社（シルギア）",
      "url": "https://shirugear.com/contact"
    }
  },
  "servers": [
    {
      "url": "https://api.shirugear.com"
    }
  ],
  "paths": {
    "/town/v1/{code}.json": {
      "get": {
        "summary": "市区町村の町字の一覧（小字を除く）",
        "operationId": "getTownMunicipality",
        "description": "自治体コード5桁（または検査数字付き6桁）。政令市は市のコードでは 404 なので、区のコードで呼びます。",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "description": "自治体コード5桁・6桁",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{5,6}$"
            },
            "examples": {
              "chiyoda": {
                "summary": "千代田区",
                "value": "13101"
              },
              "ward": {
                "summary": "札幌市中央区",
                "value": "01101"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "町字の一覧",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TownMunicipality"
                }
              }
            }
          },
          "400": {
            "description": "URLの形が違う（code は invalid_request）",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "無い市区町村コード。都道府県・政令市の市のコード・北方領土の6村も 404（code は not_found）",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/town/v1/{code}/koaza.json": {
      "get": {
        "summary": "市区町村の小字の一覧（項目を絞ったもの）",
        "operationId": "getTownKoaza",
        "description": "小字が無い市区町村では items が空の一覧を返します。政令市は区のコードで呼びます。",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "description": "自治体コード5桁・6桁",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{5,6}$"
            },
            "examples": {
              "chiyoda": {
                "summary": "千代田区",
                "value": "13101"
              },
              "ward": {
                "summary": "札幌市中央区",
                "value": "01101"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "小字の一覧",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TownKoazaList"
                }
              }
            }
          },
          "400": {
            "description": "URLの形が違う（code は invalid_request）",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "無い市区町村コード。都道府県・政令市の市のコード・北方領土の6村も 404（code は not_found）",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/town/v1/meta.json": {
      "get": {
        "summary": "データの版・出典・件数・自治体コードAPIとのずれ・市区町村の一覧",
        "operationId": "getTownMeta",
        "responses": {
          "200": {
            "description": "版と件数",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TownMeta"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Town": {
        "type": "object",
        "required": [
          "machiaza_id",
          "kind",
          "name",
          "name_kana",
          "oaza",
          "oaza_kana",
          "oaza_roma",
          "chome",
          "chome_kana",
          "chome_number",
          "koaza",
          "koaza_kana",
          "koaza_roma",
          "distinction",
          "oaza_alias",
          "koaza_alias",
          "residential_address",
          "residential_address_method",
          "status",
          "lot_numbering",
          "postal_codes",
          "current",
          "valid_from",
          "abolished",
          "gaiji",
          "note"
        ],
        "properties": {
          "machiaza_id": {
            "type": "string",
            "pattern": "^[0-9]{7}$",
            "description": "町字ID 7桁（上4桁が大字・町、下3桁が丁目 001〜100 か小字 101〜999）。市区町村の中で重ならない",
            "examples": [
              "0001001"
            ]
          },
          "kind": {
            "type": "string",
            "enum": [
              "oaza",
              "chome",
              "koaza",
              "none",
              "road"
            ],
            "description": "区分。oaza 大字・町／chome 丁目／koaza 小字（京都の通り名も）／none 大字・町・丁目・小字なし／road 道路方式の住居表示の道路名"
          },
          "name": {
            "type": [
              "string",
              "null"
            ],
            "description": "住所に書くときの名前（大字・町＋丁目）。kind が none なら null",
            "examples": [
              "内幸町一丁目"
            ]
          },
          "name_kana": {
            "type": [
              "string",
              "null"
            ],
            "description": "name の読み（全角カタカナ）。どこかの読みが元のデータに無ければ null"
          },
          "oaza": {
            "type": [
              "string",
              "null"
            ],
            "description": "大字・町の名前（道路方式の住居表示では道路名）"
          },
          "oaza_kana": {
            "type": [
              "string",
              "null"
            ]
          },
          "oaza_roma": {
            "type": [
              "string",
              "null"
            ]
          },
          "chome": {
            "type": [
              "string",
              "null"
            ],
            "description": "丁目の名前。kind が chome のときだけ"
          },
          "chome_kana": {
            "type": [
              "string",
              "null"
            ]
          },
          "chome_number": {
            "type": [
              "integer",
              "null"
            ]
          },
          "koaza": {
            "type": [
              "string",
              "null"
            ],
            "description": "小字の名前。市区町村のファイルには小字が入らないので、今はいつも null"
          },
          "koaza_kana": {
            "type": [
              "string",
              "null"
            ]
          },
          "koaza_roma": {
            "type": [
              "string",
              "null"
            ]
          },
          "distinction": {
            "type": [
              "string",
              "null"
            ],
            "description": "同じ名前の大字・町が別の町字として複数あるときの見分ける名前"
          },
          "oaza_alias": {
            "type": "boolean",
            "description": "大字・町の名前が通称なら true"
          },
          "koaza_alias": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "alias",
              "kyoto_street",
              "gsi_name",
              null
            ],
            "description": "小字の名前が通称のときの種類"
          },
          "residential_address": {
            "type": "string",
            "enum": [
              "implemented",
              "not_implemented",
              "partial"
            ],
            "description": "住居表示を実施しているか（partial は一部の区域だけ）"
          },
          "residential_address_method": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "block",
              "road",
              null
            ],
            "description": "住居表示の方式（block 街区方式・road 道路方式）"
          },
          "status": {
            "type": "string",
            "enum": [
              "town_or_aza",
              "not_town_or_aza",
              "pending",
              "unknown"
            ],
            "description": "地方自治法の町・字に当たるか（市区町村の確認の状態）"
          },
          "lot_numbering": {
            "type": "string",
            "enum": [
              "own",
              "parent",
              "not_registered"
            ],
            "description": "地番の振られ方（own 起番・parent 非起番・not_registered 登記の情報に無い）"
          },
          "postal_codes": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[0-9]{7}$"
            },
            "description": "元のデータに入っている郵便番号。多くは空"
          },
          "current": {
            "type": "boolean"
          },
          "valid_from": {
            "type": "string",
            "format": "date",
            "description": "効力が生じた日（1947-04-17 はそれより前からある町字）"
          },
          "abolished": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "gaiji": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "oaza": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "koaza": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "description": "名前に含まれる電子国土基本図の外字の位置とコード"
          },
          "note": {
            "type": [
              "string",
              "null"
            ],
            "description": "元のデータの備考"
          }
        }
      },
      "TownMunicipality": {
        "type": "object",
        "required": [
          "code",
          "code6",
          "name",
          "name_kana",
          "kind",
          "prefcode",
          "prefecture",
          "district",
          "parent_code",
          "count",
          "counts",
          "items",
          "koaza_url",
          "lgcode",
          "data_version"
        ],
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[0-9]{5}$",
            "description": "自治体コード5桁"
          },
          "code6": {
            "type": "string",
            "pattern": "^[0-9]{6}$",
            "description": "検査数字付き6桁"
          },
          "name": {
            "type": "string",
            "description": "市区町村名（政令市の区は市の名前から）",
            "examples": [
              "千代田区"
            ]
          },
          "name_kana": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "city",
              "special_ward",
              "town",
              "village",
              "ward"
            ]
          },
          "prefcode": {
            "type": "string",
            "pattern": "^[0-9]{2}$"
          },
          "prefecture": {
            "type": "string"
          },
          "district": {
            "type": [
              "string",
              "null"
            ],
            "description": "郡の名前"
          },
          "parent_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "政令市の区なら市のコード"
          },
          "count": {
            "type": "integer",
            "description": "items の数（小字を含まない）"
          },
          "counts": {
            "type": "object",
            "properties": {
              "oaza": {
                "type": "integer"
              },
              "chome": {
                "type": "integer"
              },
              "koaza": {
                "type": "integer"
              },
              "none": {
                "type": "integer"
              },
              "road": {
                "type": "integer"
              }
            },
            "description": "区分ごとの数。koaza は小字のファイルにある小字の数"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Town"
            },
            "description": "小字を除いた町字（町字IDの順）"
          },
          "koaza_url": {
            "type": "string",
            "format": "uri",
            "description": "同じ市区町村の小字の一覧の URL"
          },
          "lgcode": {
            "type": "string",
            "format": "uri",
            "description": "自治体コードAPIの同じ団体の URL"
          },
          "data_version": {
            "type": "string",
            "format": "date",
            "description": "デジタル庁が町字データを更新した日"
          }
        }
      },
      "TownKoaza": {
        "type": "object",
        "required": [
          "machiaza_id",
          "oaza",
          "oaza_kana",
          "koaza",
          "koaza_kana",
          "current"
        ],
        "description": "小字1件。住所に書くときは oaza＋koaza の順（koaza_alias が kyoto_street のときだけ koaza＋oaza の順）",
        "properties": {
          "machiaza_id": {
            "type": "string",
            "pattern": "^[0-9]{7}$"
          },
          "oaza": {
            "type": [
              "string",
              "null"
            ],
            "description": "上の階層の大字・町"
          },
          "oaza_kana": {
            "type": [
              "string",
              "null"
            ],
            "description": "大字・町の読み"
          },
          "koaza": {
            "type": "string",
            "description": "小字の名前（京都の通り名も）"
          },
          "koaza_kana": {
            "type": [
              "string",
              "null"
            ],
            "description": "小字の読み"
          },
          "current": {
            "type": "boolean"
          },
          "koaza_alias": {
            "type": "string",
            "enum": [
              "alias",
              "kyoto_street",
              "gsi_name"
            ],
            "description": "通称のときだけ入る"
          },
          "abolished": {
            "type": "string",
            "format": "date",
            "description": "廃止した小字のときだけ入る"
          }
        }
      },
      "TownKoazaList": {
        "type": "object",
        "required": [
          "code",
          "code6",
          "name",
          "prefcode",
          "prefecture",
          "count",
          "items",
          "town_url",
          "data_version"
        ],
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[0-9]{5}$"
          },
          "code6": {
            "type": "string",
            "pattern": "^[0-9]{6}$"
          },
          "name": {
            "type": "string"
          },
          "prefcode": {
            "type": "string",
            "pattern": "^[0-9]{2}$"
          },
          "prefecture": {
            "type": "string"
          },
          "count": {
            "type": "integer"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TownKoaza"
            }
          },
          "town_url": {
            "type": "string",
            "format": "uri"
          },
          "data_version": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "TownMeta": {
        "type": "object",
        "required": [
          "data_version",
          "source",
          "sources",
          "license",
          "lgcode_data_version",
          "counts",
          "codes",
          "lgcode_gap",
          "municipalities"
        ],
        "properties": {
          "data_version": {
            "type": "string",
            "format": "date"
          },
          "source": {
            "type": "string"
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "license": {
            "type": "string"
          },
          "lgcode_data_version": {
            "type": "string"
          },
          "counts": {
            "type": "object"
          },
          "codes": {
            "type": "object"
          },
          "lgcode_gap": {
            "type": "object",
            "properties": {
              "lgcode_only": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string"
                    },
                    "reason": {
                      "type": "string"
                    }
                  }
                }
              },
              "lgcode_only_count": {
                "type": "integer"
              },
              "abr_only": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "name_differences": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            }
          },
          "notes": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "municipalities": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "prefcode": {
                  "type": "string"
                },
                "count": {
                  "type": "integer"
                },
                "koaza_count": {
                  "type": "integer",
                  "description": "小字の件数"
                }
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "status",
              "code",
              "message"
            ],
            "properties": {
              "status": {
                "type": "integer"
              },
              "code": {
                "type": "string",
                "enum": [
                  "invalid_request",
                  "not_found",
                  "method_not_allowed",
                  "region_not_allowed"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
