-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add semantic type aliases for discriminated unions #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+561
−27
Conversation
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
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>
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>
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>
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>
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.
bokelley
added a commit
that referenced
this pull request
Nov 18, 2025
* 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>
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.
Summary
Adds semantic type aliases for discriminated union types that have numbered names from code generation. Aliases map numbered variants (e.g.,
PreviewRender1,PreviewRender2) to descriptive names based on their discriminator field values (e.g.,UrlPreviewRender,HtmlPreviewRender).Includes 9 semantic aliases for Preview Renders, VAST Assets, DAAST Assets, and SubAssets, plus comprehensive tests validating discriminator values and serialization roundtrips.
Changes
src/adcp/types/aliases.pyaliases.py, not auto-generated files🤖 Generated with Claude Code