【发布时间】:2021-03-03 08:28:20
【问题描述】:
我刚刚开始使用 Google Cloud Endpoints。我正在尝试向 Echo 示例添加一个新方法,以简单地使用 GET 而不是 POST。部署后,好像找不到新的API方法。对于我的生活,我无法弄清楚。
这是名为 echo2 的新方法的 java 代码。 HttpdMethod 从 POST 更改为 GET,msg 参数从 Message 更改为 String。
@ApiMethod(name = "echo2",httpMethod = ApiMethod.HttpMethod.GET)
public Message echo2( @Named("msg") String msg, @Named("n") @Nullable Integer n )
{
logger.info( "echo2(): msg=" + msg + ", and n=" + n );
return doEcho( msg, n );
}
这是添加到 openapi.json 的代码。我做了两处更改:i) 第一个参数更改为查询参数 ii) 第一个参数从 Message 对象(仅包含一个字符串)更改为 String。
"/echo/v1/echo2": {
"get": {
"operationId": "Echo2",
"parameters": [
{
"name": "msg",
"in": "query",
"required": true,
"type": "string"
},
{
"name": "n",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "A successful response",
"schema": {
"$ref": "#/definitions/Message"
}
}
}
}
},
我部署这个(到 Google App Engine 标准),重新部署 openapi.json 并运行下面的 curl,响应是 404。
curl --request GET 'https://mytestapi.appspot.com/_ah/api/echo/v1/echo2?msg=hey' --header '接受:application/json' --header 'Content-Type : 应用程序/json'
我做错了什么?
【问题讨论】:
标签: google-app-engine swagger google-cloud-endpoints openapi