6

I'm struggling to pass the path params from my gateway to the actual endpoints.

Here is my Open API yaml:

swagger: '2.0'
info:
  description: |
    Blah blah
  version: 0.0.1
  title: SSAuth
  contact:
    email: [email protected]
schemes:
  - https
produces:
  - application/json
paths:
  /v0/auth/users/echo:
    get:
      summary: check the health of api
      operationId: healthCheck
      consumes:
        - application/json
      produces:
        - application/json
      responses:
        200:
          description: OK
      x-google-backend:
        address: https://path-to-my-cloud-run-service/v0/auth/users/echo
      security:
        - api_key: []

  /v0/auth/users/type/{type}:
    post:
      summary: Add a new user to the user
      operationId: addUser
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - name: type
          in: path
          description: provider type of the user
          required: true
          type: string
      responses:
        400:
          description: Invalid input
        200:
          description: OK
      x-google-backend:
        address: https://path-to-my-cloud-run-service/v0/auth/users/type/`type`
      security:
        - api_key: []

securityDefinitions:
  api_key:
    type: apiKey
    name: X-API-Key
    in: header

When I GET the first path, it works. But in the second path, there is a path param that I cannot find a way to pass to params to my Cloud Run URL. In the log, I see this https://path-to-my-cloud-run-service/v0/auth/users/type/%60type%60?type=email instead of https://path-to-my-cloud-run-service/v0/auth/users/type/email, and that cause my service to reject due to invalid type.

What do I need to change in my yaml to make this work?

1 Answer 1

13

Found the solution after digging here.

It's the path_transaltion, here is the working yaml:

swagger: '2.0'
info:
  description: |
    Blahblah
  version: 0.0.1
  title: Title
  contact:
    email: [email protected]
schemes:
  - https
produces:
  - application/json
paths:
  /v0/auth/users/echo:
    get:
      summary: check the health of api
      operationId: healthCheck
      consumes:
        - application/json
      produces:
        - application/json
      responses:
        200:
          description: OK
      x-google-backend:
        address: https://path-to-my-service
        path_translation: APPEND_PATH_TO_ADDRESS
      security:
        - api_key: []

  /v0/auth/users/type/{type}:
    post:
      summary: Add a new user to the user
      operationId: addUser
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - name: type
          in: path
          description: provider type of the user
          required: true
          type: string
      responses:
        400:
          description: Invalid input
        200:
          description: OK
      x-google-backend:
        address: https://path-to-my-service
        path_translation: APPEND_PATH_TO_ADDRESS
      security:
        - api_key: []

securityDefinitions:
  api_key:
    type: apiKey
    name: X-API-Key
    in: header
Sign up to request clarification or add additional context in comments.

3 Comments

have you tried with PUT and DELETE method? I always getting Cannot PUT /users/{user-id} error
Exactly what I am looking for. It works for me as well. Thanks.
I was facing same issue, was integrating my Google Cloud Run Service from Google API Gateway. have used path parameters, and was getting "GET /?id=4 HTTP/1.1" 404 Not Found instead of "GET /query/4 HTTP/1.1" 200 OK. adding path_translation: APPEND_PATH_TO_ADDRESS under x-google-backend: fixed the issue. Thank!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.