feat(core): add explicit examples field to JsonSchema#91
Merged
Conversation
JsonSchema previously accepted `examples` only via `extra="allow"`, leaving it untyped, undocumented, and invisible to type checkers. Declare it as Optional[List[JsonType]] so the JSON Schema `examples` keyword is a first-class, validated field. Supports PR #88 (OpenAPI converter examples parsing), which currently relies on the extra-field fallback. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
h3xxit
added a commit
to shane-rand/python-utcp
that referenced
this pull request
Jun 24, 2026
Issue 2 — replace the blind cast on http_method with an explicit guard. OpenAPI allows operations (options/head/trace) that HttpCallTemplate's Literal type rejects; these are now skipped with a warning instead of crashing conversion via a Pydantic ValidationError. A shared SUPPORTED_HTTP_METHODS constant backs both the operation-loop filter and the per-operation check, so the cast is now truthful rather than assumed. Issue 3 — make example handling consistent across params, request bodies, and responses. Examples that appear at the schema level (not just the media type / parameter object) are now collected via _merge_examples and surfaced in the normalized JSON Schema 'examples' keyword, and the raw OpenAPI 'example'/'examples' keys are stripped before the schema is spread onto the property so they no longer leak through as untyped extra fields. This lines up with the explicit examples field added to JsonSchema in core (universal-tool-calling-protocol#91). Adds tests for unsupported-method skipping and schema-level example normalization. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
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.
What
Declares
examplesas a first-class field onJsonSchema:Why
JsonSchemapreviously acceptedexamplesonly viamodel_config extra="allow". That works at runtime but leaves the field:AttributesThis is the JSON Schema
exampleskeyword and belongs in the model explicitly.Context
Follow-up to #88 (OpenAPI converter examples parsing), which currently depends on the extra-field fallback to carry parsed examples through. With this field declared, that feature rests on a real, validated contract.
Tests
Adds
core/tests/data/test_tool_schema.py:model_fieldsNoneAll 4 pass. No serialization change (
model_dump(by_alias=True)already included extra fields; now it's a declared one).🤖 Generated with Claude Code
Summary by cubic
Add an explicit
examples: Optional[List[JsonType]]field toJsonSchemaso the JSON Schemaexampleskeyword is typed, validated, and documented. This removes reliance onextra="allow", keeps serialization unchanged, and stabilizes the OpenAPI converter’s examples parsing.Written for commit e31be05. Summary will update on new commits.