Commit 01c6491
feat(validation): validate_publisher_properties_item accepts Pydantic models (#756)
Closes the documented Pydantic-XOR gap surfaced by the round-1 protocol
review on #729 / PR #753.
datamodel-codegen cannot translate the publisher-property-selector
JSON Schema's `allOf[not[required[both]]] + anyOf[required[either]]`
construct into Pydantic field constraints, so direct instantiation of
`PublisherPropertySelector1` / `…3` silently accepts payloads the schema
rejects (notably `{selection_type: "all"}` with neither
`publisher_domain` nor `publisher_domains` set).
This change lets Pydantic consumers close the gap with a single call:
selector = PublisherPropertySelector1.model_validate(payload)
validate_publisher_properties_item(selector) # raises if XOR fails
The helper now accepts either a dict (existing wire-form path) or any
object with a `.model_dump()` method (i.e. a Pydantic model). For
anything else it raises a clear error.
Tests cover both the model and the dict input forms plus the
type-error path. Auto-enforcement at parse time (a `model_validator`
attached post-class to the generated selectors) would require either
hand-patching generated_poc/ — forbidden by the codebase's strict
layering rule — or hooking Pydantic core-schema internals, which is
fragile. A separate follow-up issue tracks that work.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 76a679f commit 01c6491
2 files changed
Lines changed: 60 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
45 | 58 | | |
46 | | - | |
| 59 | + | |
| 60 | + | |
47 | 61 | | |
48 | 62 | | |
49 | 63 | | |
50 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
51 | 72 | | |
52 | 73 | | |
53 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2872 | 2872 | | |
2873 | 2873 | | |
2874 | 2874 | | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
2875 | 2912 | | |
2876 | 2913 | | |
2877 | 2914 | | |
| |||
0 commit comments