{
  "openapi": "3.1.0",
  "info": {
    "title": "シルギア 学校コードAPI",
    "version": "1.0.0",
    "description": "登録不要・無料の学校コードAPI。文部科学省「学校コード」の全件（幼稚園〜大学・専修学校・各種学校。廃止された学校も含む）を、13桁の学校コードから1校ずつ、都道府県×学校種の一覧、名前で探すための都道府県別の索引で返します。所在地から全国地方公共団体コード（6桁）を付けています。検査数字は公表の計算方法で確かめた結果（check_digit_valid）を返すだけで、合わないコードも引けます。出典: 文部科学省ホームページ「学校コード」（https://www.mext.go.jp/b_menu/toukei/mext_01087.html）を加工して作成（アナライズギア株式会社）。文部科学省の公式のサービスではありません。説明: https://api.shirugear.com/school/ 。v1 の中では項目を足すことはあっても、名前や意味は変えません（知らない項目は無視してください）。",
    "termsOfService": "https://api.shirugear.com/terms/",
    "contact": {
      "name": "アナライズギア株式会社（シルギア）",
      "url": "https://shirugear.com/contact"
    }
  },
  "servers": [
    {
      "url": "https://api.shirugear.com"
    }
  ],
  "paths": {
    "/school/v1/{code}.json": {
      "get": {
        "summary": "1校（学校コード13桁）",
        "operationId": "getSchool",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "description": "学校コード13桁（英字は大文字）",
            "schema": {
              "$ref": "#/components/schemas/SchoolCode"
            },
            "examples": {
              "elementary": {
                "summary": "東京学芸大学附属世田谷小学校",
                "value": "B113110000016"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "1校",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/School"
                }
              }
            }
          },
          "400": {
            "description": "形が違う（invalid_code）",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "一覧に無いコード（code_not_found）",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/school/v1/pref/{prefcode}.json": {
      "get": {
        "summary": "都道府県の学校種別の件数",
        "operationId": "getSchoolPrefecture",
        "parameters": [
          {
            "name": "prefcode",
            "in": "path",
            "required": true,
            "description": "都道府県コード2桁（01〜47）",
            "schema": {
              "$ref": "#/components/schemas/PrefCode"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "学校種別の件数と一覧の URL",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PrefectureSummary"
                }
              }
            }
          },
          "400": {
            "description": "形が違う",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "無い都道府県コード",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/school/v1/pref/{prefcode}/{kind}.json": {
      "get": {
        "summary": "都道府県×学校種の一覧（廃止された学校も含む）",
        "operationId": "getSchoolList",
        "parameters": [
          {
            "name": "prefcode",
            "in": "path",
            "required": true,
            "description": "都道府県コード2桁（01〜47）",
            "schema": {
              "$ref": "#/components/schemas/PrefCode"
            }
          },
          {
            "name": "kind",
            "in": "path",
            "required": true,
            "description": "学校種",
            "schema": {
              "$ref": "#/components/schemas/SchoolKind"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "一覧",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SchoolList"
                }
              }
            }
          },
          "400": {
            "description": "形が違う",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "無い都道府県・学校種、または1件も無い組み合わせ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/school/v1/names/{prefcode}.json": {
      "get": {
        "summary": "名前で探すための索引（今ある学校のコードと名前）",
        "operationId": "getSchoolNames",
        "parameters": [
          {
            "name": "prefcode",
            "in": "path",
            "required": true,
            "description": "都道府県コード2桁（01〜47）",
            "schema": {
              "$ref": "#/components/schemas/PrefCode"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "[学校コード, 学校名] の配列",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NameIndex"
                }
              }
            }
          },
          "400": {
            "description": "形が違う",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "無い都道府県コード",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/school/v1/meta.json": {
      "get": {
        "summary": "データの版・出典・件数",
        "operationId": "getSchoolMeta",
        "responses": {
          "200": {
            "description": "データの版",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Meta"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "SchoolCode": {
        "type": "string",
        "description": "学校コード13桁: 学校種(2)+都道府県番号(2)+設置区分(1)+学校番号(7)+検査数字(1)",
        "pattern": "^[A-H][12][0-9]{11}$",
        "example": "B113110000016"
      },
      "PrefCode": {
        "type": "string",
        "description": "都道府県コード2桁（01 北海道 〜 47 沖縄県）",
        "pattern": "^[0-9]{2}$",
        "example": "13"
      },
      "SchoolKind": {
        "type": "string",
        "description": "A1 幼稚園（幼稚園型認定こども園を含む）/ A2 幼保連携型認定こども園 / B1 小学校 / C1 中学校 / C2 義務教育学校 / D1 高等学校 / D2 中等教育学校 / E1 特別支援学校 / F1 大学 / F2 短期大学 / G1 高等専門学校 / H1 専修学校 / H2 各種学校",
        "enum": [
          "A1",
          "A2",
          "B1",
          "C1",
          "C2",
          "D1",
          "D2",
          "E1",
          "F1",
          "F2",
          "G1",
          "H1",
          "H2"
        ]
      },
      "Establishment": {
        "type": "string",
        "description": "1 国立 / 2 公立 / 3 私立",
        "enum": [
          "1",
          "2",
          "3"
        ]
      },
      "Branch": {
        "type": "string",
        "description": "main 本校 / branch 分校 / closed 廃校",
        "enum": [
          "main",
          "branch",
          "closed"
        ]
      },
      "SchoolRef": {
        "type": "object",
        "required": [
          "code",
          "name",
          "url"
        ],
        "properties": {
          "code": {
            "$ref": "#/components/schemas/SchoolCode"
          },
          "name": {
            "type": [
              "string",
              "null"
            ],
            "description": "学校名。一覧に無いコードは null"
          },
          "url": {
            "type": [
              "string",
              "null"
            ],
            "description": "その学校の URL。一覧に無いコードは null"
          }
        }
      },
      "School": {
        "type": "object",
        "required": [
          "code",
          "code12",
          "check_digit",
          "check_digit_valid",
          "check_digit_expected",
          "kind",
          "kind_label",
          "kind_detail",
          "prefcode",
          "prefecture",
          "establishment",
          "establishment_label",
          "school_number",
          "branch",
          "branch_label",
          "name",
          "address",
          "zipcode",
          "lgcode",
          "city",
          "lgcode_from",
          "valid_from",
          "abolished",
          "successors",
          "predecessors",
          "former_survey_number",
          "data_version"
        ],
        "properties": {
          "code": {
            "$ref": "#/components/schemas/SchoolCode"
          },
          "code12": {
            "type": "string",
            "description": "検査数字を除いた12桁"
          },
          "check_digit": {
            "type": "string",
            "description": "検査数字（13桁目）"
          },
          "check_digit_valid": {
            "type": "boolean",
            "description": "公表の計算方法で求めた検査数字と合えば true（合わないコードも実在する）"
          },
          "check_digit_expected": {
            "type": [
              "string",
              "null"
            ],
            "description": "合わないときだけ、公表の計算方法で求めた検査数字"
          },
          "kind": {
            "$ref": "#/components/schemas/SchoolKind"
          },
          "kind_label": {
            "type": "string",
            "description": "学校種の名前",
            "example": "小学校"
          },
          "kind_detail": {
            "type": [
              "string",
              "null"
            ],
            "description": "特別支援学校だけ元の資料の区別（養護・特支聾・特支盲）"
          },
          "prefcode": {
            "$ref": "#/components/schemas/PrefCode"
          },
          "prefecture": {
            "type": "string",
            "description": "都道府県名（学校コードの都道府県番号。大学等は本部の所在地）"
          },
          "establishment": {
            "$ref": "#/components/schemas/Establishment"
          },
          "establishment_label": {
            "type": "string",
            "description": "国立・公立・私立"
          },
          "school_number": {
            "type": "string",
            "description": "学校番号7桁"
          },
          "branch": {
            "$ref": "#/components/schemas/Branch"
          },
          "branch_label": {
            "type": "string",
            "description": "本校・分校・廃校"
          },
          "name": {
            "type": "string",
            "description": "学校名（元の資料のまま）"
          },
          "address": {
            "type": "string",
            "description": "学校所在地（元の資料のまま）"
          },
          "zipcode": {
            "type": [
              "string",
              "null"
            ],
            "description": "郵便番号7桁。元の値が7桁でなければ null"
          },
          "lgcode": {
            "type": [
              "string",
              "null"
            ],
            "description": "全国地方公共団体コード6桁（検査数字付き）"
          },
          "city": {
            "type": [
              "string",
              "null"
            ],
            "description": "その自治体の名前（政令市は区まで）"
          },
          "lgcode_from": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "address",
              "zipcode",
              "former_address",
              null
            ],
            "description": "自治体コードを何から付けたか"
          },
          "valid_from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "属性情報設定年月日"
          },
          "abolished": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "属性情報廃止年月日。今ある学校は null"
          },
          "successors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SchoolRef"
            },
            "description": "移行後の学校コード"
          },
          "predecessors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SchoolRef"
            },
            "description": "このコードを移行後に持つ学校"
          },
          "former_survey_number": {
            "type": [
              "string",
              "null"
            ],
            "description": "旧学校調査番号"
          },
          "data_version": {
            "type": "string",
            "description": "元の資料の基準日",
            "format": "date",
            "example": "2026-05-01"
          }
        }
      },
      "SchoolListItem": {
        "type": "object",
        "required": [
          "code",
          "name",
          "establishment",
          "branch",
          "address",
          "zipcode",
          "lgcode",
          "abolished"
        ],
        "properties": {
          "code": {
            "$ref": "#/components/schemas/SchoolCode"
          },
          "name": {
            "type": "string"
          },
          "establishment": {
            "$ref": "#/components/schemas/Establishment"
          },
          "branch": {
            "$ref": "#/components/schemas/Branch"
          },
          "address": {
            "type": "string"
          },
          "zipcode": {
            "type": [
              "string",
              "null"
            ],
            "description": "郵便番号7桁"
          },
          "lgcode": {
            "type": [
              "string",
              "null"
            ],
            "description": "自治体コード6桁"
          },
          "abolished": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          }
        }
      },
      "SchoolList": {
        "type": "object",
        "required": [
          "prefcode",
          "prefecture",
          "kind",
          "kind_label",
          "count",
          "active",
          "items",
          "data_version"
        ],
        "properties": {
          "prefcode": {
            "$ref": "#/components/schemas/PrefCode"
          },
          "prefecture": {
            "type": "string"
          },
          "kind": {
            "$ref": "#/components/schemas/SchoolKind"
          },
          "kind_label": {
            "type": "string"
          },
          "count": {
            "type": "integer",
            "description": "廃止された学校も含めた件数"
          },
          "active": {
            "type": "integer",
            "description": "今ある学校の件数"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SchoolListItem"
            }
          },
          "data_version": {
            "type": "string"
          }
        }
      },
      "PrefectureSummary": {
        "type": "object",
        "required": [
          "prefcode",
          "prefecture",
          "kinds",
          "names_url",
          "data_version"
        ],
        "properties": {
          "prefcode": {
            "$ref": "#/components/schemas/PrefCode"
          },
          "prefecture": {
            "type": "string"
          },
          "kinds": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "kind": {
                  "$ref": "#/components/schemas/SchoolKind"
                },
                "kind_label": {
                  "type": "string"
                },
                "count": {
                  "type": "integer"
                },
                "active": {
                  "type": "integer"
                },
                "url": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "description": "一覧の URL。1件も無ければ null"
                }
              }
            }
          },
          "names_url": {
            "type": "string"
          },
          "data_version": {
            "type": "string"
          }
        }
      },
      "NameIndex": {
        "type": "object",
        "required": [
          "prefcode",
          "prefecture",
          "count",
          "fields",
          "items",
          "data_version"
        ],
        "properties": {
          "prefcode": {
            "$ref": "#/components/schemas/PrefCode"
          },
          "prefecture": {
            "type": "string"
          },
          "count": {
            "type": "integer"
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "items": {
            "type": "array",
            "items": {
              "type": "array",
              "prefixItems": [
                {
                  "$ref": "#/components/schemas/SchoolCode"
                },
                {
                  "type": "string"
                }
              ],
              "minItems": 2,
              "maxItems": 2
            }
          },
          "data_version": {
            "type": "string"
          }
        }
      },
      "Meta": {
        "type": "object",
        "required": [
          "data_version",
          "edition",
          "edition_label",
          "built_at",
          "source",
          "sources",
          "counts",
          "kinds"
        ],
        "properties": {
          "data_version": {
            "type": "string",
            "description": "元の資料の基準日"
          },
          "edition": {
            "type": "string",
            "description": "暫定版・確定版"
          },
          "edition_label": {
            "type": "string"
          },
          "source_published": {
            "type": [
              "string",
              "null"
            ],
            "description": "文部科学省が CSV を更新した日"
          },
          "built_at": {
            "type": "string",
            "format": "date-time"
          },
          "source": {
            "type": "string",
            "description": "出典の書き方"
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "counts": {
            "type": "object"
          },
          "kinds": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "status",
              "code",
              "message"
            ],
            "properties": {
              "status": {
                "type": "integer"
              },
              "code": {
                "type": "string",
                "enum": [
                  "invalid_code",
                  "code_not_found",
                  "region_not_allowed",
                  "method_not_allowed"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
