diff --git a/Sources/OpenAPIKit/Validator/Validator.swift b/Sources/OpenAPIKit/Validator/Validator.swift index 5ecab2ee2..49299c5e1 100644 --- a/Sources/OpenAPIKit/Validator/Validator.swift +++ b/Sources/OpenAPIKit/Validator/Validator.swift @@ -94,7 +94,7 @@ extension OpenAPI.Document { /// You can add validations to the validator using the /// `validating()` instance methods. /// -/// Builtin validations can be removed selectively using the +/// Builtin validations can be removed selectively using the /// `withoutValidating()` instance methods. /// /// There are a few default validations that ship with OpenAPIKit but @@ -234,14 +234,15 @@ public final class Validator { /// Add a validation to be performed. @discardableResult - public func validating(_ validation: Validation) -> Self { + public func validating(_ validation: Validation) -> Self { customValidations.append(AnyValidation(validation)) return self } /// Add one or more builtin validations to be performed. + @_semantics("optimize.no.crossmodule") @discardableResult - public func validating(_ validations: repeat KeyPath>) -> Self { + public func validating(_ validations: repeat KeyPath>) -> Self { for validationPath in repeat each validations { customValidations.append(AnyValidation(BuiltinValidation.self[keyPath: validationPath])) } @@ -249,8 +250,9 @@ public final class Validator { } /// Remove a builtin validation. + @_semantics("optimize.no.crossmodule") @discardableResult - public func withoutValidating(_ validations: repeat KeyPath>) -> Self { + public func withoutValidating(_ validations: repeat KeyPath>) -> Self { for validationPath in repeat each validations { nonReferenceDefaultValidations.removeAll { $0.description == BuiltinValidation.self[keyPath: validationPath].description } referenceDefaultValidations.removeAll { $0.description == BuiltinValidation.self[keyPath: validationPath].description } @@ -267,7 +269,7 @@ public final class Validator { /// `ValidationError` is a good general purpose error for this use-case. /// @discardableResult - public func validating( + public func validating( _ validate: @escaping (ValidationContext) -> [ValidationError] ) -> Self { return validating(Validation(check: validate, when: { _ in true })) @@ -282,7 +284,7 @@ public final class Validator { /// - predicate: A function returning `true` if this validator /// should run against the given value. /// - public func validating( + public func validating( _ validate: @escaping (ValidationContext) -> [ValidationError], when predicate: @escaping (ValidationContext) -> Bool ) -> Self { @@ -297,7 +299,7 @@ public final class Validator { /// - validate: The function called to assert a condition. The function should return `false` /// if the validity check has failed or `true` if everything is valid. @discardableResult - public func validating( + public func validating( _ description: String, check validate: @escaping (ValidationContext) -> Bool ) -> Self { @@ -317,7 +319,7 @@ public final class Validator { /// if the validity check has failed or `true` if everything is valid. /// - predicate: A condition that must be met for this validation to be applied. @discardableResult - public func validating( + public func validating( _ description: String, check validate: @escaping (ValidationContext) -> Bool, when predicate: @escaping (ValidationContext) -> Bool