mattpolzin / JSONAPI

Swift Codable JSON:API framework
MIT License
75 stars 19 forks source link

Optional Metadata #115

Closed reshadf closed 5 months ago

reshadf commented 5 months ago

I have an issue that I am not able to resolve. I have the following Resource

typealias BookResource = ResourceObject<BookDescription, BalanceMetadata?, NoLinks>

When I use the resource as main resource and have the balance metadata included in the json it works.

However, In a different call I also use this resource (as an include) where the metadata doesn't exist. I would assume it gets ignored when decoding if it's not there. However, it still tries to decode it.

ResourceObject<BookDescription, Optional<BalanceMetadata>, NoLinks, String> could not be decoded because:
The 'meta' key was not found.
  ▿ includes : 1 element
    ▿ error : Out of the 5 includes in the document, the 5th one failed to parse: Poly failed to decode any of its types at: "included/4"

Is this a bug or is it intended to work like this?

mattpolzin commented 5 months ago

This looks to just be a use-case I never came across so I didn't realize it wouldn't work. I think the sensible behavior is the behavior you expected, so I'll fix this as a bug.

reshadf commented 5 months ago

Thank you so much!

mattpolzin commented 5 months ago

Fixed in the 5.3.1 release.