fix(responses): default missing InputImageContent.detail during deserialization#546
Merged
Merged
Conversation
- default InputImageContent.detail to auto when missing in JSON input - add focused response-types integration tests covering both the EasyMessage and strict Item::Message(Input::User) deserialization paths InputImageContent.detail is documented as defaulting to `auto`, but without #[serde(default)] any spec-compliant payload that omits it (per openai-python's ResponseInputImageParam, which marks detail Optional[Literal["low","high","auto"]]) fails to deserialize. Because InputItem is #[serde(untagged)], the single missing-field error rolls up to "data did not match any variant of untagged enum InputItem", which is what spec-compliant clients hit in practice. Closes 64bit#545. Refs: - openapi.documented.yml: ResponseInputImage (type required; image_url/file_id/detail all optional) - openai-python: src/openai/types/responses/response_input_image_param.py (detail: Optional[Literal["low", "high", "auto"]]) - openai-node: src/resources/responses/responses.ts (detail?: 'low'|'high'|'auto') - Prior fix in same spirit: 64bit#527
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
InputImageContent.detailtoautowhen missing in JSON inputEasyMessageand strictItem::Message(Input::User)deserialization pathsCloses #545.
InputImageContent.detailis documented as defaulting toauto, but without#[serde(default)]any spec-compliant payload that omitsdetail(peropenai-python's
ResponseInputImageParam, which marksdetailOptional[Literal["low","high","auto"]]) fails to deserialize. BecauseInputItemis#[serde(untagged)], the single missing-field error rolls upto
data did not match any variant of untagged enum InputItem, which iswhat spec-compliant clients hit in practice (full traceback in #545).
This mirrors the precedent set by #527 (
EasyInputMessage.r#type,WebSearchApproximateLocation.r#type) and uses the same test file(
tests/responses_input_item_serde.rs).ImageDetailalready derivesDefaultwith#[default] Auto, so thefix is a single
#[serde(default)]attribute — noDefaultimpl needed.Verification
cargo test -p async-openai --test responses_input_item_serde --features response-types→ 4 passed (2 pre-existing + 2 new)cargo fmt --check→ cleancargo clippy -p async-openai --features response-types --tests -- -D warnings→ cleandata did not match any variant of untagged enum InputItem; against this branch the same payload deserializes successfully withdetaildefaulted toImageDetail::Auto.{ "role": "user", "content": [ {"type": "input_text", "text": "describe this"}, {"type": "input_image", "image_url": "https://example.com/cat.png"} ] }Refs:
ResponseInputImage(type required;image_url/file_id/detailall optional)src/openai/types/responses/response_input_image_param.py—detail: Optional[Literal["low", "high", "auto"]]src/resources/responses/responses.ts—detail?: 'low' | 'high' | 'auto'