Skip to content

fix(cli-generator): unwrap anyOf/oneOf when detecting multipart file fields - #17304

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1785436527-cli-multipart-nullable-binary
Open

fix(cli-generator): unwrap anyOf/oneOf when detecting multipart file fields#17304
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1785436527-cli-multipart-nullable-binary

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Description

Optional file uploads in generated CLIs sent the filename string as a plain text part instead of the file contents, so every optional upload was rejected by the API:

$ elevenlabs speech-to-text convert --model-id scribe_v2 --file ~/Desktop/cli.mp3
422 {"loc":["body","file"],"msg":"Value error, Expected UploadFile, received: <class 'str'>","input":"/Users/pma/Desktop/cli.mp3"}

Root cause: classify_multipart_property (generators/cli/sdk/src/openapi/parser.rs) only matched a bare type: string, format: binary / type: file (or an array of those). An optional file is emitted by most specs as a composition:

file:
  anyOf:
    - { type: string, format: binary }
    - { type: "null" }

which fell through to (is_file = false), so collect_multipart_parts sent the flag value as a text part. @path didn't help — the escape is handled inside the file branch that was never taken.

The check now also walks oneOf/anyOf branches (resolving $ref, skipping the null sentinel) and classifies on those, mirroring the existing nullable-union handling elsewhere in the parser:

if is_binary_schema(resolved) { return (true, octet_stream); }
for branch in resolved.one_of.iter().chain(resolved.any_of.iter()) {
    let effective = resolve_ref(branch);
    if is_null_sentinel(effective) { continue; }
    if is_binary_schema(effective) { return (true, octet_stream); }
}

is_binary_schema is the extracted predicate (direct binary, legacy type: file, and arrays of either), so nullable arrays of files are covered too.

Changes Made

  • generators/cli/sdk/src/openapi/parser.rs: unwrap anyOf/oneOf (incl. $ref branches) in multipart file-field classification; extract is_binary_schema.
  • Regenerated the vendored SDK copy in the seed/cli/* fixtures (verbatim copy, no other output changes).
  • Changelog entry under generators/cli/changes/unreleased/.

Testing

  • Unit tests added/updated — test_multipart_nullable_anyof_binary_is_file_part (inline anyOf [binary, null]) and test_multipart_nullable_oneof_ref_binary_is_file_part ($ref branch + nullable array of binaries). Both fail before the change, pass after; cargo test --lib multipart → 18 passed.

Link to Devin session: https://app.devin.ai/sessions/a4bcc0e77e634201a1259d693a9dfe45


Open in Devin Review

…fields

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@nitpickybot nitpickybot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review Summary

Targeted fix that unwraps anyOf/oneOf when classifying multipart file properties, plus the extracted is_binary_schema predicate and regenerated seed fixtures. Logic is correct for the reported case and behavior for the existing paths is preserved. A few resolution gaps remain ($ref inside items, allOf wrappers, nested compositions) that are common enough in real specs to be worth a follow-up.

  • 🟡 1 warning(s)
  • 🔵 2 suggestion(s)

Comment on lines 3519 to 3525
if ty == Some("array") {
if let Some(items) = &resolved.items {
if (items.schema_type() == Some("string")
if let Some(items) = &schema.items {
return (items.schema_type() == Some("string")
&& items.format.as_deref() == Some("binary"))
|| items.schema_type() == Some("file")
{
return (true, Some("application/octet-stream".to_string()));
}
|| items.schema_type() == Some("file");
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 warning

is_binary_schema doesn't resolve $ref in items, so the very common type: array, items: { $ref: '#/components/schemas/Upload' } (where Upload is string/binary) still falls through to a text part — the same class of bug this PR fixes, one level down. Consider threading component_schemas into the predicate and resolving items refs before checking type/format.

Comment on lines +3491 to +3506
// Optional / nullable uploads wrap the binary schema in a composition:
// `anyOf: [{type: string, format: binary}, {type: "null"}]`. Unwrap the
// non-null branches (resolving `$ref`) and classify on those.
for branch in resolved.one_of.iter().chain(resolved.any_of.iter()) {
let effective = branch
.schema_ref
.as_ref()
.and_then(|r| component_schemas.get(&strip_ref_prefix(r)))
.unwrap_or(branch);
if is_null_sentinel(effective) {
continue;
}
if is_binary_schema(effective) {
return (true, Some("application/octet-stream".to_string()));
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 suggestion

Only one level of composition is unwrapped: an allOf: [{$ref: Upload}] wrapper (used to attach a description to a binary field) or a nested anyOf inside a branch will still be missed. A small bounded-depth recursive helper would cover allOf and nested unions uniformly.

Comment on lines +3487 to +3504
if is_binary_schema(resolved) {
return (true, Some("application/octet-stream".to_string()));
}

// `type: string, format: binary` or legacy `type: file`
if (ty == Some("string") && fmt == Some("binary")) || ty == Some("file") {
let ct = Some("application/octet-stream".to_string());
return (true, ct);
// Optional / nullable uploads wrap the binary schema in a composition:
// `anyOf: [{type: string, format: binary}, {type: "null"}]`. Unwrap the
// non-null branches (resolving `$ref`) and classify on those.
for branch in resolved.one_of.iter().chain(resolved.any_of.iter()) {
let effective = branch
.schema_ref
.as_ref()
.and_then(|r| component_schemas.get(&strip_ref_prefix(r)))
.unwrap_or(branch);
if is_null_sentinel(effective) {
continue;
}
if is_binary_schema(effective) {
return (true, Some("application/octet-stream".to_string()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 suggestion

Some("application/octet-stream".to_string()) is now built in two places. Hoist it into a const OCTET_STREAM: &str (or a tiny fn file_part() helper) so the two return paths can't drift.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant