Google Cloud API GatewayをOpenAPI v3でデプロイする。
概要 Google Cloud API GatewayはやっとOpenAPI v3に対応した。 (日本語ドキュメントは記載なし。英語ドキュメントには3.0.x対応が明記されている。2025-10-19現在。) これによりOpenAPI v3の表現力をGoogle Cloud API Gatewayでも享受できる。 まだ記載が少ないため、移行方法を日本語で残す。 想定構成 今回はAPI Gatewayのバックエンドとして、Cloud Runを用いる。 内容はstatusとtimestampを返すだけの単純なAPI。 Cloud Run エンドポイント: https://sample.run.app (Cloud RunコンソールやCLIで確認できる) これまでは以下の構成でOpenAPI v2を用いてデプロイしていた。 既存コード swagger: '2.0' info: title: Sample API description: API for short sample. version: 0.0.1 schemes: - https produces: - application/json paths: /sample: get: summary: Sample Endpoint operationId: sample x-google-backend: address: https://sample.run.app responses: '200': description: A successful response schema: type: object properties: status: type: string timestamp: type: string 変換先 仕様としては変化させない。Cloud Run エンドポイントも上記と同じ。 OpenAPI v3を使う。 openapi: 3.0.0 info: title: Sample API description: API for short sample. version: 0.0.1 x-google-api-management: backends: cloudrun_backend: address: https://sample.run.app paths: /sample: get: x-google-backend: cloudrun_backend summary: Sample Endpoint operationId: sample responses: "200": description: A successful response content: application/json: schema: type: object properties: status: type: string timestamp: type: string 移行手順 以下3ステップで簡単に実現できる。 ...