Commit bb49e44
feat: Add semantic type aliases for discriminated unions (#49)
* feat: Add semantic type aliases for discriminated unions
Add clear, descriptive type aliases for discriminated union types that
were previously only available with auto-generated numbered names
(e.g., PreviewRender1, SubAsset1).
New semantic aliases:
- Preview Renders (output_format discriminator):
* UrlPreviewRender = PreviewRender1 (output_format='url')
* HtmlPreviewRender = PreviewRender2 (output_format='html')
* BothPreviewRender = PreviewRender3 (output_format='both')
- VAST Assets (delivery_type discriminator):
* UrlVastAsset = VastAsset1 (delivery_type='url')
* InlineVastAsset = VastAsset2 (delivery_type='inline')
- DAAST Assets (delivery_type discriminator):
* UrlDaastAsset = DaastAsset1 (delivery_type='url')
* InlineDaastAsset = DaastAsset2 (delivery_type='inline')
- SubAssets (asset_kind discriminator):
* MediaSubAsset = SubAsset1 (asset_kind='media')
* TextSubAsset = SubAsset2 (asset_kind='text')
All aliases are:
- Exported from adcp.types.aliases
- Exported from adcp.types.generated
- Re-exported from main adcp package for convenience
- Fully tested with comprehensive test coverage
This improves code readability by conveying semantic meaning rather
than relying on generated numbering.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* docs: Document semantic type alias patterns and generated file policy
Add comprehensive documentation for:
- How to add semantic type aliases for discriminated unions
- Process for creating, exporting, and testing aliases
- Current list of all semantic aliases in the codebase
- Guidelines for when to create aliases vs when not to
- Clarify that generated.py must never be manually modified
This ensures future developers understand the alias system and don't
accidentally modify auto-generated code.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: Remove semantic aliases from generated.py (will be overwritten)
The semantic type aliases were incorrectly added to generated.py,
which is auto-generated and will be overwritten on next type generation.
Moved all semantic alias imports to use aliases.py directly:
- src/adcp/types/__init__.py now imports from aliases instead of generated
- Removed all alias definitions and exports from generated.py
- All functionality preserved through aliases.py
This ensures aliases survive type regeneration.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: Remove misleading PreviewRender aliases
Removed the old, misleading aliases for PreviewRender types:
- PreviewRenderImage (misleading - actually output_format='url')
- PreviewRenderHtml (ambiguous - doesn't clarify it's output_format)
- PreviewRenderIframe (misleading - actually output_format='both')
Kept only the accurate, discriminator-based aliases:
- UrlPreviewRender (output_format='url')
- HtmlPreviewRender (output_format='html')
- BothPreviewRender (output_format='both')
These names accurately reflect the discriminator field values and
prevent confusion about what the types represent.
Since this is brand new code with no existing users, removing the
misleading names now prevents technical debt.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* test: Add comprehensive discriminator tests for semantic type aliases
Verifies that semantic aliases match their discriminator field values:
- PreviewRender: output_format ('url', 'html', 'both')
- VastAsset: delivery_type ('url', 'inline')
- DaastAsset: delivery_type ('url', 'inline')
- SubAsset: asset_kind ('media', 'text')
Tests validate:
- Correct discriminator values are present
- Correct fields exist for each variant
- Wrong discriminator values are rejected
- Serialization/deserialization roundtrips work correctly
21 new tests, all passing.
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1968ecf commit bb49e44
File tree
6 files changed
+561
-27
lines changed- src/adcp
- types
- tests
6 files changed
+561
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
67 | 163 | | |
68 | 164 | | |
69 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| 78 | + | |
76 | 79 | | |
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
80 | 86 | | |
81 | 87 | | |
82 | 88 | | |
| |||
219 | 225 | | |
220 | 226 | | |
221 | 227 | | |
| 228 | + | |
222 | 229 | | |
223 | 230 | | |
224 | 231 | | |
225 | 232 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
232 | 237 | | |
233 | 238 | | |
234 | 239 | | |
235 | 240 | | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | 241 | | |
240 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
241 | 250 | | |
242 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
243 | 255 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
5 | 16 | | |
6 | 17 | | |
7 | 18 | | |
| |||
24 | 35 | | |
25 | 36 | | |
26 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
27 | 48 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| |||
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
| |||
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
70 | 79 | | |
71 | 80 | | |
72 | 81 | | |
| |||
157 | 166 | | |
158 | 167 | | |
159 | 168 | | |
160 | | - | |
161 | | - | |
162 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
163 | 172 | | |
164 | | - | |
165 | | - | |
| 173 | + | |
| 174 | + | |
166 | 175 | | |
167 | | - | |
168 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
169 | 203 | | |
170 | 204 | | |
171 | 205 | | |
| |||
178 | 212 | | |
179 | 213 | | |
180 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
181 | 225 | | |
182 | 226 | | |
183 | 227 | | |
| |||
193 | 237 | | |
194 | 238 | | |
195 | 239 | | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | 240 | | |
201 | 241 | | |
202 | 242 | | |
| |||
0 commit comments