簡體   English   中英

GCP API 網關:無法使用路徑參數

[英]GCP API Gateway: Cannot use path params

我正在努力將路徑參數從我的網關傳遞到實際端點。

這是我打開的 API yaml:

swagger: '2.0'
info:
  description: |
    Blah blah
  version: 0.0.1
  title: SSAuth
  contact:
    email: blah@gmail.com
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

當我得到第一條路徑時,它就起作用了。 但是在第二條路徑中,有一個路徑參數,我找不到將參數傳遞給我的 Cloud Run URL 的方法。在日志中,我看到這個https://path-to-my-cloud-run-service/v0/auth/users/type/%60type%60?type=email而不是https://path-to-my-cloud-run-service/v0/auth/users/type/email ,這導致我的服務由於類型無效而拒絕。

我需要在我的 yaml 中更改什么才能使其正常工作?

我遇到的另一個問題是,如果我在正文中放入 json,即使我指定它使用 application/json,GET 請求也會收到 400 個錯誤請求。

這里挖掘后找到了解決方案。

這是 path_transaltion,這里是工作 yaml:

swagger: '2.0'
info:
  description: |
    Blahblah
  version: 0.0.1
  title: Title
  contact:
    email: blah@gmail.com
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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM