Skip to content

fix(relay/channel/aws): 修复AnthropicBeta字段的omitempty处理 - #2226

Merged
seefs001 merged 1 commit into
mainfrom
omit-anthropic_beta-empty
Nov 14, 2025
Merged

seefs001 merged 1 commit into
mainfrom
omit-anthropic_beta-empty

Conversation

@creamlike1024

@creamlike1024 creamlike1024 commented Nov 14, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Bug Fixes

  • Improved validation for API request data to prevent invalid or malformed values from being processed
  • Enhanced handling of optional fields to ensure cleaner data transmission

@coderabbitai

coderabbitai Bot commented Nov 14, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The AnthropicBeta field in AwsClaudeRequest is now marked optional in JSON serialization via the omitempty tag. Additionally, assignment of this field is now conditional, only populating it when the beta JSON unmarshals successfully into a non-empty string array.

Changes

Cohort / File(s) Change Summary
JSON serialization & validation
relay/channel/aws/dto.go
Added omitempty tag to AnthropicBeta JSON field to exclude empty values from serialization. Refactored formatRequest to conditionally assign AnthropicBeta only when betaJson unmarshals into a non-empty string array, replacing unconditional raw JSON assignment.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

  • Simple JSON tag modification for optional serialization
  • Straightforward validation logic with clear conditional checks
  • Single file with localized, low-complexity changes

Poem

🐰 A field marked omitempty, neat and tidy,
No clutter when the beta's shy.
Validation checks both ways—unmarshal with care,
Only assign when data's truly there! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing the omitempty handling for the AnthropicBeta field in the AWS relay channel DTO.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch omit-anthropic_beta-empty

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
relay/channel/aws/dto.go (1)

43-46: Good defensive validation before assignment.

The roundtrip validation (marshal → unmarshal) ensures the header values produce valid, non-empty JSON before setting AnthropicBeta. This pairs well with the omitempty tag to prevent sending empty or malformed beta features to AWS Bedrock.

Minor simplification opportunity: The check len(betaJson) > 0 on line 44 is redundant since len(tempArray) != 0 already implies betaJson is non-empty. You could simplify to:

-		if err := json.Unmarshal(betaJson, &tempArray); err == nil && len(tempArray) != 0 && len(betaJson) > 0 {
+		if err := json.Unmarshal(betaJson, &tempArray); err == nil && len(tempArray) != 0 {

Note: The current logic doesn't filter individual empty strings from the array (e.g., ["", "feature-1"] would be accepted as-is). This is likely fine for AWS Bedrock's handling, but worth noting if stricter validation is needed in the future.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7bef09 and 9e80e4e.

📒 Files selected for processing (1)
  • relay/channel/aws/dto.go (2 hunks)
🔇 Additional comments (1)
relay/channel/aws/dto.go (1)

15-15: LGTM! The omitempty tag correctly makes AnthropicBeta optional.

This prevents the field from appearing in the JSON output when it's empty or nil, which aligns with AWS Bedrock's expectations for optional beta features.

@seefs001
seefs001 merged commit 35192e5 into main Nov 14, 2025
@Calcium-Ion
Calcium-Ion deleted the omit-anthropic_beta-empty branch January 29, 2026 17:10
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…eta-empty

fix(relay/channel/aws): 修复AnthropicBeta字段的omitempty处理
@coderabbitai coderabbitai Bot mentioned this pull request Jun 16, 2026
8 of 11 tasks
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…eta-empty

fix(relay/channel/aws): 修复AnthropicBeta字段的omitempty处理
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…eta-empty

fix(relay/channel/aws): 修复AnthropicBeta字段的omitempty处理
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