0

假设我有一个带有两个必填字段的模型:

class ExampleModel(EndpointsModel):
    attr1 = ndb.StringProperty(required=True)
    attr2 = ndb.StringProperty(required=True)

然后我想使用 endpoints-proto-datastore 来查询attr1attr2:

@ExampleModel.query_method(query_fields=('attr1', 'attr2'),
                           path='example', name='list')
    def example_list(self, query):
        return query

如果我只提供其中一个字段,这将失败 - 在 API Explorer 中,这是一个必填字段,但 API 本身会返回:

{
 "error": {
  "code": 400, 
  "errors": [
   {
    "domain": "global", 
    "message": "Error parsing ProtoRPC request (Unable to parse request content: Message CombinedContainer is missing required field attr2)", 
    "reason": "badRequest"
   }
  ], 
  "message": "Error parsing ProtoRPC request (Unable to parse request content: Message CombinedContainer is missing required field attr2)"
 }
}

显然我可以将它们标记为不需要,然后在应用程序代码中处理检查 - 但我想知道是否有人提出了更好的解决方案。

非常感谢

4

1 回答 1

0

这是一个老问题,但我遇到了同样的困惑。是我找到的答案。基本上,如果您想在 Post 上强制执行某些操作,但不想让您需要制作自定义原型类。只能与方法一起使用,而不能与 query_method 一起使用。

于 2017-03-14T00:51:04.873 回答