Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCP API Gateway: Cannot use path params

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?

like image 613
Son Nguyen Avatar asked Sep 02 '26 22:09

Son Nguyen


1 Answers

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
like image 98
Son Nguyen Avatar answered Sep 04 '26 11:09

Son Nguyen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!