From 5ea83b07c13d109e8cbbaa25dce047a0dc69f145 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Thu, 24 Jan 2019 19:09:46 -0800 Subject: [PATCH] Hopefully remove some ambiguity. --- Sources/JSONAPIOpenAPI/JSONAPI/JSONAPITypes+OpenAPI.swift | 8 ++++---- Sources/JSONAPIOpenAPI/OpenAPI/OpenAPITypes.swift | 8 +------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Sources/JSONAPIOpenAPI/JSONAPI/JSONAPITypes+OpenAPI.swift b/Sources/JSONAPIOpenAPI/JSONAPI/JSONAPITypes+OpenAPI.swift index e15f3a2..4ac1da3 100644 --- a/Sources/JSONAPIOpenAPI/JSONAPI/JSONAPITypes+OpenAPI.swift +++ b/Sources/JSONAPIOpenAPI/JSONAPI/JSONAPITypes+OpenAPI.swift @@ -141,7 +141,7 @@ extension ToManyRelationship: OpenAPINodeType { } } -extension Entity: OpenAPIEncodedNodeType, OpenAPINodeType where Description.Attributes: Sampleable, Description.Relationships: Sampleable { +extension Entity: OpenAPIEncodedNodeType where Description.Attributes: Sampleable, Description.Relationships: Sampleable { public static func openAPINode(using encoder: JSONEncoder) throws -> JSONNode { // NOTE: const for json `type` not supported by OpenAPI 3.0 // Will use "enum" with one possible value for now. @@ -184,13 +184,13 @@ extension Entity: OpenAPIEncodedNodeType, OpenAPINodeType where Description.Attr } } -extension SingleResourceBody: OpenAPIEncodedNodeType, OpenAPINodeType where Entity: OpenAPIEncodedNodeType { +extension SingleResourceBody: OpenAPIEncodedNodeType where Entity: OpenAPIEncodedNodeType { public static func openAPINode(using encoder: JSONEncoder) throws -> JSONNode { return try Entity.openAPINode(using: encoder) } } -extension ManyResourceBody: OpenAPIEncodedNodeType, OpenAPINodeType where Entity: OpenAPIEncodedNodeType { +extension ManyResourceBody: OpenAPIEncodedNodeType where Entity: OpenAPIEncodedNodeType { public static func openAPINode(using encoder: JSONEncoder) throws -> JSONNode { return .array(.init(format: .generic, required: true), @@ -198,7 +198,7 @@ extension ManyResourceBody: OpenAPIEncodedNodeType, OpenAPINodeType where Entity } } -extension Document: OpenAPIEncodedNodeType, OpenAPINodeType where PrimaryResourceBody: OpenAPIEncodedNodeType, IncludeType: OpenAPINodeType { +extension Document: OpenAPIEncodedNodeType where PrimaryResourceBody: OpenAPIEncodedNodeType, IncludeType: OpenAPINodeType { public static func openAPINode(using encoder: JSONEncoder) throws -> JSONNode { // TODO: metadata, links, api description, errors // TODO: represent data and errors as the two distinct possible outcomes diff --git a/Sources/JSONAPIOpenAPI/OpenAPI/OpenAPITypes.swift b/Sources/JSONAPIOpenAPI/OpenAPI/OpenAPITypes.swift index abf2e6e..580fdb3 100644 --- a/Sources/JSONAPIOpenAPI/OpenAPI/OpenAPITypes.swift +++ b/Sources/JSONAPIOpenAPI/OpenAPI/OpenAPITypes.swift @@ -19,7 +19,7 @@ public protocol OpenAPINodeType { /// Anything conforming to `OpenAPIEncodedNodeType` can provide an /// OpenAPI schema representing itself but it may need an Encoder /// to do its job. -public protocol OpenAPIEncodedNodeType: OpenAPINodeType { +public protocol OpenAPIEncodedNodeType { static func openAPINode(using encoder: JSONEncoder) throws -> JSONNode } @@ -29,12 +29,6 @@ extension OpenAPIEncodedNodeType where Self: Sampleable, Self: Encodable { } } -extension OpenAPIEncodedNodeType { - public static func openAPINode() throws -> JSONNode { - return try openAPINode(using: JSONEncoder()) - } -} - /// Anything conforming to `RawOpenAPINodeType` can provide an /// OpenAPI schema representing itself. This second protocol is /// necessary so that one type can conditionally provide a