Skip to content

Add output_format discriminator to preview render schema#185

Merged
bokelley merged 1 commit into
mainfrom
preview-render-discriminator
Nov 7, 2025
Merged

Add output_format discriminator to preview render schema#185
bokelley merged 1 commit into
mainfrom
preview-render-discriminator

Conversation

@bokelley

@bokelley bokelley commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Summary

Add an output_format discriminator field to preview render responses to improve validation performance. Replaces inefficient oneOf constraint with conditional allOf validation based on discriminator value.

Changes

  • Added required output_format field with enum values: "url", "html", "both"
  • Updated schema validation logic in both single and batch preview responses
  • Updated documentation and examples to reflect discriminator usage

Benefits

Validation performance improvement, especially for responses with multiple renders (companion ads, multi-placement formats).

Replace oneOf validation with discriminator-based conditional validation to improve schema performance. Validators can now check output_format directly instead of trying all combinations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bokelley bokelley merged commit 435a624 into main Nov 7, 2025
5 checks passed
bokelley added a commit to adcontextprotocol/creative-agent that referenced this pull request Nov 7, 2025
Implements the schema changes from adcontextprotocol/adcp#185 which adds
a required output_format field to preview render responses. This discriminator
field indicates whether preview_url, preview_html, or both are provided,
improving validation performance by eliminating oneOf constraints.

Changes:
- Updated ADCP schemas from spec (preview-creative-response.json)
- Regenerated Pydantic models with output_format enum (url/html/both)
- Modified _generate_preview_variant() to set output_format based on
  which preview fields are provided
- All 187 tests passing

The output_format field is now required per spec:
- "url": preview_url only (iframe-embeddable)
- "html": preview_html only (direct embedding)
- "both": both preview_url and preview_html provided

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
bokelley added a commit to adcontextprotocol/creative-agent that referenced this pull request Nov 7, 2025
* Add output_format discriminator to preview responses

Implements the schema changes from adcontextprotocol/adcp#185 which adds
a required output_format field to preview render responses. This discriminator
field indicates whether preview_url, preview_html, or both are provided,
improving validation performance by eliminating oneOf constraints.

Changes:
- Updated ADCP schemas from spec (preview-creative-response.json)
- Regenerated Pydantic models with output_format enum (url/html/both)
- Modified _generate_preview_variant() to set output_format based on
  which preview fields are provided
- All 187 tests passing

The output_format field is now required per spec:
- "url": preview_url only (iframe-embeddable)
- "html": preview_html only (direct embedding)
- "both": both preview_url and preview_html provided

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Improve output_format implementation and test coverage

Address code review feedback:
- Fix error handling: raise ValueError instead of defaulting when neither
  preview_url nor preview_html is provided (fail fast approach)
- Reorder conditional logic for better readability (url/html/both)
- Update docstring to document output_format field behavior
- Add test assertions to verify output_format discriminator values
- Verify that only appropriate preview fields are present per mode

Tests verify:
- output_format="html" sets field and excludes preview_url
- output_format="url" sets field and excludes preview_html
- Both single and batch modes correctly set discriminator

All 187 tests passing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

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.

1 participant