2019-01-13 18:28:41 -08:00
|
|
|
//
|
|
|
|
|
// PrimitiveTypes.swift
|
|
|
|
|
// JSONAPIOpenAPI
|
|
|
|
|
//
|
|
|
|
|
// Created by Mathew Polzin on 01/13/19.
|
|
|
|
|
//
|
|
|
|
|
|
2019-01-20 15:39:54 -08:00
|
|
|
import AnyCodable
|
|
|
|
|
|
2019-01-13 18:28:41 -08:00
|
|
|
/**
|
|
|
|
|
|
|
|
|
|
Notable omissions in this library's default offerings:
|
|
|
|
|
|
|
|
|
|
Base 64 encoded characters:
|
|
|
|
|
.string(.byte)
|
|
|
|
|
|
|
|
|
|
Any sequence of octets:
|
|
|
|
|
.string(.binary)
|
|
|
|
|
|
|
|
|
|
RFC3339 full-date:
|
|
|
|
|
.string(.date)
|
|
|
|
|
|
|
|
|
|
RFC3339 date-time:
|
|
|
|
|
.string(.dateTime)
|
|
|
|
|
|
|
|
|
|
A hint to UIs to obscure input:
|
|
|
|
|
.string(.password)
|
|
|
|
|
|
2019-01-14 23:29:49 -08:00
|
|
|
Any object:
|
|
|
|
|
.object(.generic)
|
|
|
|
|
|
2019-01-13 18:28:41 -08:00
|
|
|
**/
|
|
|
|
|
|
2019-01-14 21:17:07 -08:00
|
|
|
extension Optional: OpenAPINodeType where Wrapped: OpenAPINodeType {
|
2019-01-19 15:30:09 -08:00
|
|
|
static public func openAPINode() throws -> JSONNode {
|
|
|
|
|
return try Wrapped.openAPINode().optionalNode()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension Optional: RawOpenAPINodeType where Wrapped: RawRepresentable, Wrapped.RawValue: OpenAPINodeType {
|
2019-01-20 18:18:35 -08:00
|
|
|
static public func rawOpenAPINode() throws -> JSONNode {
|
2019-01-19 15:30:09 -08:00
|
|
|
return try Wrapped.RawValue.openAPINode().optionalNode()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 18:18:35 -08:00
|
|
|
extension Optional: WrappedRawOpenAPIType where Wrapped: RawOpenAPINodeType {
|
|
|
|
|
static public func wrappedOpenAPINode() throws -> JSONNode {
|
|
|
|
|
return try Wrapped.rawOpenAPINode().optionalNode()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension Optional: DoubleWrappedRawOpenAPIType where Wrapped: WrappedRawOpenAPIType {
|
|
|
|
|
static public func wrappedOpenAPINode() throws -> JSONNode {
|
|
|
|
|
return try Wrapped.wrappedOpenAPINode().optionalNode()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 15:39:54 -08:00
|
|
|
extension Optional: AnyJSONCaseIterable where Wrapped: CaseIterable, Wrapped: Codable {
|
|
|
|
|
public static var allCases: [AnyCodable] {
|
|
|
|
|
return (try? allCases(from: Array(Wrapped.allCases))) ?? []
|
2019-01-13 18:28:41 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 21:17:07 -08:00
|
|
|
extension String: OpenAPINodeType {
|
2019-01-19 15:30:09 -08:00
|
|
|
static public func openAPINode() throws -> JSONNode {
|
2019-01-14 21:17:07 -08:00
|
|
|
return .string(.init(format: .generic,
|
|
|
|
|
required: true),
|
|
|
|
|
.init())
|
2019-01-13 18:28:41 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 21:17:07 -08:00
|
|
|
extension Bool: OpenAPINodeType {
|
2019-01-19 15:30:09 -08:00
|
|
|
static public func openAPINode() throws -> JSONNode {
|
2019-01-14 21:17:07 -08:00
|
|
|
return .boolean(.init(format: .generic,
|
|
|
|
|
required: true))
|
2019-01-13 18:28:41 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 21:17:07 -08:00
|
|
|
extension Array: OpenAPINodeType where Element: OpenAPINodeType {
|
2019-01-19 15:30:09 -08:00
|
|
|
static public func openAPINode() throws -> JSONNode {
|
2019-01-14 21:17:07 -08:00
|
|
|
return .array(.init(format: .generic,
|
|
|
|
|
required: true),
|
2019-01-19 15:30:09 -08:00
|
|
|
.init(items: try Element.openAPINode()))
|
2019-01-13 18:28:41 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 21:17:07 -08:00
|
|
|
extension Double: OpenAPINodeType {
|
2019-01-19 15:30:09 -08:00
|
|
|
static public func openAPINode() throws -> JSONNode {
|
2019-01-14 21:17:07 -08:00
|
|
|
return .number(.init(format: .double,
|
|
|
|
|
required: true),
|
|
|
|
|
.init())
|
2019-01-13 18:28:41 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 21:17:07 -08:00
|
|
|
extension Float: OpenAPINodeType {
|
2019-01-19 15:30:09 -08:00
|
|
|
static public func openAPINode() throws -> JSONNode {
|
2019-01-14 21:17:07 -08:00
|
|
|
return .number(.init(format: .float,
|
|
|
|
|
required: true),
|
|
|
|
|
.init())
|
2019-01-13 18:28:41 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 21:17:07 -08:00
|
|
|
extension Int: OpenAPINodeType {
|
2019-01-19 15:30:09 -08:00
|
|
|
static public func openAPINode() throws -> JSONNode {
|
2019-01-14 21:17:07 -08:00
|
|
|
return .integer(.init(format: .generic,
|
|
|
|
|
required: true),
|
|
|
|
|
.init())
|
2019-01-13 18:28:41 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 21:17:07 -08:00
|
|
|
extension Int32: OpenAPINodeType {
|
2019-01-19 15:30:09 -08:00
|
|
|
static public func openAPINode() throws -> JSONNode {
|
2019-01-14 21:17:07 -08:00
|
|
|
return .integer(.init(format: .int32,
|
|
|
|
|
required: true),
|
|
|
|
|
.init())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension Int64: OpenAPINodeType {
|
2019-01-19 15:30:09 -08:00
|
|
|
static public func openAPINode() throws -> JSONNode {
|
2019-01-14 21:17:07 -08:00
|
|
|
return .integer(.init(format: .int64,
|
|
|
|
|
required: true),
|
|
|
|
|
.init())
|
2019-01-13 18:28:41 -08:00
|
|
|
}
|
|
|
|
|
}
|