My goal is to set up a simple API for uploading a file via Google Endpoints.
This is my simplified OpenAPI specification which is valid according to Swagger validation:
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."
I always end up with this obscure error message:
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."
'
I've run out of ideas as to what might be the cause.
Any suggestions?
Looks like it requires at least some authentication: https://cloud.google.com/endpoints/docs/openapi/authentication-method
I also think that Cloud Endpoints don't support type: file, so you have to use type: string and use equivalent to curl -X POST -F "[email protected]" http://myservice.com/endpoint to upload.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With