From fe9f0c93efbf2db300bada52a7b097d779ca5eba Mon Sep 17 00:00:00 2001 From: Ismail Mustafa Date: Sat, 15 Aug 2020 12:27:00 -0400 Subject: [PATCH 01/16] Add carthage support --- .../JSONSchemaTests_Info.plist | 25 + JSONSchema.xcodeproj/JSONSchema_Info.plist | 25 + JSONSchema.xcodeproj/PathKit_Info.plist | 25 + JSONSchema.xcodeproj/project.pbxproj | 876 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/WorkspaceSettings.xcsettings | 8 + .../xcschemes/JSONSchema-Package.xcscheme | 33 + 7 files changed, 999 insertions(+) create mode 100644 JSONSchema.xcodeproj/JSONSchemaTests_Info.plist create mode 100644 JSONSchema.xcodeproj/JSONSchema_Info.plist create mode 100644 JSONSchema.xcodeproj/PathKit_Info.plist create mode 100644 JSONSchema.xcodeproj/project.pbxproj create mode 100644 JSONSchema.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings create mode 100644 JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme diff --git a/JSONSchema.xcodeproj/JSONSchemaTests_Info.plist b/JSONSchema.xcodeproj/JSONSchemaTests_Info.plist new file mode 100644 index 0000000..7c23420 --- /dev/null +++ b/JSONSchema.xcodeproj/JSONSchemaTests_Info.plist @@ -0,0 +1,25 @@ + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/JSONSchema.xcodeproj/JSONSchema_Info.plist b/JSONSchema.xcodeproj/JSONSchema_Info.plist new file mode 100644 index 0000000..57ada9f --- /dev/null +++ b/JSONSchema.xcodeproj/JSONSchema_Info.plist @@ -0,0 +1,25 @@ + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/JSONSchema.xcodeproj/PathKit_Info.plist b/JSONSchema.xcodeproj/PathKit_Info.plist new file mode 100644 index 0000000..57ada9f --- /dev/null +++ b/JSONSchema.xcodeproj/PathKit_Info.plist @@ -0,0 +1,25 @@ + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/JSONSchema.xcodeproj/project.pbxproj b/JSONSchema.xcodeproj/project.pbxproj new file mode 100644 index 0000000..57196cb --- /dev/null +++ b/JSONSchema.xcodeproj/project.pbxproj @@ -0,0 +1,876 @@ +// !$*UTF8*$! +{ + archiveVersion = "1"; + objectVersion = "46"; + objects = { + "JSONSchema::JSONSchema" = { + isa = "PBXNativeTarget"; + buildConfigurationList = "OBJ_33"; + buildPhases = ( + "OBJ_36", + "OBJ_45" + ); + dependencies = ( + ); + name = "JSONSchema"; + productName = "JSONSchema"; + productReference = "JSONSchema::JSONSchema::Product"; + productType = "com.apple.product-type.framework"; + }; + "JSONSchema::JSONSchema::Product" = { + isa = "PBXFileReference"; + path = "JSONSchema.framework"; + sourceTree = "BUILT_PRODUCTS_DIR"; + }; + "JSONSchema::JSONSchemaPackageTests::ProductTarget" = { + isa = "PBXAggregateTarget"; + buildConfigurationList = "OBJ_53"; + buildPhases = ( + ); + dependencies = ( + "OBJ_56" + ); + name = "JSONSchemaPackageTests"; + productName = "JSONSchemaPackageTests"; + }; + "JSONSchema::JSONSchemaTests" = { + isa = "PBXNativeTarget"; + buildConfigurationList = "OBJ_58"; + buildPhases = ( + "OBJ_61", + "OBJ_64" + ); + dependencies = ( + "OBJ_67", + "OBJ_69" + ); + name = "JSONSchemaTests"; + productName = "JSONSchemaTests"; + productReference = "JSONSchema::JSONSchemaTests::Product"; + productType = "com.apple.product-type.bundle.unit-test"; + }; + "JSONSchema::JSONSchemaTests::Product" = { + isa = "PBXFileReference"; + path = "JSONSchemaTests.xctest"; + sourceTree = "BUILT_PRODUCTS_DIR"; + }; + "JSONSchema::SwiftPMPackageDescription" = { + isa = "PBXNativeTarget"; + buildConfigurationList = "OBJ_47"; + buildPhases = ( + "OBJ_50" + ); + dependencies = ( + ); + name = "JSONSchemaPackageDescription"; + productName = "JSONSchemaPackageDescription"; + productType = "com.apple.product-type.framework"; + }; + "OBJ_1" = { + isa = "PBXProject"; + attributes = { + LastSwiftMigration = "9999"; + LastUpgradeCheck = "9999"; + }; + buildConfigurationList = "OBJ_2"; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = "en"; + hasScannedForEncodings = "0"; + knownRegions = ( + "en" + ); + mainGroup = "OBJ_5"; + productRefGroup = "OBJ_24"; + projectDirPath = "."; + targets = ( + "JSONSchema::JSONSchema", + "JSONSchema::SwiftPMPackageDescription", + "JSONSchema::JSONSchemaPackageTests::ProductTarget", + "JSONSchema::JSONSchemaTests", + "PathKit::PathKit", + "PathKit::SwiftPMPackageDescription" + ); + }; + "OBJ_10" = { + isa = "PBXFileReference"; + path = "Draft6Validator.swift"; + sourceTree = ""; + }; + "OBJ_11" = { + isa = "PBXFileReference"; + path = "Draft7Validator.swift"; + sourceTree = ""; + }; + "OBJ_12" = { + isa = "PBXFileReference"; + path = "JSONSchema.swift"; + sourceTree = ""; + }; + "OBJ_13" = { + isa = "PBXFileReference"; + path = "RefResolver.swift"; + sourceTree = ""; + }; + "OBJ_14" = { + isa = "PBXFileReference"; + path = "Validator.swift"; + sourceTree = ""; + }; + "OBJ_15" = { + isa = "PBXFileReference"; + path = "Validators.swift"; + sourceTree = ""; + }; + "OBJ_16" = { + isa = "PBXGroup"; + children = ( + "OBJ_17" + ); + name = "Tests"; + path = ""; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_17" = { + isa = "PBXGroup"; + children = ( + "OBJ_18", + "OBJ_19" + ); + name = "JSONSchemaTests"; + path = "Tests/JSONSchemaTests"; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_18" = { + isa = "PBXFileReference"; + path = "JSONSchemaCases.swift"; + sourceTree = ""; + }; + "OBJ_19" = { + isa = "PBXFileReference"; + path = "JSONSchemaTests.swift"; + sourceTree = ""; + }; + "OBJ_2" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_3", + "OBJ_4" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_20" = { + isa = "PBXGroup"; + children = ( + "OBJ_21" + ); + name = "Dependencies"; + path = ""; + sourceTree = ""; + }; + "OBJ_21" = { + isa = "PBXGroup"; + children = ( + "OBJ_22", + "OBJ_23" + ); + name = "PathKit 1.0.0"; + path = ".build/checkouts/PathKit/Sources"; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_22" = { + isa = "PBXFileReference"; + explicitFileType = "sourcecode.swift"; + name = "Package.swift"; + path = "/Users/ismailmustafa/Desktop/projects/JSONSchema.swift/.build/checkouts/PathKit/Package.swift"; + sourceTree = ""; + }; + "OBJ_23" = { + isa = "PBXFileReference"; + path = "PathKit.swift"; + sourceTree = ""; + }; + "OBJ_24" = { + isa = "PBXGroup"; + children = ( + "JSONSchema::JSONSchema::Product", + "PathKit::PathKit::Product", + "JSONSchema::JSONSchemaTests::Product" + ); + name = "Products"; + path = ""; + sourceTree = "BUILT_PRODUCTS_DIR"; + }; + "OBJ_28" = { + isa = "PBXFileReference"; + path = "LICENSE"; + sourceTree = ""; + }; + "OBJ_29" = { + isa = "PBXFileReference"; + path = "JSONSchema.podspec"; + sourceTree = ""; + }; + "OBJ_3" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_OBJC_ARC = "YES"; + COMBINE_HIDPI_IMAGES = "YES"; + COPY_PHASE_STRIP = "NO"; + DEBUG_INFORMATION_FORMAT = "dwarf"; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_NS_ASSERTIONS = "YES"; + GCC_OPTIMIZATION_LEVEL = "0"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "SWIFT_PACKAGE=1", + "DEBUG=1" + ); + MACOSX_DEPLOYMENT_TARGET = "10.10"; + ONLY_ACTIVE_ARCH = "YES"; + OTHER_SWIFT_FLAGS = ( + "$(inherited)", + "-DXcode" + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = "macosx"; + SUPPORTED_PLATFORMS = ( + "macosx", + "iphoneos", + "iphonesimulator", + "appletvos", + "appletvsimulator", + "watchos", + "watchsimulator" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)", + "SWIFT_PACKAGE", + "DEBUG" + ); + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + USE_HEADERMAP = "NO"; + }; + name = "Debug"; + }; + "OBJ_30" = { + isa = "PBXFileReference"; + path = "CHANGELOG.md"; + sourceTree = ""; + }; + "OBJ_31" = { + isa = "PBXFileReference"; + path = "README.md"; + sourceTree = ""; + }; + "OBJ_33" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_34", + "OBJ_35" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_34" = { + isa = "XCBuildConfiguration"; + buildSettings = { + ENABLE_TESTABILITY = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "JSONSchema.xcodeproj/JSONSchema_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + PRODUCT_BUNDLE_IDENTIFIER = "JSONSchema"; + PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = "YES"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_VERSION = "4.2"; + TARGET_NAME = "JSONSchema"; + }; + name = "Debug"; + }; + "OBJ_35" = { + isa = "XCBuildConfiguration"; + buildSettings = { + ENABLE_TESTABILITY = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "JSONSchema.xcodeproj/JSONSchema_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + PRODUCT_BUNDLE_IDENTIFIER = "JSONSchema"; + PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = "YES"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_VERSION = "4.2"; + TARGET_NAME = "JSONSchema"; + }; + name = "Release"; + }; + "OBJ_36" = { + isa = "PBXSourcesBuildPhase"; + files = ( + "OBJ_37", + "OBJ_38", + "OBJ_39", + "OBJ_40", + "OBJ_41", + "OBJ_42", + "OBJ_43", + "OBJ_44" + ); + }; + "OBJ_37" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_8"; + }; + "OBJ_38" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_9"; + }; + "OBJ_39" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_10"; + }; + "OBJ_4" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_OBJC_ARC = "YES"; + COMBINE_HIDPI_IMAGES = "YES"; + COPY_PHASE_STRIP = "YES"; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = "s"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "SWIFT_PACKAGE=1" + ); + MACOSX_DEPLOYMENT_TARGET = "10.10"; + OTHER_SWIFT_FLAGS = ( + "$(inherited)", + "-DXcode" + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = "macosx"; + SUPPORTED_PLATFORMS = ( + "macosx", + "iphoneos", + "iphonesimulator", + "appletvos", + "appletvsimulator", + "watchos", + "watchsimulator" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)", + "SWIFT_PACKAGE" + ); + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + USE_HEADERMAP = "NO"; + }; + name = "Release"; + }; + "OBJ_40" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_11"; + }; + "OBJ_41" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_12"; + }; + "OBJ_42" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_13"; + }; + "OBJ_43" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_14"; + }; + "OBJ_44" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_15"; + }; + "OBJ_45" = { + isa = "PBXFrameworksBuildPhase"; + files = ( + ); + }; + "OBJ_47" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_48", + "OBJ_49" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_48" = { + isa = "XCBuildConfiguration"; + buildSettings = { + LD = "/usr/bin/true"; + OTHER_SWIFT_FLAGS = ( + "-swift-version", + "4.2", + "-I", + "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", + "-target", + "x86_64-apple-macosx10.10", + "-sdk", + "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk", + "-package-description-version", + "4.2" + ); + SWIFT_VERSION = "4.2"; + }; + name = "Debug"; + }; + "OBJ_49" = { + isa = "XCBuildConfiguration"; + buildSettings = { + LD = "/usr/bin/true"; + OTHER_SWIFT_FLAGS = ( + "-swift-version", + "4.2", + "-I", + "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", + "-target", + "x86_64-apple-macosx10.10", + "-sdk", + "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk", + "-package-description-version", + "4.2" + ); + SWIFT_VERSION = "4.2"; + }; + name = "Release"; + }; + "OBJ_5" = { + isa = "PBXGroup"; + children = ( + "OBJ_6", + "OBJ_7", + "OBJ_16", + "OBJ_20", + "OBJ_24", + "OBJ_28", + "OBJ_29", + "OBJ_30", + "OBJ_31" + ); + path = ""; + sourceTree = ""; + }; + "OBJ_50" = { + isa = "PBXSourcesBuildPhase"; + files = ( + "OBJ_51" + ); + }; + "OBJ_51" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_6"; + }; + "OBJ_53" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_54", + "OBJ_55" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_54" = { + isa = "XCBuildConfiguration"; + buildSettings = { + }; + name = "Debug"; + }; + "OBJ_55" = { + isa = "XCBuildConfiguration"; + buildSettings = { + }; + name = "Release"; + }; + "OBJ_56" = { + isa = "PBXTargetDependency"; + target = "JSONSchema::JSONSchemaTests"; + }; + "OBJ_58" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_59", + "OBJ_60" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_59" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_MODULES = "YES"; + EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "JSONSchema.xcodeproj/JSONSchemaTests_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/../Frameworks", + "@loader_path/Frameworks" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_VERSION = "4.2"; + TARGET_NAME = "JSONSchemaTests"; + }; + name = "Debug"; + }; + "OBJ_6" = { + isa = "PBXFileReference"; + explicitFileType = "sourcecode.swift"; + path = "Package.swift"; + sourceTree = ""; + }; + "OBJ_60" = { + isa = "XCBuildConfiguration"; + buildSettings = { + CLANG_ENABLE_MODULES = "YES"; + EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "JSONSchema.xcodeproj/JSONSchemaTests_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/../Frameworks", + "@loader_path/Frameworks" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_VERSION = "4.2"; + TARGET_NAME = "JSONSchemaTests"; + }; + name = "Release"; + }; + "OBJ_61" = { + isa = "PBXSourcesBuildPhase"; + files = ( + "OBJ_62", + "OBJ_63" + ); + }; + "OBJ_62" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_18"; + }; + "OBJ_63" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_19"; + }; + "OBJ_64" = { + isa = "PBXFrameworksBuildPhase"; + files = ( + "OBJ_65", + "OBJ_66" + ); + }; + "OBJ_65" = { + isa = "PBXBuildFile"; + fileRef = "PathKit::PathKit::Product"; + }; + "OBJ_66" = { + isa = "PBXBuildFile"; + fileRef = "JSONSchema::JSONSchema::Product"; + }; + "OBJ_67" = { + isa = "PBXTargetDependency"; + target = "PathKit::PathKit"; + }; + "OBJ_69" = { + isa = "PBXTargetDependency"; + target = "JSONSchema::JSONSchema"; + }; + "OBJ_7" = { + isa = "PBXGroup"; + children = ( + "OBJ_8", + "OBJ_9", + "OBJ_10", + "OBJ_11", + "OBJ_12", + "OBJ_13", + "OBJ_14", + "OBJ_15" + ); + name = "Sources"; + path = "Sources"; + sourceTree = "SOURCE_ROOT"; + }; + "OBJ_70" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_71", + "OBJ_72" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_71" = { + isa = "XCBuildConfiguration"; + buildSettings = { + ENABLE_TESTABILITY = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "JSONSchema.xcodeproj/PathKit_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + PRODUCT_BUNDLE_IDENTIFIER = "PathKit"; + PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = "YES"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_VERSION = "4.2"; + TARGET_NAME = "PathKit"; + }; + name = "Debug"; + }; + "OBJ_72" = { + isa = "XCBuildConfiguration"; + buildSettings = { + ENABLE_TESTABILITY = "YES"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PLATFORM_DIR)/Developer/Library/Frameworks" + ); + HEADER_SEARCH_PATHS = ( + "$(inherited)" + ); + INFOPLIST_FILE = "JSONSchema.xcodeproj/PathKit_Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" + ); + OTHER_CFLAGS = ( + "$(inherited)" + ); + OTHER_LDFLAGS = ( + "$(inherited)" + ); + OTHER_SWIFT_FLAGS = ( + "$(inherited)" + ); + PRODUCT_BUNDLE_IDENTIFIER = "PathKit"; + PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = "YES"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( + "$(inherited)" + ); + SWIFT_VERSION = "4.2"; + TARGET_NAME = "PathKit"; + }; + name = "Release"; + }; + "OBJ_73" = { + isa = "PBXSourcesBuildPhase"; + files = ( + "OBJ_74" + ); + }; + "OBJ_74" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_23"; + }; + "OBJ_75" = { + isa = "PBXFrameworksBuildPhase"; + files = ( + ); + }; + "OBJ_77" = { + isa = "XCConfigurationList"; + buildConfigurations = ( + "OBJ_78", + "OBJ_79" + ); + defaultConfigurationIsVisible = "0"; + defaultConfigurationName = "Release"; + }; + "OBJ_78" = { + isa = "XCBuildConfiguration"; + buildSettings = { + LD = "/usr/bin/true"; + OTHER_SWIFT_FLAGS = ( + "-swift-version", + "4.2", + "-I", + "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", + "-target", + "x86_64-apple-macosx10.10", + "-sdk", + "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk", + "-package-description-version", + "4.2" + ); + SWIFT_VERSION = "4.2"; + }; + name = "Debug"; + }; + "OBJ_79" = { + isa = "XCBuildConfiguration"; + buildSettings = { + LD = "/usr/bin/true"; + OTHER_SWIFT_FLAGS = ( + "-swift-version", + "4.2", + "-I", + "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", + "-target", + "x86_64-apple-macosx10.10", + "-sdk", + "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk", + "-package-description-version", + "4.2" + ); + SWIFT_VERSION = "4.2"; + }; + name = "Release"; + }; + "OBJ_8" = { + isa = "PBXFileReference"; + path = "Draft201909Validator.swift"; + sourceTree = ""; + }; + "OBJ_80" = { + isa = "PBXSourcesBuildPhase"; + files = ( + "OBJ_81" + ); + }; + "OBJ_81" = { + isa = "PBXBuildFile"; + fileRef = "OBJ_22"; + }; + "OBJ_9" = { + isa = "PBXFileReference"; + path = "Draft4Validator.swift"; + sourceTree = ""; + }; + "PathKit::PathKit" = { + isa = "PBXNativeTarget"; + buildConfigurationList = "OBJ_70"; + buildPhases = ( + "OBJ_73", + "OBJ_75" + ); + dependencies = ( + ); + name = "PathKit"; + productName = "PathKit"; + productReference = "PathKit::PathKit::Product"; + productType = "com.apple.product-type.framework"; + }; + "PathKit::PathKit::Product" = { + isa = "PBXFileReference"; + path = "PathKit.framework"; + sourceTree = "BUILT_PRODUCTS_DIR"; + }; + "PathKit::SwiftPMPackageDescription" = { + isa = "PBXNativeTarget"; + buildConfigurationList = "OBJ_77"; + buildPhases = ( + "OBJ_80" + ); + dependencies = ( + ); + name = "PathKitPackageDescription"; + productName = "PathKitPackageDescription"; + productType = "com.apple.product-type.framework"; + }; + }; + rootObject = "OBJ_1"; +} diff --git a/JSONSchema.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/JSONSchema.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..fe1aa71 --- /dev/null +++ b/JSONSchema.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..a72dc2b --- /dev/null +++ b/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded + + + \ No newline at end of file diff --git a/JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme b/JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme new file mode 100644 index 0000000..b3657b9 --- /dev/null +++ b/JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + From 48024234f6f2ee8712b812bd1b2292a187813949 Mon Sep 17 00:00:00 2001 From: Ismail Mustafa Date: Sat, 15 Aug 2020 13:55:31 -0400 Subject: [PATCH 02/16] Add date-time, date, and time validators --- .gitignore | 27 ++++++ JSONSchema.xcodeproj/JSONSchema_Info.plist | 2 +- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++ .../xcschemes/JSONSchema-Package.xcscheme | 97 +++++++++++++------ Sources/Draft201909Validator.swift | 3 + Sources/Draft7Validator.swift | 3 + Sources/Validators.swift | 49 ++++++++++ 7 files changed, 157 insertions(+), 32 deletions(-) create mode 100644 JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/.gitignore b/.gitignore index 0e03e15..ae8e107 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,28 @@ /.build/ + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Gcc Patch +/*.gcno diff --git a/JSONSchema.xcodeproj/JSONSchema_Info.plist b/JSONSchema.xcodeproj/JSONSchema_Info.plist index 57ada9f..b4349eb 100644 --- a/JSONSchema.xcodeproj/JSONSchema_Info.plist +++ b/JSONSchema.xcodeproj/JSONSchema_Info.plist @@ -18,7 +18,7 @@ CFBundleSignature ???? CFBundleVersion - $(CURRENT_PROJECT_VERSION) + 1 NSPrincipalClass diff --git a/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme b/JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme index b3657b9..e30ceda 100644 --- a/JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme +++ b/JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme @@ -1,33 +1,68 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Draft201909Validator.swift b/Sources/Draft201909Validator.swift index f6fd148..a89f8ed 100644 --- a/Sources/Draft201909Validator.swift +++ b/Sources/Draft201909Validator.swift @@ -46,6 +46,9 @@ public class Draft201909Validator: Validator { "ipv4": validateIPv4, "ipv6": validateIPv6, "uri": validateURI, + "date-time": validateDateTime, + "date": validateDate, + "time": validateTime ] public required init(schema: Bool) { diff --git a/Sources/Draft7Validator.swift b/Sources/Draft7Validator.swift index 43245b4..e9b6286 100644 --- a/Sources/Draft7Validator.swift +++ b/Sources/Draft7Validator.swift @@ -44,6 +44,9 @@ public class Draft7Validator: Validator { "ipv4": validateIPv4, "ipv6": validateIPv6, "uri": validateURI, + "date-time": validateDateTime, + "date": validateDate, + "time": validateTime ] public required init(schema: Bool) { diff --git a/Sources/Validators.swift b/Sources/Validators.swift index 0089751..82a34e6 100644 --- a/Sources/Validators.swift +++ b/Sources/Validators.swift @@ -747,6 +747,55 @@ func validateURI(_ value: Any) -> AnySequence { } +func validateDateTime(_ value: Any) -> AnySequence { + if let date = value as? String { + let rfc3339DateTimeFormatter = DateFormatter() + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" + rfc3339DateTimeFormatter.timeZone = TimeZone(secondsFromGMT: 0) + + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence(["'\(date)' is not a valid RFC 3339 formatted date-time."]) + } + + return AnySequence(EmptyCollection()) +} + +func validateDate(_ value: Any) -> AnySequence { + if let date = value as? String { + let rfc3339DateTimeFormatter = DateFormatter() + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd" + rfc3339DateTimeFormatter.timeZone = TimeZone(secondsFromGMT: 0) + + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence(["'\(date)' is not a valid RFC 3339 formatted date."]) + } + + return AnySequence(EmptyCollection()) +} + +func validateTime(_ value: Any) -> AnySequence { + if let date = value as? String { + let rfc3339DateTimeFormatter = DateFormatter() + rfc3339DateTimeFormatter.dateFormat = "HH:mm:ssZZZZZ" + rfc3339DateTimeFormatter.timeZone = TimeZone(secondsFromGMT: 0) + + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence(["'\(date)' is not a valid RFC 3339 formatted time."]) + } + + return AnySequence(EmptyCollection()) +} + + extension Sequence where Iterator.Element == ValidationError { func validationResult() -> ValidationResult { let errors = Array(self) From 0aec188b4f53198cab7e466cb08e849512874ecf Mon Sep 17 00:00:00 2001 From: Ismail Mustafa Date: Fri, 21 Aug 2020 11:09:06 -0400 Subject: [PATCH 03/16] Enable tests for new validators --- Tests/JSONSchemaTests/JSONSchemaCases.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Tests/JSONSchemaTests/JSONSchemaCases.swift b/Tests/JSONSchemaTests/JSONSchemaCases.swift index 9d4790e..c9ee516 100644 --- a/Tests/JSONSchemaTests/JSONSchemaCases.swift +++ b/Tests/JSONSchemaTests/JSONSchemaCases.swift @@ -100,8 +100,6 @@ class JSONSchemaCases: XCTestCase { "ecmascript-regex.json", // optional, format - "date-time.json", - "date.json", "email.json", "hostname.json", "idn-email.json", @@ -111,7 +109,6 @@ class JSONSchemaCases: XCTestCase { "json-pointer.json", "regex.json", "relative-json-pointer.json", - "time.json", "uri-reference.json", "uri-template.json", ]) @@ -134,8 +131,6 @@ class JSONSchemaCases: XCTestCase { "ecmascript-regex.json", // optional, format - "date-time.json", - "date.json", "duration.json", "email.json", "hostname.json", @@ -146,7 +141,6 @@ class JSONSchemaCases: XCTestCase { "json-pointer.json", "regex.json", "relative-json-pointer.json", - "time.json", "uri-reference.json", "uri-template.json", ]) From c01e38caeb1777fa86a93662c56f136d949db9ea Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 14 Apr 2021 07:53:08 +0100 Subject: [PATCH 04/16] Re-add date + time validators --- Sources/Validators.swift | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Sources/Validators.swift b/Sources/Validators.swift index 5a78185..1df04f2 100644 --- a/Sources/Validators.swift +++ b/Sources/Validators.swift @@ -146,6 +146,55 @@ func isEqual(_ lhs: NSObject, _ rhs: NSObject) -> Bool { } +func validateDateTime(_ value: Any) -> AnySequence { + if let date = value as? String { + let rfc3339DateTimeFormatter = DateFormatter() + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" + rfc3339DateTimeFormatter.timeZone = TimeZone(secondsFromGMT: 0) + + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence(["'\(date)' is not a valid RFC 3339 formatted date-time."]) + } + + return AnySequence(EmptyCollection()) +} + + +func validateDate(_ value: Any) -> AnySequence { + if let date = value as? String { + let rfc3339DateTimeFormatter = DateFormatter() + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd" + rfc3339DateTimeFormatter.timeZone = TimeZone(secondsFromGMT: 0) + + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence(["'\(date)' is not a valid RFC 3339 formatted date."]) + } + + return AnySequence(EmptyCollection()) +} + + +func validateTime(_ value: Any) -> AnySequence { + if let date = value as? String { + let rfc3339DateTimeFormatter = DateFormatter() + rfc3339DateTimeFormatter.dateFormat = "HH:mm:ssZZZZZ" + rfc3339DateTimeFormatter.timeZone = TimeZone(secondsFromGMT: 0) + + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence(["'\(date)' is not a valid RFC 3339 formatted time."]) + } + + return AnySequence(EmptyCollection()) +} extension Sequence where Iterator.Element == ValidationError { func validationResult() -> ValidationResult { From a7f6c8239f19dcf0631df3b8474e6eb720d12519 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 14 Apr 2021 07:54:35 +0100 Subject: [PATCH 05/16] Add swiftpm generated folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ae8e107..2f4c642 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ DerivedData/ ## Gcc Patch /*.gcno +.swiftpm/ From 991b65346e79c75eb1182f01a3498e2a4672e7e9 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 14 Apr 2021 08:54:11 +0100 Subject: [PATCH 06/16] Update validators + tests --- Sources/Draft201909Validator.swift | 4 +- Sources/Draft202012Validator.swift | 3 ++ Sources/Validator.swift | 1 + Sources/Validators.swift | 78 +++++++++++++++++++++++++----- 4 files changed, 72 insertions(+), 14 deletions(-) diff --git a/Sources/Draft201909Validator.swift b/Sources/Draft201909Validator.swift index 070f7bc..787a907 100644 --- a/Sources/Draft201909Validator.swift +++ b/Sources/Draft201909Validator.swift @@ -53,8 +53,8 @@ public class Draft201909Validator: Validator { "unevaluatedItems": unsupported("unevaluatedItems"), "unevaluatedProperties": unsupported("unevaluatedProperties"), ] - - let formats: [String: (Context, String) -> (AnySequence)] = [ + + let formats: [String: ValidationClosure] = [ "ipv4": validateIPv4, "ipv6": validateIPv6, "uri": validateURI, diff --git a/Sources/Draft202012Validator.swift b/Sources/Draft202012Validator.swift index ee1aeb0..1440c0c 100644 --- a/Sources/Draft202012Validator.swift +++ b/Sources/Draft202012Validator.swift @@ -56,11 +56,14 @@ public class Draft202012Validator: Validator { ] let formats: [String: (Context, String) -> (AnySequence)] = [ + "date-time": validateDateTime, + "date": validateDate, "ipv4": validateIPv4, "ipv6": validateIPv6, "uri": validateURI, "uuid": validateUUID, "regex": validateRegex, + "time": validateTime, "json-pointer": validateJSONPointer, ] diff --git a/Sources/Validator.swift b/Sources/Validator.swift index 13016c5..48fb8f5 100644 --- a/Sources/Validator.swift +++ b/Sources/Validator.swift @@ -63,6 +63,7 @@ class Context { protocol Validator { typealias Validation = (Context, Any, Any, [String: Any]) throws -> AnySequence + typealias ValidationClosure = (Context, String) -> (AnySequence) var resolver: RefResolver { get } diff --git a/Sources/Validators.swift b/Sources/Validators.swift index 1df04f2..d768831 100644 --- a/Sources/Validators.swift +++ b/Sources/Validators.swift @@ -146,51 +146,105 @@ func isEqual(_ lhs: NSObject, _ rhs: NSObject) -> Bool { } -func validateDateTime(_ value: Any) -> AnySequence { +func validateDateTime(_ context: Context, _ value: Any) -> AnySequence { if let date = value as? String { + if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}", options: .caseInsensitive) { + let range = NSRange(location: 0, length: date.utf16.count) + let result = regularExpression.matches(in: date, options: [], range: range) + if result.isEmpty { + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + } + let rfc3339DateTimeFormatter = DateFormatter() + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" - rfc3339DateTimeFormatter.timeZone = TimeZone(secondsFromGMT: 0) - + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd't'HH:mm:ss.SSS'z'" if rfc3339DateTimeFormatter.date(from: date) != nil { return AnySequence(EmptyCollection()) } - return AnySequence(["'\(date)' is not a valid RFC 3339 formatted date-time."]) + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date-time.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) } return AnySequence(EmptyCollection()) } -func validateDate(_ value: Any) -> AnySequence { +func validateDate(_ context: Context, _ value: Any) -> AnySequence { if let date = value as? String { + + if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}$", options: []) { + let range = NSRange(location: 0, length: date.utf16.count) + let result = regularExpression.matches(in: date, options: [], range: range) + if result.isEmpty { + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + } + let rfc3339DateTimeFormatter = DateFormatter() + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd" - rfc3339DateTimeFormatter.timeZone = TimeZone(secondsFromGMT: 0) - if rfc3339DateTimeFormatter.date(from: date) != nil { return AnySequence(EmptyCollection()) } - return AnySequence(["'\(date)' is not a valid RFC 3339 formatted date."]) + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) } return AnySequence(EmptyCollection()) } -func validateTime(_ value: Any) -> AnySequence { +func validateTime(_ context: Context, _ value: Any) -> AnySequence { if let date = value as? String { let rfc3339DateTimeFormatter = DateFormatter() - rfc3339DateTimeFormatter.dateFormat = "HH:mm:ssZZZZZ" - rfc3339DateTimeFormatter.timeZone = TimeZone(secondsFromGMT: 0) + rfc3339DateTimeFormatter.dateFormat = "HH:mm:ss.SSSZZZZZ" if rfc3339DateTimeFormatter.date(from: date) != nil { return AnySequence(EmptyCollection()) } - return AnySequence(["'\(date)' is not a valid RFC 3339 formatted time."]) + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted time.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) } return AnySequence(EmptyCollection()) From a47ad74ece1131127274ffb535f3100afbd2c892 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 14 Apr 2021 08:58:25 +0100 Subject: [PATCH 07/16] Move validators to correct folder --- Sources/Validation/date.swift | 38 +++++++++++ Sources/Validation/datetime.swift | 46 +++++++++++++ Sources/Validation/time.swift | 22 +++++++ Sources/Validators.swift | 105 ------------------------------ 4 files changed, 106 insertions(+), 105 deletions(-) create mode 100644 Sources/Validation/date.swift create mode 100644 Sources/Validation/datetime.swift create mode 100644 Sources/Validation/time.swift diff --git a/Sources/Validation/date.swift b/Sources/Validation/date.swift new file mode 100644 index 0000000..df4b9dd --- /dev/null +++ b/Sources/Validation/date.swift @@ -0,0 +1,38 @@ +import Foundation + +func validateDate(_ context: Context, _ value: Any) -> AnySequence { + if let date = value as? String { + + if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}$", options: []) { + let range = NSRange(location: 0, length: date.utf16.count) + let result = regularExpression.matches(in: date, options: [], range: range) + if result.isEmpty { + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + } + + let rfc3339DateTimeFormatter = DateFormatter() + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd" + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + + return AnySequence(EmptyCollection()) +} + diff --git a/Sources/Validation/datetime.swift b/Sources/Validation/datetime.swift new file mode 100644 index 0000000..e1b7d68 --- /dev/null +++ b/Sources/Validation/datetime.swift @@ -0,0 +1,46 @@ +import Foundation + +func validateDateTime(_ context: Context, _ value: Any) -> AnySequence { + if let date = value as? String { + if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}", options: .caseInsensitive) { + let range = NSRange(location: 0, length: date.utf16.count) + let result = regularExpression.matches(in: date, options: [], range: range) + if result.isEmpty { + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + } + + let rfc3339DateTimeFormatter = DateFormatter() + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd't'HH:mm:ss.SSS'z'" + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date-time.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + + return AnySequence(EmptyCollection()) +} diff --git a/Sources/Validation/time.swift b/Sources/Validation/time.swift new file mode 100644 index 0000000..1f0f98f --- /dev/null +++ b/Sources/Validation/time.swift @@ -0,0 +1,22 @@ +import Foundation + +func validateTime(_ context: Context, _ value: Any) -> AnySequence { + if let date = value as? String { + let rfc3339DateTimeFormatter = DateFormatter() + rfc3339DateTimeFormatter.dateFormat = "HH:mm:ss.SSSZZZZZ" + + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted time.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + + return AnySequence(EmptyCollection()) +} diff --git a/Sources/Validators.swift b/Sources/Validators.swift index d768831..aacf912 100644 --- a/Sources/Validators.swift +++ b/Sources/Validators.swift @@ -145,111 +145,6 @@ func isEqual(_ lhs: NSObject, _ rhs: NSObject) -> Bool { return lhs == rhs } - -func validateDateTime(_ context: Context, _ value: Any) -> AnySequence { - if let date = value as? String { - if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}", options: .caseInsensitive) { - let range = NSRange(location: 0, length: date.utf16.count) - let result = regularExpression.matches(in: date, options: [], range: range) - if result.isEmpty { - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted date.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) - } - } - - let rfc3339DateTimeFormatter = DateFormatter() - - rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - - rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - - rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd't'HH:mm:ss.SSS'z'" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted date-time.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) - } - - return AnySequence(EmptyCollection()) -} - - -func validateDate(_ context: Context, _ value: Any) -> AnySequence { - if let date = value as? String { - - if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}$", options: []) { - let range = NSRange(location: 0, length: date.utf16.count) - let result = regularExpression.matches(in: date, options: [], range: range) - if result.isEmpty { - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted date.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) - } - } - - let rfc3339DateTimeFormatter = DateFormatter() - - rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted date.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) - } - - return AnySequence(EmptyCollection()) -} - - -func validateTime(_ context: Context, _ value: Any) -> AnySequence { - if let date = value as? String { - let rfc3339DateTimeFormatter = DateFormatter() - rfc3339DateTimeFormatter.dateFormat = "HH:mm:ss.SSSZZZZZ" - - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted time.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) - } - - return AnySequence(EmptyCollection()) -} - extension Sequence where Iterator.Element == ValidationError { func validationResult() -> ValidationResult { let errors = Array(self) From 5d4edf771db6903bf78cd9e17b0f07dc5757ba6b Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 14 Apr 2021 08:59:55 +0100 Subject: [PATCH 08/16] Fix gitignore --- .gitignore | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 2f4c642..af13669 100644 --- a/.gitignore +++ b/.gitignore @@ -1,29 +1,2 @@ /.build/ - -# Xcode -# -# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore - -## User settings -xcuserdata/ - -## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) -*.xcscmblueprint -*.xccheckout - -## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) -build/ -DerivedData/ -*.moved-aside -*.pbxuser -!default.pbxuser -*.mode1v3 -!default.mode1v3 -*.mode2v3 -!default.mode2v3 -*.perspectivev3 -!default.perspectivev3 - -## Gcc Patch -/*.gcno -.swiftpm/ +/.swiftpm/ From 4ddf0a4b90748db6f4ea7b71d73edc5a02643604 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 14 Apr 2021 09:00:36 +0100 Subject: [PATCH 09/16] Remove xcodeproj --- .../JSONSchemaTests_Info.plist | 25 - JSONSchema.xcodeproj/JSONSchema_Info.plist | 25 - JSONSchema.xcodeproj/PathKit_Info.plist | 25 - JSONSchema.xcodeproj/project.pbxproj | 876 ------------------ .../contents.xcworkspacedata | 7 - .../xcshareddata/IDEWorkspaceChecks.plist | 8 - .../xcshareddata/WorkspaceSettings.xcsettings | 8 - .../xcschemes/JSONSchema-Package.xcscheme | 68 -- 8 files changed, 1042 deletions(-) delete mode 100644 JSONSchema.xcodeproj/JSONSchemaTests_Info.plist delete mode 100644 JSONSchema.xcodeproj/JSONSchema_Info.plist delete mode 100644 JSONSchema.xcodeproj/PathKit_Info.plist delete mode 100644 JSONSchema.xcodeproj/project.pbxproj delete mode 100644 JSONSchema.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist delete mode 100644 JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings delete mode 100644 JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme diff --git a/JSONSchema.xcodeproj/JSONSchemaTests_Info.plist b/JSONSchema.xcodeproj/JSONSchemaTests_Info.plist deleted file mode 100644 index 7c23420..0000000 --- a/JSONSchema.xcodeproj/JSONSchemaTests_Info.plist +++ /dev/null @@ -1,25 +0,0 @@ - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/JSONSchema.xcodeproj/JSONSchema_Info.plist b/JSONSchema.xcodeproj/JSONSchema_Info.plist deleted file mode 100644 index b4349eb..0000000 --- a/JSONSchema.xcodeproj/JSONSchema_Info.plist +++ /dev/null @@ -1,25 +0,0 @@ - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - NSPrincipalClass - - - diff --git a/JSONSchema.xcodeproj/PathKit_Info.plist b/JSONSchema.xcodeproj/PathKit_Info.plist deleted file mode 100644 index 57ada9f..0000000 --- a/JSONSchema.xcodeproj/PathKit_Info.plist +++ /dev/null @@ -1,25 +0,0 @@ - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/JSONSchema.xcodeproj/project.pbxproj b/JSONSchema.xcodeproj/project.pbxproj deleted file mode 100644 index 57196cb..0000000 --- a/JSONSchema.xcodeproj/project.pbxproj +++ /dev/null @@ -1,876 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = "1"; - objectVersion = "46"; - objects = { - "JSONSchema::JSONSchema" = { - isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_33"; - buildPhases = ( - "OBJ_36", - "OBJ_45" - ); - dependencies = ( - ); - name = "JSONSchema"; - productName = "JSONSchema"; - productReference = "JSONSchema::JSONSchema::Product"; - productType = "com.apple.product-type.framework"; - }; - "JSONSchema::JSONSchema::Product" = { - isa = "PBXFileReference"; - path = "JSONSchema.framework"; - sourceTree = "BUILT_PRODUCTS_DIR"; - }; - "JSONSchema::JSONSchemaPackageTests::ProductTarget" = { - isa = "PBXAggregateTarget"; - buildConfigurationList = "OBJ_53"; - buildPhases = ( - ); - dependencies = ( - "OBJ_56" - ); - name = "JSONSchemaPackageTests"; - productName = "JSONSchemaPackageTests"; - }; - "JSONSchema::JSONSchemaTests" = { - isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_58"; - buildPhases = ( - "OBJ_61", - "OBJ_64" - ); - dependencies = ( - "OBJ_67", - "OBJ_69" - ); - name = "JSONSchemaTests"; - productName = "JSONSchemaTests"; - productReference = "JSONSchema::JSONSchemaTests::Product"; - productType = "com.apple.product-type.bundle.unit-test"; - }; - "JSONSchema::JSONSchemaTests::Product" = { - isa = "PBXFileReference"; - path = "JSONSchemaTests.xctest"; - sourceTree = "BUILT_PRODUCTS_DIR"; - }; - "JSONSchema::SwiftPMPackageDescription" = { - isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_47"; - buildPhases = ( - "OBJ_50" - ); - dependencies = ( - ); - name = "JSONSchemaPackageDescription"; - productName = "JSONSchemaPackageDescription"; - productType = "com.apple.product-type.framework"; - }; - "OBJ_1" = { - isa = "PBXProject"; - attributes = { - LastSwiftMigration = "9999"; - LastUpgradeCheck = "9999"; - }; - buildConfigurationList = "OBJ_2"; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = "en"; - hasScannedForEncodings = "0"; - knownRegions = ( - "en" - ); - mainGroup = "OBJ_5"; - productRefGroup = "OBJ_24"; - projectDirPath = "."; - targets = ( - "JSONSchema::JSONSchema", - "JSONSchema::SwiftPMPackageDescription", - "JSONSchema::JSONSchemaPackageTests::ProductTarget", - "JSONSchema::JSONSchemaTests", - "PathKit::PathKit", - "PathKit::SwiftPMPackageDescription" - ); - }; - "OBJ_10" = { - isa = "PBXFileReference"; - path = "Draft6Validator.swift"; - sourceTree = ""; - }; - "OBJ_11" = { - isa = "PBXFileReference"; - path = "Draft7Validator.swift"; - sourceTree = ""; - }; - "OBJ_12" = { - isa = "PBXFileReference"; - path = "JSONSchema.swift"; - sourceTree = ""; - }; - "OBJ_13" = { - isa = "PBXFileReference"; - path = "RefResolver.swift"; - sourceTree = ""; - }; - "OBJ_14" = { - isa = "PBXFileReference"; - path = "Validator.swift"; - sourceTree = ""; - }; - "OBJ_15" = { - isa = "PBXFileReference"; - path = "Validators.swift"; - sourceTree = ""; - }; - "OBJ_16" = { - isa = "PBXGroup"; - children = ( - "OBJ_17" - ); - name = "Tests"; - path = ""; - sourceTree = "SOURCE_ROOT"; - }; - "OBJ_17" = { - isa = "PBXGroup"; - children = ( - "OBJ_18", - "OBJ_19" - ); - name = "JSONSchemaTests"; - path = "Tests/JSONSchemaTests"; - sourceTree = "SOURCE_ROOT"; - }; - "OBJ_18" = { - isa = "PBXFileReference"; - path = "JSONSchemaCases.swift"; - sourceTree = ""; - }; - "OBJ_19" = { - isa = "PBXFileReference"; - path = "JSONSchemaTests.swift"; - sourceTree = ""; - }; - "OBJ_2" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_3", - "OBJ_4" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_20" = { - isa = "PBXGroup"; - children = ( - "OBJ_21" - ); - name = "Dependencies"; - path = ""; - sourceTree = ""; - }; - "OBJ_21" = { - isa = "PBXGroup"; - children = ( - "OBJ_22", - "OBJ_23" - ); - name = "PathKit 1.0.0"; - path = ".build/checkouts/PathKit/Sources"; - sourceTree = "SOURCE_ROOT"; - }; - "OBJ_22" = { - isa = "PBXFileReference"; - explicitFileType = "sourcecode.swift"; - name = "Package.swift"; - path = "/Users/ismailmustafa/Desktop/projects/JSONSchema.swift/.build/checkouts/PathKit/Package.swift"; - sourceTree = ""; - }; - "OBJ_23" = { - isa = "PBXFileReference"; - path = "PathKit.swift"; - sourceTree = ""; - }; - "OBJ_24" = { - isa = "PBXGroup"; - children = ( - "JSONSchema::JSONSchema::Product", - "PathKit::PathKit::Product", - "JSONSchema::JSONSchemaTests::Product" - ); - name = "Products"; - path = ""; - sourceTree = "BUILT_PRODUCTS_DIR"; - }; - "OBJ_28" = { - isa = "PBXFileReference"; - path = "LICENSE"; - sourceTree = ""; - }; - "OBJ_29" = { - isa = "PBXFileReference"; - path = "JSONSchema.podspec"; - sourceTree = ""; - }; - "OBJ_3" = { - isa = "XCBuildConfiguration"; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = "YES"; - COMBINE_HIDPI_IMAGES = "YES"; - COPY_PHASE_STRIP = "NO"; - DEBUG_INFORMATION_FORMAT = "dwarf"; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_NS_ASSERTIONS = "YES"; - GCC_OPTIMIZATION_LEVEL = "0"; - GCC_PREPROCESSOR_DEFINITIONS = ( - "$(inherited)", - "SWIFT_PACKAGE=1", - "DEBUG=1" - ); - MACOSX_DEPLOYMENT_TARGET = "10.10"; - ONLY_ACTIVE_ARCH = "YES"; - OTHER_SWIFT_FLAGS = ( - "$(inherited)", - "-DXcode" - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = "macosx"; - SUPPORTED_PLATFORMS = ( - "macosx", - "iphoneos", - "iphonesimulator", - "appletvos", - "appletvsimulator", - "watchos", - "watchsimulator" - ); - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)", - "SWIFT_PACKAGE", - "DEBUG" - ); - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - USE_HEADERMAP = "NO"; - }; - name = "Debug"; - }; - "OBJ_30" = { - isa = "PBXFileReference"; - path = "CHANGELOG.md"; - sourceTree = ""; - }; - "OBJ_31" = { - isa = "PBXFileReference"; - path = "README.md"; - sourceTree = ""; - }; - "OBJ_33" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_34", - "OBJ_35" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_34" = { - isa = "XCBuildConfiguration"; - buildSettings = { - ENABLE_TESTABILITY = "YES"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "JSONSchema.xcodeproj/JSONSchema_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - PRODUCT_BUNDLE_IDENTIFIER = "JSONSchema"; - PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = "YES"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_VERSION = "4.2"; - TARGET_NAME = "JSONSchema"; - }; - name = "Debug"; - }; - "OBJ_35" = { - isa = "XCBuildConfiguration"; - buildSettings = { - ENABLE_TESTABILITY = "YES"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "JSONSchema.xcodeproj/JSONSchema_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - PRODUCT_BUNDLE_IDENTIFIER = "JSONSchema"; - PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = "YES"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_VERSION = "4.2"; - TARGET_NAME = "JSONSchema"; - }; - name = "Release"; - }; - "OBJ_36" = { - isa = "PBXSourcesBuildPhase"; - files = ( - "OBJ_37", - "OBJ_38", - "OBJ_39", - "OBJ_40", - "OBJ_41", - "OBJ_42", - "OBJ_43", - "OBJ_44" - ); - }; - "OBJ_37" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_8"; - }; - "OBJ_38" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_9"; - }; - "OBJ_39" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_10"; - }; - "OBJ_4" = { - isa = "XCBuildConfiguration"; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = "YES"; - COMBINE_HIDPI_IMAGES = "YES"; - COPY_PHASE_STRIP = "YES"; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_OPTIMIZATION_LEVEL = "s"; - GCC_PREPROCESSOR_DEFINITIONS = ( - "$(inherited)", - "SWIFT_PACKAGE=1" - ); - MACOSX_DEPLOYMENT_TARGET = "10.10"; - OTHER_SWIFT_FLAGS = ( - "$(inherited)", - "-DXcode" - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = "macosx"; - SUPPORTED_PLATFORMS = ( - "macosx", - "iphoneos", - "iphonesimulator", - "appletvos", - "appletvsimulator", - "watchos", - "watchsimulator" - ); - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)", - "SWIFT_PACKAGE" - ); - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - USE_HEADERMAP = "NO"; - }; - name = "Release"; - }; - "OBJ_40" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_11"; - }; - "OBJ_41" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_12"; - }; - "OBJ_42" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_13"; - }; - "OBJ_43" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_14"; - }; - "OBJ_44" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_15"; - }; - "OBJ_45" = { - isa = "PBXFrameworksBuildPhase"; - files = ( - ); - }; - "OBJ_47" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_48", - "OBJ_49" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_48" = { - isa = "XCBuildConfiguration"; - buildSettings = { - LD = "/usr/bin/true"; - OTHER_SWIFT_FLAGS = ( - "-swift-version", - "4.2", - "-I", - "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", - "-target", - "x86_64-apple-macosx10.10", - "-sdk", - "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk", - "-package-description-version", - "4.2" - ); - SWIFT_VERSION = "4.2"; - }; - name = "Debug"; - }; - "OBJ_49" = { - isa = "XCBuildConfiguration"; - buildSettings = { - LD = "/usr/bin/true"; - OTHER_SWIFT_FLAGS = ( - "-swift-version", - "4.2", - "-I", - "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", - "-target", - "x86_64-apple-macosx10.10", - "-sdk", - "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk", - "-package-description-version", - "4.2" - ); - SWIFT_VERSION = "4.2"; - }; - name = "Release"; - }; - "OBJ_5" = { - isa = "PBXGroup"; - children = ( - "OBJ_6", - "OBJ_7", - "OBJ_16", - "OBJ_20", - "OBJ_24", - "OBJ_28", - "OBJ_29", - "OBJ_30", - "OBJ_31" - ); - path = ""; - sourceTree = ""; - }; - "OBJ_50" = { - isa = "PBXSourcesBuildPhase"; - files = ( - "OBJ_51" - ); - }; - "OBJ_51" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_6"; - }; - "OBJ_53" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_54", - "OBJ_55" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_54" = { - isa = "XCBuildConfiguration"; - buildSettings = { - }; - name = "Debug"; - }; - "OBJ_55" = { - isa = "XCBuildConfiguration"; - buildSettings = { - }; - name = "Release"; - }; - "OBJ_56" = { - isa = "PBXTargetDependency"; - target = "JSONSchema::JSONSchemaTests"; - }; - "OBJ_58" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_59", - "OBJ_60" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_59" = { - isa = "XCBuildConfiguration"; - buildSettings = { - CLANG_ENABLE_MODULES = "YES"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "JSONSchema.xcodeproj/JSONSchemaTests_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@loader_path/../Frameworks", - "@loader_path/Frameworks" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_VERSION = "4.2"; - TARGET_NAME = "JSONSchemaTests"; - }; - name = "Debug"; - }; - "OBJ_6" = { - isa = "PBXFileReference"; - explicitFileType = "sourcecode.swift"; - path = "Package.swift"; - sourceTree = ""; - }; - "OBJ_60" = { - isa = "XCBuildConfiguration"; - buildSettings = { - CLANG_ENABLE_MODULES = "YES"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = "YES"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "JSONSchema.xcodeproj/JSONSchemaTests_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@loader_path/../Frameworks", - "@loader_path/Frameworks" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_VERSION = "4.2"; - TARGET_NAME = "JSONSchemaTests"; - }; - name = "Release"; - }; - "OBJ_61" = { - isa = "PBXSourcesBuildPhase"; - files = ( - "OBJ_62", - "OBJ_63" - ); - }; - "OBJ_62" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_18"; - }; - "OBJ_63" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_19"; - }; - "OBJ_64" = { - isa = "PBXFrameworksBuildPhase"; - files = ( - "OBJ_65", - "OBJ_66" - ); - }; - "OBJ_65" = { - isa = "PBXBuildFile"; - fileRef = "PathKit::PathKit::Product"; - }; - "OBJ_66" = { - isa = "PBXBuildFile"; - fileRef = "JSONSchema::JSONSchema::Product"; - }; - "OBJ_67" = { - isa = "PBXTargetDependency"; - target = "PathKit::PathKit"; - }; - "OBJ_69" = { - isa = "PBXTargetDependency"; - target = "JSONSchema::JSONSchema"; - }; - "OBJ_7" = { - isa = "PBXGroup"; - children = ( - "OBJ_8", - "OBJ_9", - "OBJ_10", - "OBJ_11", - "OBJ_12", - "OBJ_13", - "OBJ_14", - "OBJ_15" - ); - name = "Sources"; - path = "Sources"; - sourceTree = "SOURCE_ROOT"; - }; - "OBJ_70" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_71", - "OBJ_72" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_71" = { - isa = "XCBuildConfiguration"; - buildSettings = { - ENABLE_TESTABILITY = "YES"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "JSONSchema.xcodeproj/PathKit_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - PRODUCT_BUNDLE_IDENTIFIER = "PathKit"; - PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = "YES"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_VERSION = "4.2"; - TARGET_NAME = "PathKit"; - }; - name = "Debug"; - }; - "OBJ_72" = { - isa = "XCBuildConfiguration"; - buildSettings = { - ENABLE_TESTABILITY = "YES"; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PLATFORM_DIR)/Developer/Library/Frameworks" - ); - HEADER_SEARCH_PATHS = ( - "$(inherited)" - ); - INFOPLIST_FILE = "JSONSchema.xcodeproj/PathKit_Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx" - ); - OTHER_CFLAGS = ( - "$(inherited)" - ); - OTHER_LDFLAGS = ( - "$(inherited)" - ); - OTHER_SWIFT_FLAGS = ( - "$(inherited)" - ); - PRODUCT_BUNDLE_IDENTIFIER = "PathKit"; - PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SKIP_INSTALL = "YES"; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = ( - "$(inherited)" - ); - SWIFT_VERSION = "4.2"; - TARGET_NAME = "PathKit"; - }; - name = "Release"; - }; - "OBJ_73" = { - isa = "PBXSourcesBuildPhase"; - files = ( - "OBJ_74" - ); - }; - "OBJ_74" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_23"; - }; - "OBJ_75" = { - isa = "PBXFrameworksBuildPhase"; - files = ( - ); - }; - "OBJ_77" = { - isa = "XCConfigurationList"; - buildConfigurations = ( - "OBJ_78", - "OBJ_79" - ); - defaultConfigurationIsVisible = "0"; - defaultConfigurationName = "Release"; - }; - "OBJ_78" = { - isa = "XCBuildConfiguration"; - buildSettings = { - LD = "/usr/bin/true"; - OTHER_SWIFT_FLAGS = ( - "-swift-version", - "4.2", - "-I", - "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", - "-target", - "x86_64-apple-macosx10.10", - "-sdk", - "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk", - "-package-description-version", - "4.2" - ); - SWIFT_VERSION = "4.2"; - }; - name = "Debug"; - }; - "OBJ_79" = { - isa = "XCBuildConfiguration"; - buildSettings = { - LD = "/usr/bin/true"; - OTHER_SWIFT_FLAGS = ( - "-swift-version", - "4.2", - "-I", - "$(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2", - "-target", - "x86_64-apple-macosx10.10", - "-sdk", - "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk", - "-package-description-version", - "4.2" - ); - SWIFT_VERSION = "4.2"; - }; - name = "Release"; - }; - "OBJ_8" = { - isa = "PBXFileReference"; - path = "Draft201909Validator.swift"; - sourceTree = ""; - }; - "OBJ_80" = { - isa = "PBXSourcesBuildPhase"; - files = ( - "OBJ_81" - ); - }; - "OBJ_81" = { - isa = "PBXBuildFile"; - fileRef = "OBJ_22"; - }; - "OBJ_9" = { - isa = "PBXFileReference"; - path = "Draft4Validator.swift"; - sourceTree = ""; - }; - "PathKit::PathKit" = { - isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_70"; - buildPhases = ( - "OBJ_73", - "OBJ_75" - ); - dependencies = ( - ); - name = "PathKit"; - productName = "PathKit"; - productReference = "PathKit::PathKit::Product"; - productType = "com.apple.product-type.framework"; - }; - "PathKit::PathKit::Product" = { - isa = "PBXFileReference"; - path = "PathKit.framework"; - sourceTree = "BUILT_PRODUCTS_DIR"; - }; - "PathKit::SwiftPMPackageDescription" = { - isa = "PBXNativeTarget"; - buildConfigurationList = "OBJ_77"; - buildPhases = ( - "OBJ_80" - ); - dependencies = ( - ); - name = "PathKitPackageDescription"; - productName = "PathKitPackageDescription"; - productType = "com.apple.product-type.framework"; - }; - }; - rootObject = "OBJ_1"; -} diff --git a/JSONSchema.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/JSONSchema.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index fe1aa71..0000000 --- a/JSONSchema.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings deleted file mode 100644 index a72dc2b..0000000 --- a/JSONSchema.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded - - - \ No newline at end of file diff --git a/JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme b/JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme deleted file mode 100644 index e30ceda..0000000 --- a/JSONSchema.xcodeproj/xcshareddata/xcschemes/JSONSchema-Package.xcscheme +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - From 9ff0b2a67509fea88b256178917d07594354db05 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 14 Apr 2021 09:05:51 +0100 Subject: [PATCH 10/16] Cleanup --- Sources/Draft201909Validator.swift | 4 ++-- Sources/Validator.swift | 1 - Tests/JSONSchemaTests/JSONSchemaCases.swift | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Draft201909Validator.swift b/Sources/Draft201909Validator.swift index 787a907..070f7bc 100644 --- a/Sources/Draft201909Validator.swift +++ b/Sources/Draft201909Validator.swift @@ -53,8 +53,8 @@ public class Draft201909Validator: Validator { "unevaluatedItems": unsupported("unevaluatedItems"), "unevaluatedProperties": unsupported("unevaluatedProperties"), ] - - let formats: [String: ValidationClosure] = [ + + let formats: [String: (Context, String) -> (AnySequence)] = [ "ipv4": validateIPv4, "ipv6": validateIPv6, "uri": validateURI, diff --git a/Sources/Validator.swift b/Sources/Validator.swift index 48fb8f5..13016c5 100644 --- a/Sources/Validator.swift +++ b/Sources/Validator.swift @@ -63,7 +63,6 @@ class Context { protocol Validator { typealias Validation = (Context, Any, Any, [String: Any]) throws -> AnySequence - typealias ValidationClosure = (Context, String) -> (AnySequence) var resolver: RefResolver { get } diff --git a/Tests/JSONSchemaTests/JSONSchemaCases.swift b/Tests/JSONSchemaTests/JSONSchemaCases.swift index bd83576..e4ac246 100644 --- a/Tests/JSONSchemaTests/JSONSchemaCases.swift +++ b/Tests/JSONSchemaTests/JSONSchemaCases.swift @@ -137,6 +137,8 @@ class JSONSchemaCases: XCTestCase { "infinite-loop-detection.json", // optional, format + "date-time.json", + "date.json", "email.json", "hostname.json", "idn-email.json", @@ -144,6 +146,7 @@ class JSONSchemaCases: XCTestCase { "iri-reference.json", "iri.json", "relative-json-pointer.json", + "time.json", "uri-reference.json", "uri-template.json", ] + additionalExclusions) @@ -219,6 +222,7 @@ class JSONSchemaCases: XCTestCase { "iri-reference.json", "iri.json", "relative-json-pointer.json", + "time.json", "uri-reference.json", "uri-template.json", ] + additionalExclusions) From c21d82683c426097700afc90dfe63fe06ed5127c Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 14 Apr 2021 09:10:12 +0100 Subject: [PATCH 11/16] Fix indentation --- Sources/Validation/date.swift | 58 ++++++++++++----------- Sources/Validation/datetime.swift | 76 +++++++++++++++---------------- Sources/Validation/time.swift | 30 ++++++------ 3 files changed, 81 insertions(+), 83 deletions(-) diff --git a/Sources/Validation/date.swift b/Sources/Validation/date.swift index df4b9dd..989745a 100644 --- a/Sources/Validation/date.swift +++ b/Sources/Validation/date.swift @@ -1,38 +1,36 @@ import Foundation func validateDate(_ context: Context, _ value: Any) -> AnySequence { - if let date = value as? String { - - if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}$", options: []) { - let range = NSRange(location: 0, length: date.utf16.count) - let result = regularExpression.matches(in: date, options: [], range: range) - if result.isEmpty { - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted date.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) - } - } - - let rfc3339DateTimeFormatter = DateFormatter() - - rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - + if let date = value as? String { + if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}$", options: []) { + let range = NSRange(location: 0, length: date.utf16.count) + let result = regularExpression.matches(in: date, options: [], range: range) + if result.isEmpty { return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted date.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) ]) + } } - return AnySequence(EmptyCollection()) -} + let rfc3339DateTimeFormatter = DateFormatter() + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd" + if rfc3339DateTimeFormatter.date (from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + return AnySequence(EmptyCollection()) +} diff --git a/Sources/Validation/datetime.swift b/Sources/Validation/datetime.swift index e1b7d68..45250d6 100644 --- a/Sources/Validation/datetime.swift +++ b/Sources/Validation/datetime.swift @@ -1,46 +1,46 @@ import Foundation func validateDateTime(_ context: Context, _ value: Any) -> AnySequence { - if let date = value as? String { - if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}", options: .caseInsensitive) { - let range = NSRange(location: 0, length: date.utf16.count) - let result = regularExpression.matches(in: date, options: [], range: range) - if result.isEmpty { - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted date.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) - } - } - - let rfc3339DateTimeFormatter = DateFormatter() - - rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - - rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - - rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd't'HH:mm:ss.SSS'z'" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - + if let date = value as? String { + if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}", options: .caseInsensitive) { + let range = NSRange(location: 0, length: date.utf16.count) + let result = regularExpression.matches(in: date, options: [], range: range) + if result.isEmpty { return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted date-time.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) ]) + } } - return AnySequence(EmptyCollection()) + let rfc3339DateTimeFormatter = DateFormatter() + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd't'HH:mm:ss.SSS'z'" + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date-time.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + + return AnySequence(EmptyCollection()) } diff --git a/Sources/Validation/time.swift b/Sources/Validation/time.swift index 1f0f98f..decb641 100644 --- a/Sources/Validation/time.swift +++ b/Sources/Validation/time.swift @@ -1,22 +1,22 @@ import Foundation func validateTime(_ context: Context, _ value: Any) -> AnySequence { - if let date = value as? String { - let rfc3339DateTimeFormatter = DateFormatter() - rfc3339DateTimeFormatter.dateFormat = "HH:mm:ss.SSSZZZZZ" + if let date = value as? String { + let rfc3339DateTimeFormatter = DateFormatter() + rfc3339DateTimeFormatter.dateFormat = "HH:mm:ss.SSSZZZZZ" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted time.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) } - return AnySequence(EmptyCollection()) + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted time.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + + return AnySequence(EmptyCollection()) } From 0fb89291787674ce0455ac6993676ce9884e5c29 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 21 Apr 2021 08:27:23 +0100 Subject: [PATCH 12/16] Apply patch from @kylef --- Tests/JSONSchemaTests/JSONSchemaCases.swift | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Tests/JSONSchemaTests/JSONSchemaCases.swift b/Tests/JSONSchemaTests/JSONSchemaCases.swift index e4ac246..67e1dc8 100644 --- a/Tests/JSONSchemaTests/JSONSchemaCases.swift +++ b/Tests/JSONSchemaTests/JSONSchemaCases.swift @@ -117,7 +117,6 @@ class JSONSchemaCases: XCTestCase { "infinite-loop-detection.json", // optional formats - "date-time.json", "email.json", "hostname.json", "uri-reference.json", @@ -137,8 +136,6 @@ class JSONSchemaCases: XCTestCase { "infinite-loop-detection.json", // optional, format - "date-time.json", - "date.json", "email.json", "hostname.json", "idn-email.json", @@ -146,7 +143,6 @@ class JSONSchemaCases: XCTestCase { "iri-reference.json", "iri.json", "relative-json-pointer.json", - "time.json", "uri-reference.json", "uri-template.json", ] + additionalExclusions) @@ -173,8 +169,6 @@ class JSONSchemaCases: XCTestCase { // optional, format "format.json", - "date-time.json", - "date.json", "duration.json", "email.json", "hostname.json", @@ -183,7 +177,6 @@ class JSONSchemaCases: XCTestCase { "iri-reference.json", "iri.json", "relative-json-pointer.json", - "time.json", "uri-reference.json", "uri-template.json", ] + additionalExclusions) @@ -212,8 +205,6 @@ class JSONSchemaCases: XCTestCase { // optional, format "format.json", - "date-time.json", - "date.json", "duration.json", "email.json", "hostname.json", @@ -222,7 +213,6 @@ class JSONSchemaCases: XCTestCase { "iri-reference.json", "iri.json", "relative-json-pointer.json", - "time.json", "uri-reference.json", "uri-template.json", ] + additionalExclusions) @@ -245,7 +235,7 @@ class JSONSchemaCases: XCTestCase { return cases.filter { if let schema = $0.schema as? [String: Any] { let format = schema["format"] as! String - return !["date-time", "email", "hostname"].contains(format) + return !["email", "hostname"].contains(format) } return true From 29e2b15e92bcb474b60b91c8115b0c1186bdf14f Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 21 Apr 2021 08:30:22 +0100 Subject: [PATCH 13/16] Move date validator to format.swift --- Sources/Validation/date.swift | 36 ----------------------------------- Sources/format.swift | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 36 deletions(-) delete mode 100644 Sources/Validation/date.swift diff --git a/Sources/Validation/date.swift b/Sources/Validation/date.swift deleted file mode 100644 index 989745a..0000000 --- a/Sources/Validation/date.swift +++ /dev/null @@ -1,36 +0,0 @@ -import Foundation - -func validateDate(_ context: Context, _ value: Any) -> AnySequence { - if let date = value as? String { - if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}$", options: []) { - let range = NSRange(location: 0, length: date.utf16.count) - let result = regularExpression.matches(in: date, options: [], range: range) - if result.isEmpty { - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted date.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) - } - } - - let rfc3339DateTimeFormatter = DateFormatter() - - rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd" - if rfc3339DateTimeFormatter.date (from: date) != nil { - return AnySequence(EmptyCollection()) - } - - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted date.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) - } - - return AnySequence(EmptyCollection()) -} diff --git a/Sources/format.swift b/Sources/format.swift index 44cf7a1..cb890fa 100644 --- a/Sources/format.swift +++ b/Sources/format.swift @@ -161,3 +161,38 @@ func validateJSONPointer(_ context: Context, _ value: Any) -> AnySequence AnySequence { + if let date = value as? String { + if let regularExpression = try? NSRegularExpression(pattern: "^\\d{4}-\\d{2}-\\d{2}$", options: []) { + let range = NSRange(location: 0, length: date.utf16.count) + let result = regularExpression.matches(in: date, options: [], range: range) + if result.isEmpty { + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + } + + let rfc3339DateTimeFormatter = DateFormatter() + + rfc3339DateTimeFormatter.dateFormat = "yyyy-MM-dd" + if rfc3339DateTimeFormatter.date (from: date) != nil { + return AnySequence(EmptyCollection()) + } + + return AnySequence([ + ValidationError( + "'\(date)' is not a valid RFC 3339 formatted date.", + instanceLocation: context.instanceLocation, + keywordLocation: context.keywordLocation + ) + ]) + } + + return AnySequence(EmptyCollection()) +} From 4637ac1cf57745c29003738f36e1b6c232fbd1a6 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 21 Apr 2021 08:40:15 +0100 Subject: [PATCH 14/16] Add test case for time with timezone + without fraction seconds, and update time validator --- Sources/Validation/time.swift | 7 ++++++- Tests/JSONSchemaTests/Validation/TestTime.swift | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Tests/JSONSchemaTests/Validation/TestTime.swift diff --git a/Sources/Validation/time.swift b/Sources/Validation/time.swift index decb641..6a9bc7a 100644 --- a/Sources/Validation/time.swift +++ b/Sources/Validation/time.swift @@ -3,12 +3,17 @@ import Foundation func validateTime(_ context: Context, _ value: Any) -> AnySequence { if let date = value as? String { let rfc3339DateTimeFormatter = DateFormatter() - rfc3339DateTimeFormatter.dateFormat = "HH:mm:ss.SSSZZZZZ" + rfc3339DateTimeFormatter.dateFormat = "HH:mm:ss.SSSZZZZZ" if rfc3339DateTimeFormatter.date(from: date) != nil { return AnySequence(EmptyCollection()) } + rfc3339DateTimeFormatter.dateFormat = "HH:mm:ssZZZZZ" + if rfc3339DateTimeFormatter.date(from: date) != nil { + return AnySequence(EmptyCollection()) + } + return AnySequence([ ValidationError( "'\(date)' is not a valid RFC 3339 formatted time.", diff --git a/Tests/JSONSchemaTests/Validation/TestTime.swift b/Tests/JSONSchemaTests/Validation/TestTime.swift new file mode 100644 index 0000000..1817cbe --- /dev/null +++ b/Tests/JSONSchemaTests/Validation/TestTime.swift @@ -0,0 +1,16 @@ +import XCTest +@testable import JSONSchema + + +class TimeFormatTests: XCTestCase { + func testTimeWithoutSecondFraction() throws { + let schema: [String: Any] = [ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "time", + ] + + let result = try validate("23:59:50Z", schema: schema) + + XCTAssertTrue(result.valid) + } +} From e31ef51a050bf9a66c0833fd7ac51d4e9f4b8960 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Tue, 4 May 2021 09:05:45 +0100 Subject: [PATCH 15/16] Remove duplicate formats keys --- Sources/Draft201909Validator.swift | 2 -- Sources/Draft202012Validator.swift | 2 -- Sources/Draft7Validator.swift | 2 -- 3 files changed, 6 deletions(-) diff --git a/Sources/Draft201909Validator.swift b/Sources/Draft201909Validator.swift index 1c8d40f..0d2df86 100644 --- a/Sources/Draft201909Validator.swift +++ b/Sources/Draft201909Validator.swift @@ -59,8 +59,6 @@ public class Draft201909Validator: Validator { "ipv6": validateIPv6, "uri": validateURI, "date-time": validateDateTime, - "date": validateDate, - "time": validateTime, "uuid": validateUUID, "regex": validateRegex, "json-pointer": validateJSONPointer, diff --git a/Sources/Draft202012Validator.swift b/Sources/Draft202012Validator.swift index 5d627c4..21f72f4 100644 --- a/Sources/Draft202012Validator.swift +++ b/Sources/Draft202012Validator.swift @@ -57,13 +57,11 @@ public class Draft202012Validator: Validator { let formats: [String: (Context, String) -> (AnySequence)] = [ "date-time": validateDateTime, - "date": validateDate, "ipv4": validateIPv4, "ipv6": validateIPv6, "uri": validateURI, "uuid": validateUUID, "regex": validateRegex, - "time": validateTime, "json-pointer": validateJSONPointer, "duration": validateDuration, "time": validateTime, diff --git a/Sources/Draft7Validator.swift b/Sources/Draft7Validator.swift index c06d668..071f28d 100644 --- a/Sources/Draft7Validator.swift +++ b/Sources/Draft7Validator.swift @@ -49,8 +49,6 @@ public class Draft7Validator: Validator { "ipv6": validateIPv6, "uri": validateURI, "date-time": validateDateTime, - "date": validateDate, - "time": validateTime, "json-pointer": validateJSONPointer, "regex": validateRegex, "time": validateTime, From cdb44c4b7fe4bb63b6976432bf53ab37584c71f1 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Wed, 5 May 2021 11:22:06 +0100 Subject: [PATCH 16/16] Remove time.swift from Validation folder --- Sources/Validation/time.swift | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 Sources/Validation/time.swift diff --git a/Sources/Validation/time.swift b/Sources/Validation/time.swift deleted file mode 100644 index 6a9bc7a..0000000 --- a/Sources/Validation/time.swift +++ /dev/null @@ -1,27 +0,0 @@ -import Foundation - -func validateTime(_ context: Context, _ value: Any) -> AnySequence { - if let date = value as? String { - let rfc3339DateTimeFormatter = DateFormatter() - - rfc3339DateTimeFormatter.dateFormat = "HH:mm:ss.SSSZZZZZ" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - - rfc3339DateTimeFormatter.dateFormat = "HH:mm:ssZZZZZ" - if rfc3339DateTimeFormatter.date(from: date) != nil { - return AnySequence(EmptyCollection()) - } - - return AnySequence([ - ValidationError( - "'\(date)' is not a valid RFC 3339 formatted time.", - instanceLocation: context.instanceLocation, - keywordLocation: context.keywordLocation - ) - ]) - } - - return AnySequence(EmptyCollection()) -}