michiel / jsonapi-rust

Rust library for serialization, deserialization and working with JSON-API data
MIT License
109 stars 30 forks source link

WIP: Add partial resources #77

Closed johnchildren closed 3 years ago

johnchildren commented 3 years ago

Adds a notion of partial resources which are an extension of the PrimaryData internal type. This allows for separate definitions of models that do not have id fields and are not expected to have included data.

This is useful in cases where a server should generate the IDs for resources: https://jsonapi.org/format/1.0/#crud-creating-client-ids

There may be a few edge cases where a user wants support included resources without an id in the primary data, or wants to only submit relationships with an ID, but this can be resolved separately.

TODO:


Hi,

Have been thinking about how to resolve #74 and therefore implemented the suggestion of PartialResources to what I would understand them to be. I have added a test, but this change requires an extra macro for implementing a new PartialJsonApiModel trait, with the idea that users would invoke this macro for a separate struct, though I am unsure on the ergonomics of this.

If there is any feedback on these changes I would appreciate it, otherwise I will try to fixup this PR over the course of the next few weeks with docs and tests.

johnchildren commented 3 years ago

I don't think I'm going to get a chance to finish this unfortunately, and I'm not convinced it is even the best approach.