Skip to content

Conversation

@majiayu000
Copy link

Fixes #1019

Changes

  • Use json.RawMessage instead of jsonschema.Definition to preserve all JSON Schema features during unmarshal
  • Add validation to ensure schema is a JSON object
  • Add comprehensive tests for JSON Schema features (anyOf, oneOf, allOf, const, title, $defs, $ref)

🤖 Generated with Claude Code

The previous implementation converted JSON Schema to jsonschema.Definition
during unmarshal, which lost unsupported features like anyOf, oneOf, allOf,
const, title, and other JSON Schema Draft 2020-12 features.

This fix uses json.RawMessage to preserve the complete schema during
round-trip (unmarshal/marshal), ensuring all JSON Schema features are
maintained while still validating that the schema is a valid JSON object.

Fixes sashabaranov#1019

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

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Signed-off-by: majiayu000 <[email protected]>
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.51%. Comparing base (5d7a276) to head (60ce150).

Files with missing lines Patch % Lines
chat.go 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1098      +/-   ##
==========================================
- Coverage   99.59%   99.51%   -0.09%     
==========================================
  Files          34       34              
  Lines        2209     1842     -367     
==========================================
- Hits         2200     1833     -367     
+ Misses          6        5       -1     
- Partials        3        4       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…JSON

Add test cases to improve coverage for the schema validation logic:
- Test invalid schemas (array, string, number, boolean)
- Test valid schemas with leading whitespace (spaces, tabs, newlines)
- Test null schema and missing schema field
- Ensure proper error messages for invalid schemas

This improves test coverage for the new validation code in
ChatCompletionResponseFormatJSONSchema.UnmarshalJSON.

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

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant