Swagger / OpenAPI 规范的特点是文件上传被 Google Endpoints 拒绝

Raf*_*ael 5 python google-cloud-platform swagger-2.0 openapi

我的目标是建立一个简单的 API,用于通过 Google Endpoints 上传文件。

这是我的简化 OpenAPI 规范,根据 Swagger 验证它是有效的:

swagger: "2.0"
info:
  title: "JSON Ingester"
  description: "Receive JSON files, transform and load them."
  version: "1.0.0"

host: "project-id.appspot.com"
schemes:
  - "https"

paths:
  /uploadFile:
    post:
      operationId: uploadFile
      consumes:
        - multipart/form-data
      parameters:
        - 
          in: formData
          name: upfile
          type: file
          description: file
      responses:
        200:
          description: "File uploaded."
        400:
          description: "Error during file upload."
Run Code Online (Sandbox Code Playgroud)

我总是得到这个晦涩的错误消息:

user@cloudshell:~/google-cloud-json-ingester (project-id)$ gcloud endpoints services deploy ./openapi.yaml
ERROR: (gcloud.endpoints.services.deploy) INVALID_ARGUMENT: Cannot convert to service config.
'location: "openapi.yaml: Operation \'post\' in path \'/uploadFile\'"
message: "Operation does not require an API key; callers may invoke the method without specifying an associated API-consuming project. To enable API key all the SecurityRequirement Objects (https://gi
thub.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-requirement-object) inside security definition must reference at least one SecurityDefinition of type : \'apiKey\'."
 location: "unknown location"
kind: ERROR
message: "http: repeated message field \'google.protobuf.Struct.fields\' referred to by message \'UploadFileRequest\' cannot be mapped as an HTTP parameter."
 location: "unknown location"
kind: ERROR
message: "http: cyclic message field \'google.protobuf.Struct.FieldsEntry.value\' referred to by message \'UploadFileRequest\' in method \'method 1.project_id_appspot_com.UploadFile\' cannot
 be mapped as an HTTP parameter."
 location: "unknown location"
kind: ERROR
message: "http: cyclic message field \'google.protobuf.ListValue.values\' referred to by message \'UploadFileRequest\' in method \'method 1.project_id_appspot_com.UploadFile\' cannot be mapp
ed as an HTTP parameter."
'
Run Code Online (Sandbox Code Playgroud)

对于可能的原因我已经没有想法了。

有什么建议么?

小智 1

看起来它至少需要一些身份验证:https://cloud.google.com/endpoints/docs/openapi/authentication-method

我还认为 Cloud Endpoints 不支持type: file,因此您必须使用type: string并使用相当于curl -X POST -F "file_upload=@file.txt" http://myservice.com/endpoint的上传。