Add subscript access to Poly types. Add empty test class for Poly type. Remove unneeded Foundation import. Small README change to read more clearly.

This commit is contained in:
Mathew Polzin
2018-11-23 08:49:55 -08:00
parent 98bb64268f
commit 2563edf419
5 changed files with 62 additions and 2 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
# JSONAPI
[![MIT license](http://img.shields.io/badge/license-MIT-lightgrey.svg)](http://opensource.org/licenses/MIT) [![Swift 4.2](http://img.shields.io/badge/Swift-4.2-blue.svg)](https://swift.org) [![Build Status](https://app.bitrise.io/app/c8295b9589aa401e/status.svg?token=vzcyqWD5bQ4xqQfZsaVzNw&branch=master)](https://app.bitrise.io/app/c8295b9589aa401e)
A Swift package for encoding and decoding to *JSON API* compliant requests and responses.
A Swift package for encoding to- and decoding from *JSON API* compliant requests and responses.
See the JSON API Spec here: https://jsonapi.org/format/
+42
View File
@@ -55,6 +55,13 @@ public protocol _Poly1: _Poly0 {
init(_ a: A)
}
public extension _Poly1 {
subscript(_ lookup: A.Type) -> A? {
return a
}
}
public enum Poly1<A: EntityType>: _Poly1 {
case a(A)
@@ -101,6 +108,13 @@ public protocol _Poly2: _Poly1 {
init(_ b: B)
}
public extension _Poly2 {
subscript(_ lookup: B.Type) -> B? {
return b
}
}
public enum Poly2<A: EntityType, B: EntityType>: _Poly2 {
case a(A)
case b(B)
@@ -173,6 +187,13 @@ public protocol _Poly3: _Poly2 {
init(_ c: C)
}
public extension _Poly3 {
subscript(_ lookup: C.Type) -> C? {
return c
}
}
public enum Poly3<A: EntityType, B: EntityType, C: EntityType>: _Poly3 {
case a(A)
case b(B)
@@ -260,6 +281,13 @@ public protocol _Poly4: _Poly3 {
init(_ d: D)
}
public extension _Poly4 {
subscript(_ lookup: D.Type) -> D? {
return d
}
}
public enum Poly4<A: EntityType, B: EntityType, C: EntityType, D: EntityType>: _Poly4 {
case a(A)
case b(B)
@@ -362,6 +390,13 @@ public protocol _Poly5: _Poly4 {
init(_ e: E)
}
public extension _Poly5 {
subscript(_ lookup: E.Type) -> E? {
return e
}
}
public enum Poly5<A: EntityType, B: EntityType, C: EntityType, D: EntityType, E: EntityType>: _Poly5 {
case a(A)
case b(B)
@@ -479,6 +514,13 @@ public protocol _Poly6: _Poly5 {
init(_ f: F)
}
public extension _Poly6 {
subscript(_ lookup: F.Type) -> F? {
return f
}
}
public enum Poly6<A: EntityType, B: EntityType, C: EntityType, D: EntityType, E: EntityType, F: EntityType>: _Poly6 {
case a(A)
case b(B)
+13
View File
@@ -0,0 +1,13 @@
//
// PolyTests.swift
// JSONAPITests
//
// Created by Mathew Polzin on 11/23/18.
//
import XCTest
import JSONAPI
class PolyTests: XCTestCase {
}
@@ -0,0 +1,6 @@
//
// PolyStubs.swift
// JSONAPITests
//
// Created by Mathew Polzin on 11/23/18.
//
@@ -5,7 +5,6 @@
// Created by Mathew Polzin on 11/15/18.
//
import Foundation
import JSONAPI
public typealias Entity<Description: JSONAPI.EntityDescription> = JSONAPI.Entity<Description, Id<String, Description>>