我正在努力将路径参数从网关传递到实际端点。
这是我的 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
当我得到第一条路径时,它就起作用了。但在第二条路径中,有一个路径参数,我无法找到将参数传递给我的 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 错误请求。
挖掘后找到解决方案here.
这是 path_transaltion,这是工作 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)