From 875d938b95ae92382e0957698bce5dab438da1d7 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 20 Jan 2019 16:19:26 -0800 Subject: [PATCH] Add id and type properties to Entity OpenAPI Schema --- Sources/JSONAPIOpenAPI/JSONAPIOpenAPITypes.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/JSONAPIOpenAPI/JSONAPIOpenAPITypes.swift b/Sources/JSONAPIOpenAPI/JSONAPIOpenAPITypes.swift index 01702b6..636184a 100644 --- a/Sources/JSONAPIOpenAPI/JSONAPIOpenAPITypes.swift +++ b/Sources/JSONAPIOpenAPI/JSONAPIOpenAPITypes.swift @@ -104,7 +104,18 @@ extension ToManyRelationship: OpenAPINodeType { extension Entity: OpenAPINodeType where Description.Attributes: Sampleable, Description.Relationships: Sampleable { public static func openAPINode() throws -> JSONNode { - // TODO: Id, type, metadata, links + // TODO: metadata, links + + let idNode = JSONNode.string(.init(format: .generic, + required: true), + .init()) + let idProperty = ("id", idNode) + + let typeNode = JSONNode.string(.init(format: .generic, + required: true), + .init()) + let typeProperty = ("type", typeNode) + let attributesNode: JSONNode? = Description.Attributes.self == NoAttributes.self ? nil : try Description.Attributes.genericObjectOpenAPINode() @@ -118,6 +129,8 @@ extension Entity: OpenAPINodeType where Description.Attributes: Sampleable, Desc let relationshipsProperty = relationshipsNode.map { ("relationships", $0) } let propertiesDict = Dictionary([ + idProperty, + typeProperty, attributesProperty, relationshipsProperty ].compactMap { $0 }) { _, value in value }