diff --git a/Sources/ProjectSpec/Project.swift b/Sources/ProjectSpec/Project.swift index 201cd0f8..57bdeaf2 100644 --- a/Sources/ProjectSpec/Project.swift +++ b/Sources/ProjectSpec/Project.swift @@ -170,6 +170,14 @@ extension Project { public init(basePath: Path = "", jsonDictionary: JSONDictionary) throws { self.basePath = basePath + let validKeys = Set(["name", "settings", "settingGroups", "settingPresets", "configs", "targets", "aggregateTargets", "projectReferences", "schemes", "breakpoints", "fileGroups", "configFiles", "attributes", "breakpoints", "packages", "localPackages", "options", "targetTemplates", "include", "templates", "schemeTemplates"]) + + for key in jsonDictionary.keys { + if !validKeys.contains(key) { + throw SpecValidationError(errors: [.unknownDictionaryKey(key)]) + } + } + let jsonDictionary = Project.resolveProject(jsonDictionary: jsonDictionary) name = try jsonDictionary.json(atKeyPath: "name") diff --git a/Sources/ProjectSpec/SpecValidationError.swift b/Sources/ProjectSpec/SpecValidationError.swift index 6e93de0e..cb9eac11 100644 --- a/Sources/ProjectSpec/SpecValidationError.swift +++ b/Sources/ProjectSpec/SpecValidationError.swift @@ -42,6 +42,7 @@ public struct SpecValidationError: Error, CustomStringConvertible { case multipleDefaultTestPlans case duplicateDependencies(target: String, dependencyReference: String) case invalidPluginPackageReference(plugin: String, package: String) + case unknownDictionaryKey(String) public var description: String { switch self { @@ -109,6 +110,8 @@ public struct SpecValidationError: Error, CustomStringConvertible { return "Target \(target.quoted) has the dependency \(dependencyReference.quoted) multiple times" case let .invalidPluginPackageReference(plugin, package): return "Plugin \(plugin) has invalid package reference \(package)" + case let .unknownDictionaryKey(key): + return "Unknown key \(key)" } } }