From b47c2b7ca2a463c8359d518922483cd30b4a03c3 Mon Sep 17 00:00:00 2001 From: Eugene <> Date: Thu, 30 Sep 2021 12:11:42 +0300 Subject: [PATCH] Type-erased protocol added. --- Sources/Endpoints/Endpoint.swift | 10 ++++++++++ Tests/EndpointsTests/EndpointsTests.swift | 4 +--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Sources/Endpoints/Endpoint.swift b/Sources/Endpoints/Endpoint.swift index fbb4a6c..b015921 100644 --- a/Sources/Endpoints/Endpoint.swift +++ b/Sources/Endpoints/Endpoint.swift @@ -52,3 +52,13 @@ public struct EmptyBody: HTTPPayload { extension String: HTTPPayload { public var kind: HTTP.ContentType { .plainText } } + +// MARK: - AnyEndpoint + +/// Type-erased Endpoint. +protocol AnyEndpoint: Endpoint { } + +extension AnyEndpoint { + + var body: EmptyBody? { nil } +} diff --git a/Tests/EndpointsTests/EndpointsTests.swift b/Tests/EndpointsTests/EndpointsTests.swift index 530360d..5920257 100644 --- a/Tests/EndpointsTests/EndpointsTests.swift +++ b/Tests/EndpointsTests/EndpointsTests.swift @@ -1,7 +1,7 @@ import XCTest @testable import Endpoints -struct GetAPI: Endpoint { +struct GetAPI: AnyEndpoint { var method: HTTP.Method { .get } @@ -13,8 +13,6 @@ struct GetAPI: Endpoint { @HTTP.Parameter(name: "item-id", help: "item id") var itemId: String - - var body: EmptyBody? }