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.
A
multipart/form-databody with a field that is a JSON object, or an array of files, generates a method that returnsHttpError::Configbefore sending anything, so the operation can't be called:The rest of the method is unreachable, so it also compiles with
unreachable_code,unused_variablesandunused_mutwarnings.Reproduce
spec.yaml:openapi-to-rust.toml:With 0.19.0,
upload_scriptreturns the error above forfiles. Withfilesremoved, it returns it formetadatainstead, so each of the two shapes is unsupported on its own.Expected:
encoding.<field>.contentTypefrom the document (application/jsonhere), orapplication/jsonby default;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}:metadataobject andfilesarray), 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.