I have a backend developed in FastApi using OpenAPI 3.0. It's hosted in GCP Cloud. The FastAPI is auto-documented (Swagger UI), and it's exposed to internet.
Now, I am deploying a GCP API Gateway in front of this service. This is the openapi.yaml that is deployed in GCP API Gateway.
swagger: '2.0'
info:
title: care-chat
description: Sample API on API Gateway with a Cloud Run backend
version: 1.0.0
schemes:
- https
produces:
- application/json
x-google-backend:
address: https://care-navigation-api-zibxv3ldca-ue.a.run.app
paths:
"/api/v1/tenants":
get:
summary: Tenant
operationId: getTenants
responses:
200:
description: "Success."
schema:
type: string
Basically I have two questions:
As I have shared in the above Comment, this Article explains the step by step for using FastAPI and GCP API Gateway
.
The well known problem is clearly explained in the Article, Bridging the Gap: Converting FastAPI OpenAPI to Swagger 2.0 for GCP API Gateway compatibility
which will do the trick.
The Problem
Incompatibility issue between the OpenAPI document supported by GCP API Gateway, and the OpenAPI document automatically generated from FastAPI itself. Indeed, GCP API Gateway only supports the OpenAPI version 2.0 specification. On the other side, the OpenAPI doc produced using the .openapi() method, only supports version 3.0.
This mismatch necessitates a manual conversion of the OpenAPI document to version 2.0 before it can be utilized by API Gateway.
The Solution: For this will be clearly explained in the Link.
Also the Article contains the clear explanation for: