Vapor 2 Validation Valid-Type throws "Using an Undeclared Valid Type"

I am trying to use the Vapor 2 Valid Type, but the compiler only says: "Using the undeclared Valid type."

I read: https://docs.vapor.codes/2.0/validation/package/ + https://docs.vapor.codes/2.0/validation/overview/

In my my Package.swift I defined

  • /vapor/vapor.git
  • /vapor/validation-provider.git
  • /fluent-provider.git

as dependencies.

If I try to use Valid<SomeValidator>, the compiler says: "Use an undeclared Valid type."

Using import Validationvs import VaporValidationdoesn't matter.

Does anyone have any ideas how I can get Valid to work?

Thanks for your help.

: Vapor vapor new validtest --api.

Package.swift:

import PackageDescription

let package = Package(
    name: "validtest",
    targets: [
        Target(name: "App"),
        Target(name: "Run", dependencies: ["App"]),
    ],
    dependencies: [
        .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2),
        .Package(url: "https://github.com/vapor/validation.git", majorVersion: 1),
        .Package(url: "https://github.com/vapor/validation-provider.git", majorVersion: 1),
        .Package(url: "https://github.com/vapor/fluent-provider.git", majorVersion: 1)
    ],
    exclude: [
        "Config",
        "Database",
        "Localization",
        "Public",
        "Resources",
    ]
)

Ran vapor fetch vapor xcode.

Routes.swift :

import Vapor
import FluentProvider
import Validation
// or and both imports are tested
import VaporValidation

extension Droplet {
    func setupRoutes() throws {
        get("info") { req in

            let input: Valid<OnlyAlphanumeric> = try req.data["input"].validated()

, , : " Valid".

+4
2

let input: Valid<OnlyAlphanumeric> = try req.data["input"].validated()

2

guard let input = req.data["input"]?.string else { throw SomeError }
try input.validated(by: OnlyAlphanumeric())

, ValidationError.

+2

. :

.Package(url: "https://github.com/vapor/validation.git", majorVersion: 1)

...

import Validation

...

try EmailValidator().validate(email)
0

Source: https://habr.com/ru/post/1680124/


All Articles