@@ -72,6 +72,16 @@ class IncludedTests: XCTestCase {
7272 data: three_different_type_includes)
7373 }
7474
75+ func test_OneKnownAndTwoGenericIncludes( ) {
76+ let includes = decoded ( type: Includes < Include2 < TestEntity , TestEntityOther > > . self,
77+ data: three_different_type_includes)
78+
79+ XCTAssertEqual ( includes [ TestEntity . self] . count, 1 )
80+ XCTAssertEqual ( includes [ TestEntityOther . self] . count, 2 )
81+ XCTAssert ( includes [ TestEntityOther . self] . contains { $0. type == " test_entity2 " } )
82+ XCTAssert ( includes [ TestEntityOther . self] . contains { $0. type == " test_entity4 " } )
83+ }
84+
7585 func test_FourDifferentIncludes( ) {
7686 let includes = decoded ( type: Includes < Include4 < TestEntity , TestEntity2 , TestEntity4 , TestEntity6 > > . self,
7787 data: four_different_type_includes)
@@ -678,4 +688,50 @@ extension IncludedTests {
678688 }
679689
680690 typealias TestEntity15 = BasicEntity < TestEntityType15 >
691+
692+ enum TestEntityTypeOther : ResourceObjectProxyDescription {
693+ public static var jsonType : String { return " _generic " }
694+
695+ typealias Attributes = NoAttributes
696+ typealias Relationships = NoRelationships
697+ }
698+
699+ struct TestEntityOther : ResourceObjectProxy , Codable {
700+ typealias Description = TestEntityTypeOther
701+ typealias EntityRawIdType = String
702+
703+ public let type : String
704+ public let id : JSONAPI . Id < String , Self >
705+
706+ public let attributes = NoAttributes ( )
707+ public let relationships = NoRelationships ( )
708+
709+ enum CodingKeys : CodingKey {
710+ case id
711+ case type
712+ }
713+
714+ init ( from decoder: Decoder ) throws {
715+ let container = try decoder. container ( keyedBy: CodingKeys . self)
716+
717+ let type : String
718+ do {
719+ type = try container. decode ( String . self, forKey: . type)
720+ } catch let error as DecodingError {
721+ throw ResourceObjectDecodingError ( error, jsonAPIType: Self . jsonType)
722+ ?? error
723+ }
724+
725+ id = . init( rawValue: try container. decode ( String . self, forKey: . id) )
726+ self . type = type
727+ }
728+
729+ func encode( to encoder: Encoder ) throws {
730+ var container = encoder. container ( keyedBy: CodingKeys . self)
731+
732+ try container. encode ( type, forKey: . type)
733+
734+ try container. encode ( id, forKey: . id)
735+ }
736+ }
681737}
0 commit comments