Skip to content

Cast form values when matching allOf subschemas (#1212)#1213

Open
apoorvdarshan wants to merge 1 commit into
python-openapi:masterfrom
apoorvdarshan:fix-1212-allof-form-caster
Open

Cast form values when matching allOf subschemas (#1212)#1213
apoorvdarshan wants to merge 1 commit into
python-openapi:masterfrom
apoorvdarshan:fix-1212-allof-form-caster

Conversation

@apoorvdarshan

Copy link
Copy Markdown

Summary

Fixes #1212. For application/x-www-form-urlencoded requests, an allOf subschema that contains a non-string field (boolean, integer, object) is silently dropped — every field in that part disappears from the result, with only a log.warning("invalid allOf schema found") and an empty result.errors.

# schema: allOf: [ {enabled: boolean, label: string}, {name: string} ]
# body:   name=widget&label=hello&enabled=true
result.body    # -> {'name': 'widget'}   (enabled + label lost!)
result.errors  # -> []

Cause

Form values always arrive as strings. iter_any_of_schemas already takes an optional caster and coerces the value before validating each subschema (added for exactly this form-encoded case), but iter_all_of_schemas did not — so it validated the raw string value against the boolean/integer field, failed, and skipped the whole subschema.

Fix

Give iter_all_of_schemas the same optional caster parameter and casting logic as iter_any_of_schemas, and pass caster=self.schema_caster from iter_composed_all_of_schemas in the media-type deserializer (mirroring the existing anyOf call).

Now the example yields {'enabled': True, 'label': 'hello', 'name': 'widget'}.

Tests

  • Added test_urlencoded_allof_non_string_field; it fails on master (fields dropped, warning logged) and passes here.
  • tests/unit (excluding contrib/templating suites that need optional deps unrelated to this change) is green — 571 passed; ruff and black clean.

Disclosure: prepared with AI assistance; reviewed and verified locally.

For application/x-www-form-urlencoded requests, iter_any_of_schemas casts
scalar form values (which always arrive as strings) before validating each
subschema, but iter_all_of_schemas did not. An allOf part containing a
non-string field (boolean/integer/object) therefore failed validation
against the raw string value and was silently dropped (only a
'invalid allOf schema found' warning), losing every field in that part.

Give iter_all_of_schemas the same optional caster as iter_any_of_schemas
and pass it from the media-type deserializer.

Fixes python-openapi#1212.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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.

[Bug]: allOf in a request body silently drops fields for x-www-form-urlencoded requests

1 participant