Add id and type properties to Entity OpenAPI Schema

This commit is contained in:
Mathew Polzin
2019-01-20 16:19:26 -08:00
parent 1ed34b00dc
commit 875d938b95
@@ -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 }