Skip to content

Conversation

@bokelley
Copy link
Contributor

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

  • Add 9 semantic aliases in src/adcp/types/aliases.py
  • Re-export from main package for ergonomics
  • Add 21 discriminator tests to verify correctness
  • Document pattern in CLAUDE.md to prevent future mistakes
  • Ensure aliases live in aliases.py, not auto-generated files

🤖 Generated with Claude Code

bokelley and others added 5 commits November 16, 2025 10:33
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 bokelley merged commit d776bc6 into main Nov 16, 2025
7 checks passed
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants