replicate / replicate-go

Go client for Replicate
https://replicate.com
Apache License 2.0
65 stars 9 forks source link

Replace custom `MarshalJSON` implementations with `RawJSON` instance method #59

Closed mattt closed 6 months ago

mattt commented 6 months ago

19 updated resources to store raw JSON content when unmarshaling from API responses. This allowed applications like the CLI, for example, to show any new fields that were added to the API but not yet reflected in the Go client library.

However, this can create some unexpected results if you attempt to re-encode a resource after making any changes. The current implementation of MarshalJSON would have any rawJSON value returned, if present, with no mechanism for invalidating or resetting state of any of the fields were modified.

This PR removes those MarshalJSON functions in favor of using the built-in marshaling based on the structures. To access the original JSON from the API response, you can now use the RawJSON method.