From 25bda795a7205af6c79102d2a8af6377fd83e042 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Sun, 13 Jan 2019 18:28:41 -0800 Subject: [PATCH] Rename JSONAPITestLib to JSONAPITesting to fit with naming convention I am adopting going forward. Added OpenAPI JSON schema types. Added default schema types for a handful of Swift primitives. --- Package.resolved | 2 +- Package.swift | 6 +- Sources/JSONAPIOpenAPI/OpenAPI.swift | 8 ++ Sources/JSONAPIOpenAPI/OpenAPITypes.swift | 82 +++++++++++++++++++ .../JSONAPIOpenAPI/SwiftPrimitiveTypes.swift | 78 ++++++++++++++++++ .../Attribute+Literal.swift | 0 .../EntityCheck.swift | 0 .../Id+Literal.swift | 0 .../Optional+Literal.swift | 0 .../Relationship+Literal.swift | 0 .../Attribute+LiteralTests.swift | 0 .../EntityCheckTests.swift | 0 .../Id+LiteralTests.swift | 0 .../Relationship+LiteralTests.swift | 0 .../Test Helpers/EntityTestTypes.swift | 0 .../String+CreatableRawIdType.swift | 0 .../XCTestManifests.swift | 0 17 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 Sources/JSONAPIOpenAPI/OpenAPI.swift create mode 100644 Sources/JSONAPIOpenAPI/OpenAPITypes.swift create mode 100644 Sources/JSONAPIOpenAPI/SwiftPrimitiveTypes.swift rename Sources/{JSONAPITestLib => JSONAPITesting}/Attribute+Literal.swift (100%) rename Sources/{JSONAPITestLib => JSONAPITesting}/EntityCheck.swift (100%) rename Sources/{JSONAPITestLib => JSONAPITesting}/Id+Literal.swift (100%) rename Sources/{JSONAPITestLib => JSONAPITesting}/Optional+Literal.swift (100%) rename Sources/{JSONAPITestLib => JSONAPITesting}/Relationship+Literal.swift (100%) rename Tests/{JSONAPITestLibTests => JSONAPITestingTests}/Attribute+LiteralTests.swift (100%) rename Tests/{JSONAPITestLibTests => JSONAPITestingTests}/EntityCheckTests.swift (100%) rename Tests/{JSONAPITestLibTests => JSONAPITestingTests}/Id+LiteralTests.swift (100%) rename Tests/{JSONAPITestLibTests => JSONAPITestingTests}/Relationship+LiteralTests.swift (100%) rename Tests/{JSONAPITestLibTests => JSONAPITestingTests}/Test Helpers/EntityTestTypes.swift (100%) rename Tests/{JSONAPITestLibTests => JSONAPITestingTests}/Test Helpers/String+CreatableRawIdType.swift (100%) rename Tests/{JSONAPITestLibTests => JSONAPITestingTests}/XCTestManifests.swift (100%) diff --git a/Package.resolved b/Package.resolved index e498677..85b6784 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,7 +6,7 @@ "repositoryURL": "https://github.com/mattpolzin/Poly.git", "state": { "branch": "master", - "revision": "e03e896e23315525702334cfb552bb947d085ae5", + "revision": "77f45b8963a51c02d71fc4075eba5cff47ff0d07", "version": null } } diff --git a/Package.swift b/Package.swift index c8a1145..3278ecf 100644 --- a/Package.swift +++ b/Package.swift @@ -11,7 +11,7 @@ let package = Package( targets: ["JSONAPI"]), .library( name: "JSONAPITesting", - targets: ["JSONAPITestLib"]), + targets: ["JSONAPITesting"]), .library( name: "JSONAPIOpenAPI", targets: ["JSONAPIOpenAPI"]) @@ -24,7 +24,7 @@ let package = Package( name: "JSONAPI", dependencies: ["Poly"]), .target( - name: "JSONAPITestLib", + name: "JSONAPITesting", dependencies: ["JSONAPI"]), .target( name: "JSONAPIOpenAPI", @@ -33,7 +33,7 @@ let package = Package( name: "JSONAPITests", dependencies: ["JSONAPI", "JSONAPITesting"]), .testTarget( - name: "JSONAPITestLibTests", + name: "JSONAPITestingTests", dependencies: ["JSONAPI", "JSONAPITesting"]), .testTarget( name: "JSONAPIOpenAPITests", diff --git a/Sources/JSONAPIOpenAPI/OpenAPI.swift b/Sources/JSONAPIOpenAPI/OpenAPI.swift new file mode 100644 index 0000000..7e89f04 --- /dev/null +++ b/Sources/JSONAPIOpenAPI/OpenAPI.swift @@ -0,0 +1,8 @@ +// +// OpenAPI.swift +// JSONAPI +// +// Created by Mathew Polzin on 1/13/19. +// + +public enum OpenAPI {} diff --git a/Sources/JSONAPIOpenAPI/OpenAPITypes.swift b/Sources/JSONAPIOpenAPI/OpenAPITypes.swift new file mode 100644 index 0000000..efd8aea --- /dev/null +++ b/Sources/JSONAPIOpenAPI/OpenAPITypes.swift @@ -0,0 +1,82 @@ +// +// OpenAPITypes.swift +// JSONAPI +// +// Created by Mathew Polzin on 1/13/19. +// + +public protocol OpenAPITyped { + var openAPIType: OpenAPI.JSONTypeFormat { get } +} + +public extension OpenAPI { + enum JSONType: String { + case boolean = "boolean" + case object = "object" + case array = "array" + case number = "number" + case integer = "integer" + case string = "string" + } + + enum JSONTypeFormat: Equatable { + case boolean(BooleanFormat) + case object(ObjectFormat) + case array(ArrayFormat) + case number(NumberFormat) + case integer(IntegerFormat) + case string(StringFormat) + } +} + +public extension OpenAPI.JSONTypeFormat { + public enum BooleanFormat: String, Equatable, Codable { + case generic = "" + } + + public enum ObjectFormat: String, Equatable, Codable { + case generic = "" + } + + public enum ArrayFormat: String, Equatable, Codable { + case generic = "" + } + + public enum NumberFormat: String, Equatable, Codable { + case generic = "" + case float = "float" + case double = "double" + } + + public enum IntegerFormat: String, Equatable, Codable { + case generic = "" + case int32 = "int32" + case int64 = "int64" + } + + public enum StringFormat: String, Equatable, Codable { + case generic = "" + case byte = "byte" + case binary = "binary" + case date = "date" + case dateTime = "date-time" + case password = "password" + } + + public var type: OpenAPI.JSONType { + switch self { + case .boolean: + return .boolean + case .object: + return .object + case .array: + return .array + case .number: + return .number + case .integer: + return .integer + case .string: + return .string + } + } +} diff --git a/Sources/JSONAPIOpenAPI/SwiftPrimitiveTypes.swift b/Sources/JSONAPIOpenAPI/SwiftPrimitiveTypes.swift new file mode 100644 index 0000000..2da0222 --- /dev/null +++ b/Sources/JSONAPIOpenAPI/SwiftPrimitiveTypes.swift @@ -0,0 +1,78 @@ +// +// PrimitiveTypes.swift +// JSONAPIOpenAPI +// +// Created by Mathew Polzin on 01/13/19. +// + +/** + +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) + +An object: +.object(.generic) + +**/ + +extension String: OpenAPITyped { + public var openAPIType: OpenAPI.JSONTypeFormat { + return .string(.generic) + } +} + +extension Bool: OpenAPITyped { + public var openAPIType: OpenAPI.JSONTypeFormat { + return .boolean(.generic) + } +} + +extension Array: OpenAPITyped { + public var openAPIType: OpenAPI.JSONTypeFormat { + return .array(.generic) + } +} + +extension Double: OpenAPITyped { + public var openAPIType: OpenAPI.JSONTypeFormat { + return .number(.double) + } +} + +extension Float: OpenAPITyped { + public var openAPIType: OpenAPI.JSONTypeFormat { + return .number(.float) + } +} + +extension Int: OpenAPITyped { + public var openAPIType: OpenAPI.JSONTypeFormat { + return .integer(.generic) + } +} + +extension Int32: OpenAPITyped { + public var openAPIType: OpenAPI.JSONTypeFormat { + return .integer(.int32) + } +} + +extension Int64: OpenAPITyped { + public var openAPIType: OpenAPI.JSONTypeFormat { + return .integer(.int64) + } +} diff --git a/Sources/JSONAPITestLib/Attribute+Literal.swift b/Sources/JSONAPITesting/Attribute+Literal.swift similarity index 100% rename from Sources/JSONAPITestLib/Attribute+Literal.swift rename to Sources/JSONAPITesting/Attribute+Literal.swift diff --git a/Sources/JSONAPITestLib/EntityCheck.swift b/Sources/JSONAPITesting/EntityCheck.swift similarity index 100% rename from Sources/JSONAPITestLib/EntityCheck.swift rename to Sources/JSONAPITesting/EntityCheck.swift diff --git a/Sources/JSONAPITestLib/Id+Literal.swift b/Sources/JSONAPITesting/Id+Literal.swift similarity index 100% rename from Sources/JSONAPITestLib/Id+Literal.swift rename to Sources/JSONAPITesting/Id+Literal.swift diff --git a/Sources/JSONAPITestLib/Optional+Literal.swift b/Sources/JSONAPITesting/Optional+Literal.swift similarity index 100% rename from Sources/JSONAPITestLib/Optional+Literal.swift rename to Sources/JSONAPITesting/Optional+Literal.swift diff --git a/Sources/JSONAPITestLib/Relationship+Literal.swift b/Sources/JSONAPITesting/Relationship+Literal.swift similarity index 100% rename from Sources/JSONAPITestLib/Relationship+Literal.swift rename to Sources/JSONAPITesting/Relationship+Literal.swift diff --git a/Tests/JSONAPITestLibTests/Attribute+LiteralTests.swift b/Tests/JSONAPITestingTests/Attribute+LiteralTests.swift similarity index 100% rename from Tests/JSONAPITestLibTests/Attribute+LiteralTests.swift rename to Tests/JSONAPITestingTests/Attribute+LiteralTests.swift diff --git a/Tests/JSONAPITestLibTests/EntityCheckTests.swift b/Tests/JSONAPITestingTests/EntityCheckTests.swift similarity index 100% rename from Tests/JSONAPITestLibTests/EntityCheckTests.swift rename to Tests/JSONAPITestingTests/EntityCheckTests.swift diff --git a/Tests/JSONAPITestLibTests/Id+LiteralTests.swift b/Tests/JSONAPITestingTests/Id+LiteralTests.swift similarity index 100% rename from Tests/JSONAPITestLibTests/Id+LiteralTests.swift rename to Tests/JSONAPITestingTests/Id+LiteralTests.swift diff --git a/Tests/JSONAPITestLibTests/Relationship+LiteralTests.swift b/Tests/JSONAPITestingTests/Relationship+LiteralTests.swift similarity index 100% rename from Tests/JSONAPITestLibTests/Relationship+LiteralTests.swift rename to Tests/JSONAPITestingTests/Relationship+LiteralTests.swift diff --git a/Tests/JSONAPITestLibTests/Test Helpers/EntityTestTypes.swift b/Tests/JSONAPITestingTests/Test Helpers/EntityTestTypes.swift similarity index 100% rename from Tests/JSONAPITestLibTests/Test Helpers/EntityTestTypes.swift rename to Tests/JSONAPITestingTests/Test Helpers/EntityTestTypes.swift diff --git a/Tests/JSONAPITestLibTests/Test Helpers/String+CreatableRawIdType.swift b/Tests/JSONAPITestingTests/Test Helpers/String+CreatableRawIdType.swift similarity index 100% rename from Tests/JSONAPITestLibTests/Test Helpers/String+CreatableRawIdType.swift rename to Tests/JSONAPITestingTests/Test Helpers/String+CreatableRawIdType.swift diff --git a/Tests/JSONAPITestLibTests/XCTestManifests.swift b/Tests/JSONAPITestingTests/XCTestManifests.swift similarity index 100% rename from Tests/JSONAPITestLibTests/XCTestManifests.swift rename to Tests/JSONAPITestingTests/XCTestManifests.swift