mattpolzin / JSONAPI

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

Links example? #88

Closed axmo closed 3 years ago

axmo commented 3 years ago

The API I am connecting to includes Links on some resources, but adding

struct Links: JSONAPI.Links {
    public let user: Link<URL, NoMetadata>
}

within a ResourceObjectDescription

Results in errors:

Type 'FooDescription.Links' does not conform to protocol 'Decodable'
Type 'FooDescription.Links' does not conform to protocol 'Encodable'
Type 'FooDescription.Links' does not conform to protocol 'Equatable'

and

Type 'URL' does not conform to protocol 'JSONAPIURL'

The Colab examples and Server/Client example all have NoLinks, and the documentation on Links is pretty short. I have tried Link<JSONAPIURL, NoMetadata> and Link<String, NoMetadata> but those result in errors as well.

Any help you can provide would be appreciated!

Using version 5.0

mattpolzin commented 3 years ago

Sorry for the confusion! You were really close to getting this to work. I have added a better example to the documentation in response to this question, but I'll also briefly note here that either of the following would probably solve your problem:

  1. Use Link<String, NoMetadata> and add extension String: JSONAPIURL {}
  2. Use Link<URL, NoMetadata> and add extension URL: JSONAPIURL {}

It is generally bad practice to extend types you didn't implement with protocols you didn't create, but in this case it is exactly how I intend apps to specify that a type that is not necessarily a URL should be used to decode the URL in a particular link.

mattpolzin commented 3 years ago

It looks like this issue can be closed. Feel free to reopen it if I have not fully answered the question you were asking.