I am currently setting up first API Gateway with Google cloud platform but I am now a little confused how I can add a header to all requests, is it possible in the .yaml file? Here's what it looks like so far. Where it says my_api_key is where my real one is and I want to send it as a header to all upcoming endpoints. Is it possible?
x-cg-pro-api-key: my_api_key
swagger: "2.0"
info:
title: Crypto API
description: API Gateway with Cloud Run backend.
version: 1.0.0
schemes:
- https
produces:
- application/json
paths:
/new:
get:
summary: Returns a list of new coins.
operationId: new
x-google-backend:
address: https://pro-api.coingecko.com/api/v3/coins/list/new
parameters:
- in: header
name: x-cg-pro-api-key
type: string
responses:
'200':
description: OK
schema:
type: string
Googling a lot, trying different things
I would highly recommend using the latest version of OpenAPI 3.1.0.
Swagger:2.0is quite old.I defined the
securitySchemesin thecomponentscollection and then you need to addsecurityto either the root or individual endpoints, like the example below.bonus content: RFC9457 defines
problem+jsonschema which is recommended as a common error reporting schema for http apis.EDIT:
Because Google API Gateway doesn't support OAS 3.x.x, Swagger 2.0 is required.
here's a sample of using
security.