{
  "openapi": "3.1.0",
  "info": {
    "title": "シルギア 地方公共団体コードAPI",
    "version": "1.0.0",
    "description": "登録不要・無料の全国地方公共団体コード（都道府県・市区町村コード）のAPI。総務省「全国地方公共団体コード」と e-Stat の標準地域コードをもとに、廃止されたコードの理由と今のコード、1970年4月1日以降の変更の履歴を返します。説明: https://api.shirugear.com/lgcode/ 。v1 の中では項目を足すことはあっても、名前や意味は変えません（知らない項目は無視してください）。",
    "termsOfService": "https://api.shirugear.com/terms/",
    "contact": {
      "name": "アナライズギア株式会社（シルギア）",
      "url": "https://shirugear.com/contact"
    }
  },
  "servers": [
    {
      "url": "https://api.shirugear.com"
    }
  ],
  "paths": {
    "/lgcode/v1/{code}.json": {
      "get": {
        "summary": "コードから団体（今のコードも廃止されたコードも）",
        "operationId": "getLgCode",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "description": "5桁、または検査数字付きの6桁（半角数字）",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{5,6}$",
              "examples": [
                "13101",
                "131016"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "見つかった（廃止されたコードを含む）",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LgCodeResponse"
                }
              }
            }
          },
          "400": {
            "description": "形が正しくない（invalid_lgcode）／6桁の検査数字が合わない（invalid_check_digit）",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "見つからない（lgcode_not_found）",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/lgcode/v1/pref.json": {
      "get": {
        "summary": "47都道府県の一覧",
        "operationId": "getLgPrefList",
        "responses": {
          "200": {
            "description": "一覧",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PrefListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/lgcode/v1/pref/{prefcode}.json": {
      "get": {
        "summary": "都道府県の今の団体の一覧",
        "operationId": "getLgPref",
        "parameters": [
          {
            "name": "prefcode",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{2}$",
              "examples": [
                "13"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "一覧",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PrefResponse"
                }
              }
            }
          },
          "400": {
            "description": "invalid_lgcode",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "lgcode_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/lgcode/v1/all.json": {
      "get": {
        "summary": "今の全団体",
        "operationId": "getLgAll",
        "responses": {
          "200": {
            "description": "全件",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AllResponse"
                }
              }
            }
          }
        }
      }
    },
    "/lgcode/v1/changes.json": {
      "get": {
        "summary": "変更の履歴（1970年4月1日以降）",
        "operationId": "getLgChanges",
        "responses": {
          "200": {
            "description": "履歴",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangesResponse"
                }
              }
            }
          }
        }
      }
    },
    "/lgcode/v1/meta.json": {
      "get": {
        "summary": "データの版・出典・件数",
        "operationId": "getLgMeta",
        "responses": {
          "200": {
            "description": "版と件数",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MetaResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Ref": {
        "type": "object",
        "required": [
          "code",
          "name"
        ],
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[0-9]{5}$"
          },
          "name": {
            "type": "string"
          }
        }
      },
      "CurrentRef": {
        "type": "object",
        "required": [
          "code",
          "name",
          "kind"
        ],
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[0-9]{5}$"
          },
          "name": {
            "type": "string"
          },
          "kind": {
            "$ref": "#/components/schemas/Kind"
          }
        }
      },
      "Kind": {
        "type": "string",
        "enum": [
          "prefecture",
          "designated_city",
          "ward",
          "special_ward",
          "city",
          "town",
          "village"
        ],
        "description": "prefecture=都道府県 / designated_city=政令指定都市 / ward=政令指定都市の区 / special_ward=特別区 / city=市（政令指定都市を除く）/ town=町 / village=村"
      },
      "Reason": {
        "type": "string",
        "enum": [
          "absorption",
          "new_merger",
          "city_status",
          "town_status",
          "rename",
          "designated_city",
          "ward_established",
          "ward_split",
          "ward_division",
          "ward_reorganization",
          "district_change",
          "okinawa_reversion",
          "other"
        ],
        "description": "absorption=編入合併 / new_merger=新設合併 / city_status=市制施行 / town_status=町制施行 / rename=名称変更 / designated_city=政令指定都市への移行 / ward_established=区の設置 / ward_split=分区 / ward_division=区の分割 / ward_reorganization=区の再編 / district_change=郡・支庁の区域の変更 / okinawa_reversion=沖縄の本土復帰 / other=その他。値が増えることがある"
      },
      "NamePeriod": {
        "type": "object",
        "required": [
          "name",
          "name_kana",
          "from",
          "until"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "name_kana": {
            "type": "string"
          },
          "from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "その名前になった日。1970-04-01より前からなら null"
          },
          "until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          }
        }
      },
      "Established": {
        "type": "object",
        "required": [
          "date",
          "reason",
          "reason_label",
          "description",
          "from"
        ],
        "properties": {
          "date": {
            "type": "string",
            "format": "date"
          },
          "reason": {
            "$ref": "#/components/schemas/Reason"
          },
          "reason_label": {
            "type": "string"
          },
          "description": {
            "type": "string",
            "description": "e-Stat の説明文"
          },
          "from": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Ref"
            }
          }
        }
      },
      "Abolished": {
        "type": "object",
        "required": [
          "date",
          "reason",
          "reason_label",
          "description",
          "to"
        ],
        "properties": {
          "date": {
            "type": "string",
            "format": "date",
            "description": "廃止された日（この日から移った先）"
          },
          "reason": {
            "$ref": "#/components/schemas/Reason"
          },
          "reason_label": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "to": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Ref"
            },
            "minItems": 1
          }
        }
      },
      "PreviousUse": {
        "type": "object",
        "required": [
          "name",
          "name_kana",
          "kind",
          "kind_label",
          "district",
          "parent",
          "valid_from",
          "valid_until",
          "established",
          "abolished",
          "current_codes",
          "former_names"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "name_kana": {
            "type": "string"
          },
          "kind": {
            "$ref": "#/components/schemas/Kind"
          },
          "kind_label": {
            "type": "string"
          },
          "district": {
            "type": [
              "string",
              "null"
            ]
          },
          "parent": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Ref"
              },
              {
                "type": "null"
              }
            ]
          },
          "valid_from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "valid_until": {
            "type": "string",
            "format": "date"
          },
          "established": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Established"
              },
              {
                "type": "null"
              }
            ]
          },
          "abolished": {
            "$ref": "#/components/schemas/Abolished"
          },
          "current_codes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CurrentRef"
            }
          },
          "former_names": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/NamePeriod"
            }
          }
        }
      },
      "LgCodeResponse": {
        "type": "object",
        "required": [
          "code",
          "code6",
          "check_digit",
          "name",
          "name_kana",
          "kind",
          "kind_label",
          "prefcode",
          "prefecture",
          "prefecture_kana",
          "district",
          "parent",
          "current",
          "valid_from",
          "valid_until",
          "established",
          "abolished",
          "current_codes",
          "former_names",
          "previous_uses",
          "zip_city",
          "note",
          "data_version"
        ],
        "properties": {
          "code": {
            "type": "string",
            "pattern": "^[0-9]{5}$"
          },
          "code6": {
            "type": "string",
            "pattern": "^[0-9]{6}$"
          },
          "check_digit": {
            "type": "string",
            "pattern": "^[0-9]$"
          },
          "name": {
            "type": "string",
            "description": "政令指定都市の区は「札幌市中央区」のように市の名前から。町村に郡は付かない"
          },
          "name_kana": {
            "type": "string",
            "description": "全角カタカナ"
          },
          "kind": {
            "$ref": "#/components/schemas/Kind"
          },
          "kind_label": {
            "type": "string"
          },
          "prefcode": {
            "type": "string",
            "pattern": "^[0-9]{2}$"
          },
          "prefecture": {
            "type": "string"
          },
          "prefecture_kana": {
            "type": "string"
          },
          "district": {
            "type": [
              "string",
              "null"
            ],
            "description": "町村の属する郡"
          },
          "parent": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Ref"
              },
              {
                "type": "null"
              }
            ]
          },
          "current": {
            "type": "boolean"
          },
          "valid_from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "使われ始めた日。1970-04-01より前からなら null"
          },
          "valid_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "廃止された日。今も使われていれば null"
          },
          "established": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Established"
              },
              {
                "type": "null"
              }
            ]
          },
          "abolished": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Abolished"
              },
              {
                "type": "null"
              }
            ]
          },
          "current_codes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CurrentRef"
            },
            "minItems": 1,
            "description": "今のコード（今も使われていれば自分自身。廃止されたコードは最後までたどった今のコード）"
          },
          "former_names": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/NamePeriod"
            }
          },
          "previous_uses": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PreviousUse"
            },
            "description": "同じコードを以前に使っていた別の団体"
          },
          "zip_city": {
            "type": [
              "string",
              "null"
            ],
            "description": "郵便番号API の町域一覧の URL（/zip/v1/city/{code}.json）"
          },
          "note": {
            "type": [
              "string",
              "null"
            ]
          },
          "data_version": {
            "type": "string",
            "format": "date",
            "description": "総務省の一覧の版（その日現在）"
          }
        }
      },
      "Summary": {
        "type": "object",
        "required": [
          "code",
          "code6",
          "name",
          "name_kana",
          "kind",
          "district",
          "parent_code"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "code6": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "name_kana": {
            "type": "string"
          },
          "kind": {
            "$ref": "#/components/schemas/Kind"
          },
          "district": {
            "type": [
              "string",
              "null"
            ]
          },
          "parent_code": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "PrefListResponse": {
        "type": "object",
        "required": [
          "count",
          "prefectures",
          "data_version"
        ],
        "properties": {
          "count": {
            "type": "integer"
          },
          "prefectures": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "prefcode",
                "code",
                "code6",
                "name",
                "name_kana",
                "count",
                "url"
              ],
              "properties": {
                "prefcode": {
                  "type": "string"
                },
                "code": {
                  "type": "string"
                },
                "code6": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "name_kana": {
                  "type": "string"
                },
                "count": {
                  "type": "integer",
                  "description": "その都道府県の今の市区町村の数"
                },
                "url": {
                  "type": "string",
                  "description": "その都道府県の一覧の URL"
                }
              }
            }
          },
          "data_version": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "PrefResponse": {
        "type": "object",
        "required": [
          "prefcode",
          "code",
          "code6",
          "prefecture",
          "prefecture_kana",
          "count",
          "municipalities",
          "data_version"
        ],
        "properties": {
          "prefcode": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "code6": {
            "type": "string"
          },
          "prefecture": {
            "type": "string"
          },
          "prefecture_kana": {
            "type": "string"
          },
          "count": {
            "type": "integer"
          },
          "municipalities": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Summary"
            }
          },
          "data_version": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "AllResponse": {
        "type": "object",
        "required": [
          "count",
          "items",
          "data_version"
        ],
        "properties": {
          "count": {
            "type": "integer"
          },
          "items": {
            "type": "array",
            "items": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Summary"
                },
                {
                  "type": "object",
                  "required": [
                    "prefcode",
                    "prefecture"
                  ],
                  "properties": {
                    "prefcode": {
                      "type": "string"
                    },
                    "prefecture": {
                      "type": "string"
                    }
                  }
                }
              ]
            }
          },
          "data_version": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "Change": {
        "type": "object",
        "required": [
          "date",
          "reason",
          "reason_label",
          "description",
          "abolished",
          "established",
          "continued"
        ],
        "properties": {
          "date": {
            "type": "string",
            "format": "date"
          },
          "reason": {
            "$ref": "#/components/schemas/Reason"
          },
          "reason_label": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "abolished": {
            "type": "array",
            "items": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Ref"
                },
                {
                  "type": "object",
                  "required": [
                    "to"
                  ],
                  "properties": {
                    "to": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              ]
            }
          },
          "established": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Ref"
            }
          },
          "continued": {
            "type": "array",
            "items": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Ref"
                },
                {
                  "type": "object",
                  "required": [],
                  "properties": {
                    "name_before": {
                      "type": "string"
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "ChangesResponse": {
        "type": "object",
        "required": [
          "from",
          "count",
          "changes",
          "data_version"
        ],
        "properties": {
          "from": {
            "type": "string",
            "format": "date"
          },
          "count": {
            "type": "integer"
          },
          "changes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Change"
            }
          },
          "data_version": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "MetaResponse": {
        "type": "object",
        "required": [
          "data_version",
          "built_at",
          "source",
          "sources",
          "history",
          "counts"
        ],
        "properties": {
          "data_version": {
            "type": "string",
            "format": "date"
          },
          "built_at": {
            "type": "string",
            "format": "date-time"
          },
          "source": {
            "type": "string"
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "url"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                }
              }
            }
          },
          "history": {
            "type": "object",
            "required": [
              "from",
              "latest_change"
            ],
            "properties": {
              "from": {
                "type": "string",
                "format": "date"
              },
              "latest_change": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date"
              }
            }
          },
          "counts": {
            "type": "object",
            "required": [
              "current",
              "prefectures",
              "designated_cities",
              "cities",
              "special_wards",
              "wards",
              "towns",
              "villages",
              "northern_territory_villages",
              "municipalities",
              "abolished_codes",
              "changes"
            ],
            "properties": {
              "current": {
                "type": "integer"
              },
              "prefectures": {
                "type": "integer"
              },
              "designated_cities": {
                "type": "integer"
              },
              "cities": {
                "type": "integer"
              },
              "special_wards": {
                "type": "integer"
              },
              "wards": {
                "type": "integer"
              },
              "towns": {
                "type": "integer"
              },
              "villages": {
                "type": "integer"
              },
              "northern_territory_villages": {
                "type": "integer"
              },
              "municipalities": {
                "type": "integer"
              },
              "abolished_codes": {
                "type": "integer"
              },
              "changes": {
                "type": "integer"
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "status",
              "code",
              "message"
            ],
            "properties": {
              "status": {
                "type": "integer"
              },
              "code": {
                "type": "string",
                "description": "エラーの種類（固定値）",
                "enum": [
                  "invalid_lgcode",
                  "invalid_check_digit",
                  "lgcode_not_found",
                  "not_found",
                  "method_not_allowed"
                ]
              },
              "message": {
                "type": "string",
                "description": "日本語の説明"
              }
            }
          }
        }
      }
    }
  }
}
