Swagger / OpenAPI spec featuring file upload rejected by Google Endpoints
Asked Answered
B

3

6

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?

Bag answered 2/7, 2019 at 13:54 Comment(0)
P
1

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.

Piscine answered 3/7, 2019 at 9:35 Comment(1)
I doubt authentication is the issue here b/c that same message will always be shown - even when going through for other paths - but then as a warning. Possible that Endpoints doesn't support "file" despite them explicitly advertising support of OpenAPI 2.0. Using type=string should be a viable workaround.Bag
C
3

I solved this by copying and pasting my swagger file into https://editor.swagger.io/ to identify bugs and referencing https://swagger.io/specification/v2/ to fix the errors.

Chukar answered 18/11, 2022 at 17:26 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Ephesians
P
1

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.

Piscine answered 3/7, 2019 at 9:35 Comment(1)
I doubt authentication is the issue here b/c that same message will always be shown - even when going through for other paths - but then as a warning. Possible that Endpoints doesn't support "file" despite them explicitly advertising support of OpenAPI 2.0. Using type=string should be a viable workaround.Bag
U
0

I ran into this problem today and created a repro. I believe that your issue likely lies in the order of:

in: formData
name: upfile

If you are still seeing this issue, can you please try reversing the order:

name: upfile
in: formData

Uprush answered 23/9, 2020 at 23:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.