mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
Add todos for Entity Id and type. Add example usage of OpenAPI entity schema support in Playground
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
//: [Previous](@previous)
|
||||
|
||||
import Foundation
|
||||
import JSONAPI
|
||||
import JSONAPIOpenAPI
|
||||
|
||||
// print Entity Schema
|
||||
let encoder = JSONEncoder()
|
||||
encoder.outputFormatting = .prettyPrinted
|
||||
|
||||
let personSchemaData = try? encoder.encode(Person.openAPINode())
|
||||
|
||||
print(personSchemaData.map { String(data: $0, encoding: .utf8)! } ?? "Schema Construction Failed")
|
||||
@@ -0,0 +1,16 @@
|
||||
import Foundation
|
||||
import JSONAPI
|
||||
import JSONAPITesting // for the convenience of literal initialization
|
||||
import JSONAPIOpenAPI
|
||||
|
||||
extension PersonDescription.Attributes: Sampleable {
|
||||
public static var sample: PersonDescription.Attributes {
|
||||
return .init(name: ["Abbie", "Eibba"], favoriteColor: "Blue")
|
||||
}
|
||||
}
|
||||
|
||||
extension PersonDescription.Relationships: Sampleable {
|
||||
public static var sample: PersonDescription.Relationships {
|
||||
return .init(friends: ["1", "2"], dogs: ["2"], home: "1")
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,8 @@
|
||||
<pages>
|
||||
<page name='Test Library'/>
|
||||
<page name='Usage'/>
|
||||
<page name='Full Client & Server Example'/>
|
||||
<page name='Full Document Verbose Generation'/>
|
||||
<page name='OpenAPI Documentation'/>
|
||||
</pages>
|
||||
</playground>
|
||||
@@ -104,6 +104,7 @@ extension ToManyRelationship: OpenAPINodeType {
|
||||
|
||||
extension Entity: OpenAPINodeType where Description.Attributes: Sampleable, Description.Relationships: Sampleable {
|
||||
public static func openAPINode() throws -> JSONNode {
|
||||
// TODO: Id, type, metadata, links
|
||||
let attributesNode: JSONNode? = Description.Attributes.self == NoAttributes.self
|
||||
? nil
|
||||
: try Description.Attributes.genericObjectOpenAPINode()
|
||||
|
||||
@@ -49,32 +49,7 @@ extension Sampleable {
|
||||
let newNode: JSONNode?
|
||||
if let allCases = maybeAllCases,
|
||||
let openAPINode = maybeOpenAPINode {
|
||||
newNode = try openAPINode.with(allowedValues: allCases) // try {
|
||||
// if let cases = allCases as? [JSONTypeFormat.BooleanFormat.SwiftType] {
|
||||
// return try openAPINode.with(allowedValues: cases)
|
||||
//
|
||||
// } else if let cases = allCases as? [JSONTypeFormat.ArrayFormat.SwiftType] {
|
||||
// return try openAPINode.with(allowedValues: cases)
|
||||
//
|
||||
// } else if let cases = allCases as? [JSONTypeFormat.ObjectFormat.SwiftType] {
|
||||
// return try openAPINode.with(allowedValues: cases)
|
||||
//
|
||||
// } else if let cases = allCases as? [JSONTypeFormat.NumberFormat.SwiftType] {
|
||||
// return try openAPINode.with(allowedValues: cases)
|
||||
//
|
||||
// } else if let cases = allCases as? [JSONTypeFormat.IntegerFormat.SwiftType] {
|
||||
// return try openAPINode.with(allowedValues: cases)
|
||||
//
|
||||
// } else if let cases = allCases as? [JSONTypeFormat.StringFormat.SwiftType] {
|
||||
// return try openAPINode.with(allowedValues: cases)
|
||||
//
|
||||
// } else if allCases.compactMap({ $0 as? RawStringRepresentable }).count == allCases.count {
|
||||
// return try openAPINode.with(allowedValues: allCases.compactMap { ($0 as? RawStringRepresentable)?.rawValue })
|
||||
//
|
||||
// } else {
|
||||
// throw SampleableError.allowedValuesNotOfExpectedType(forNode: openAPINode, allowedValues: allCases)
|
||||
// }
|
||||
// }()
|
||||
newNode = try openAPINode.with(allowedValues: allCases)
|
||||
} else {
|
||||
newNode = maybeOpenAPINode
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user