Skip to content

Multipart object and array-of-binary fields make the method return HttpError::Config #87

Description

@iamralch

A multipart/form-data body with a field that is a JSON object, or an array of files, generates a method that returns HttpError::Config before sending anything, so the operation can't be called:

let mut req = self.http_client.put(request_url);
return Err(
    HttpError::Config(
            "multipart field `metadata` must be binary or a scalar text field"
                .to_string(),
        )
        .into(),
);
// the rest is unreachable

The rest of the method is unreachable, so it also compiles with unreachable_code, unused_variables and unused_mut warnings.

Reproduce

spec.yaml:

openapi: 3.0.3
info:
  title: multipart repro
  version: "1"
paths:
  /scripts:
    put:
      operationId: uploadScript
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [metadata]
              properties:
                # A JSON object, sent as one part, as Workers script uploads do.
                metadata:
                  type: object
                  properties:
                    main_module: { type: string }
                files:
                  type: array
                  items: { type: string, format: binary }
            encoding:
              metadata:
                contentType: application/json
      responses:
        "200":
          description: ok

openapi-to-rust.toml:

[generator]
spec_path = "spec.yaml"
output_dir = "out"
module_name = "repro"

[features]
enable_async_client = true

With 0.19.0, upload_script returns the error above for files. With files removed, it returns it for metadata instead, so each of the two shapes is unsupported on its own.

Expected:

  • an object field is serialized as JSON into one part, with the encoding.<field>.contentType from the document (application/json here), or application/json by default;
  • an array of binary is sent as one part per item, under the same name.

Where it comes from

Cloudflare's document, where 13 operations take one of these, among them uploading a Worker (PUT /accounts/{account_id}/workers/scripts/{script_name}: metadata object and files array), writing a KV value with metadata, and uploading to Images. They are some of the most used operations in the API, so the client can't be used for them at all.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions