Skip to content

Make requests Encodable-only instead of Codable #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 2, 2025
Merged

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 2, 2025

This PR changes WPNRequestBase and the generic parameter T in WPNRequest<T> from Codable to Encodable only, reducing constraints on integrators.

Changes Made

  • Changed WPNRequestBase: Codable to WPNRequestBase: Encodable
  • Changed WPNRequest<T: Codable> to WPNRequest<T: Encodable>
  • Removed the unused init(from decoder:) method from WPNRequest class

Benefits for Integrators

Before (required Codable):

struct MyRequestPayload: Codable {  // Had to be Codable
    let userId: String
    let amount: Double
    
    // Had to implement init(from decoder:) even though it's never used!
    init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        userId = try container.decode(String.self, forKey: .userId)
        amount = try container.decode(Double.self, forKey: .amount)
    }
    // ... plus encode(to:) and CodingKeys
}

After (only requires Encodable):

struct MyRequestPayload: Encodable {  // Only needs to be Encodable!
    let userId: String
    let amount: Double
    
    // No need for init(from decoder:) - much cleaner!
    // Automatic synthesis of encode(to:) works perfectly
}

Rationale

Request objects are only encoded (sent to server), never decoded (received from server). Requiring Codable forced integrators to implement unnecessary Decodable conformance. This change:

  • ✅ Reduces boilerplate code for integrators
  • ✅ Makes the API intent clearer (requests are only sent, not received)
  • ✅ Maintains full backward compatibility
  • ✅ Keeps response types as Codable (which need both encoding and decoding)

Fixes #71.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Requests should be only Encodable Make requests Encodable-only instead of Codable Jul 2, 2025
@Copilot Copilot AI requested a review from kober32 July 2, 2025 12:18
Copilot finished work on behalf of kober32 July 2, 2025 12:18
Copy link
Member

@kober32 kober32 left a comment

Choose a reason for hiding this comment

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

Note the change into the 1.5.1 version in changelog.md file

Copy link
Contributor Author

Copilot AI commented Jul 2, 2025

Note the change into the 1.5.1 version in changelog.md file

Added changelog.md with the 1.5.1 entry documenting the Encodable-only changes. Commit: 019f29a

@Copilot Copilot AI requested a review from kober32 July 2, 2025 12:55
Copilot finished work on behalf of kober32 July 2, 2025 12:55
@kober32 kober32 marked this pull request as ready for review July 2, 2025 13:06
Copy link
Member

@kober32 kober32 left a comment

Choose a reason for hiding this comment

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

OK

@kober32 kober32 merged commit d1f0242 into develop Jul 2, 2025
3 checks passed
@kober32 kober32 deleted the copilot/fix-71 branch July 2, 2025 13:08
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.

Requests should be only Encodable
2 participants