# Example Swagger configuration for API Gateway
swagger: "2.0"
info:
title: User Check API Gateway
version: "1.0.0"
schemes:
- https
paths:
/get-hello:
get:
summary: Public GET
Endpoint
operationId: getUserInfo
x-google-backend:
address:
https://us-central1-learning-cloud-450805.cloudfunctions.net/getHelloWorld
protocol: h2
responses:
"200":
description:
"Successful GET request"
/get-user-data:
get:
summary: Secure GET Endpoint
(Requires API Key)
operationId: getUserData
x-google-backend:
address:
https://us-central1-learning-cloud-450805.cloudfunctions.net/getUserData
protocol: h2
security:
- api_key: []
responses:
"200":
description:
"Successful authenticated request"
securityDefinitions:
api_key:
type: apiKey
name: x-api-key
in: header
# Example Swagger configuration for API Gateway
swagger: "2.0"
info:
title: User Check API Gateway
version: "1.0.0"
schemes:
- https
paths:
/get-hello:
get:
summary: Public GET
Endpoint
operationId: getUserInfo
x-google-backend:
address:
https://us-central1-learning-cloud-450805.cloudfunctions.net/getHelloWorld
protocol: h2
responses:
"200":
description:
"Successful GET request"
/get-user-data:
get:
summary: Secure GET Endpoint
(Requires API Key)
operationId: getUserData
x-google-backend:
address:
https://us-central1-learning-cloud-450805.cloudfunctions.net/getUserData
protocol: h2
security:
- api_key: []
responses:
"200":
description:
"Successful authenticated request"
securityDefinitions:
api_key:
type: apiKey
name: x-api-key
in: header
# Advanced Swagger configuration for API Gateway
swagger: "2.0"
info:
title: Advanced User Check API Gateway
description: Fully advanced Swagger config with API
key, OAuth2, JWT, quota, and CORS
version: "1.0.0"
host: example-api.gateway.dev
schemes:
- https
basePath: /
consumes:
- application/json
produces:
- application/json
x-google-endpoints:
- name: example-api.gateway.dev
allowCors: true
paths:
/get-hello:
get:
summary: Public GET
Endpoint
description: Simple hello
endpoint without auth
operationId: getUserInfo
x-google-backend:
address:
https://us-central1-learning-cloud-450805.cloudfunctions.net/getHelloWorld
protocol: h2
deadline:
15.0
path_translation:
APPEND_PATH_TO_ADDRESS
responses:
"200":
description:
Successful GET request
/get-user-data:
get:
summary: Secure GET Endpoint
(Requires API Key)
operationId: getUserData
x-google-backend:
address:
https://us-central1-learning-cloud-450805.cloudfunctions.net/getUserData
protocol: h2
deadline:
20.0
security:
- api_key: []
responses:
"200":
description:
Successful authenticated request
"401":
description:
Unauthorized
/get-user-oauth:
get:
summary: OAuth2 Secured
Endpoint
operationId: getUserOAuth
x-google-backend:
address:
https://us-central1-learning-cloud-450805.cloudfunctions.net/getUserOAuth
security:
-
google_id_token: []
- firebase:
[]
responses:
"200":
description:
Authenticated via OAuth2 / JWT
"403":
description:
Forbidden
securityDefinitions:
api_key:
type: apiKey
name: x-api-key
in: header
google_id_token:
type: oauth2
authorizationUrl: ""
flow: implicit
x-google-issuer:
https://accounts.google.com
x-google-jwks_uri:
https://www.googleapis.com/oauth2/v3/certs
x-google-audiences:
example-api-client-id.apps.googleusercontent.com
firebase:
type: oauth2
authorizationUrl: ""
flow: implicit
x-google-issuer:
https://securetoken.google.com/my-firebase-project
x-google-jwks_uri:
https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com
x-google-audiences:
my-firebase-project
x-google-quota:
limits:
requests_per_minute:
name: per-minute
metric:
serviceruntime.googleapis.com/api/request_count
unit: 1/min/{project}
values:
STANDARD: 100
requests_per_day:
name: per-day
metric:
serviceruntime.googleapis.com/api/request_count
unit: 1/day/{project}
values:
STANDARD:
5000
x-google-backend:
deadline: 30.0
protocol: h2
path_translation: APPEND_PATH_TO_ADDRESS
x-google-allow:
- GET
- POST
- OPTIONS
x-google-allow-credentials: true
x-google-allow-headers:
- Authorization
- Content-Type
- x-api-key
x-google-allow-origin: "*"
x-google-custom-errors:
rules:
- error_code: 404
error_message: Custom Not Found
Message
- error_code: 500
error_message: Something went wrong,
please try again later.
# Full Advanced Swagger configuration for API Gateway
swagger: "2.0"
info:
title: Full Auth API Gateway
description: Includes public, API key, JWT, OAuth2,
and custom key secured endpoints
version: "1.0.0"
host: example-api.gateway.dev
schemes:
- https
basePath: /
consumes:
- application/json
produces:
- application/json
x-google-endpoints:
- name: example-api.gateway.dev
allowCors: true
paths:
/auth/login:
post:
summary: User Login
(Public)
description: Authenticate
user and return JWT token
operationId: userLogin
x-google-backend:
address:
https://us-central1-project.cloudfunctions.net/login
responses:
"200":
description:
Login successful (returns JWT)
/auth/logout:
post:
summary: User Logout
(Requires JWT)
operationId: userLogout
x-google-backend:
address:
https://us-central1-project.cloudfunctions.net/logout
security:
- jwt_auth:
[]
responses:
"200":
description:
Logout successful
/auth/register:
post:
summary: User Registration
(Public)
operationId: userRegister
x-google-backend:
address:
https://us-central1-project.cloudfunctions.net/register
responses:
"200":
description:
Registration successful
/dashboard:
get:
summary: Dashboard (Requires
API Key)
operationId: getDashboard
x-google-backend:
address:
https://us-central1-project.cloudfunctions.net/dashboard
security:
- api_key: []
responses:
"200":
description:
Dashboard data
/dashboard/course:
get:
summary: Dashboard Course
(Requires OAuth2 or Custom Key)
operationId:
getDashboardCourse
x-google-backend:
address:
https://us-central1-project.cloudfunctions.net/course
security:
- google_oauth:
[]
- custom_key:
[]
responses:
"200":
description:
Course data
securityDefinitions:
api_key:
type: apiKey
name: x-api-key
in: header
jwt_auth:
type: oauth2
flow: implicit
x-google-issuer:
https://securetoken.google.com/my-project
x-google-jwks_uri:
https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com
x-google-audiences: my-project
google_oauth:
type: oauth2
flow: implicit
x-google-issuer:
https://accounts.google.com
x-google-jwks_uri:
https://www.googleapis.com/oauth2/v3/certs
x-google-audiences:
client-id.apps.googleusercontent.com
custom_key:
type: apiKey
name: x-custom-key
in: header
x-google-quota:
limits:
requests_per_minute:
name: per-minute
metric:
serviceruntime.googleapis.com/api/request_count
unit: 1/min/{project}
values:
STANDARD: 100
x-google-allow:
- GET
- POST
- OPTIONS
x-google-allow-origin: "*"
x-google-allow-headers:
- Authorization
- Content-Type
- x-api-key
- x-custom-key
x-google-allow-credentials: true
# Advanced Swagger 2.0 Example with Multiple Security Types
swagger: "2.0"
info:
title: Full Auth Example API Gateway
version: "1.0.0"
schemes:
- https
paths:
/register:
post:
summary: Public Register (no
auth required)
operationId: registerUser
x-google-backend:
address:
https://example.com/register
responses:
"200":
description:
"User registered successfully"
/login:
post:
summary: Login with
username/password to get JWT
operationId: loginUser
x-google-backend:
address:
https://example.com/login
responses:
"200":
description:
"Returns JWT token"
/logout:
post:
summary: Logout (requires
JWT)
operationId: logoutUser
security:
- jwt_token: []
# depends on login
x-google-backend:
address:
https://example.com/logout
responses:
"200":
description:
"User logged out"
/dashboard:
get:
summary: Secure dashboard
(JWT or OAuth2)
operationId: getDashboard
security:
- jwt_token: []
# OR
- oauth2: [read]
# dashboard can be accessed via oauth2 scope
x-google-backend:
address:
https://example.com/dashboard
responses:
"200":
description:
"Dashboard data"
/dashboard/course:
get:
summary: Advanced - Requires
BOTH JWT + Custom API Key
operationId: getCourses
security:
- jwt_token:
[]
- api_key: [] #
multi-factor security
x-google-backend:
address:
https://example.com/dashboard/course
responses:
"200":
description:
"Course list"
securityDefinitions:
# 1. Custom API Key
api_key:
type: apiKey
name: x-api-key
in: header
# 2. JWT (Bearer Token)
jwt_token:
type: apiKey
name: Authorization
in: header
x-google-issuer:
"https://securetoken.google.com/project-id"
x-google-jwks_uri:
"https://www.googleapis.com/service_accounts/v1/jwk/project-id"
x-google-audiences: "project-id"
# 3. OAuth2
oauth2:
type: oauth2
authorizationUrl:
"https://accounts.google.com/o/oauth2/auth"
flow: accessCode
tokenUrl:
"https://oauth2.googleapis.com/token"
scopes:
read: "Read access to
dashboard"
write: "Write access to
dashboard"
Tip: Use the
OpenAPI specification to define your API structure, security
requirements, and backend connections in a standardized format.