Is it possible to have schema validation of path p...
# http4k
m
Is it possible to have schema validation of path parameters in a contract? I have tried
Copy code
routes += "/foo" / Path.regex("[0-9a-fA-F]{64}").of("bar", "Hex encoded value") meta { /* ... */ }
but I can't get it to match anything, and no corresponding schema is included in the generated OpenAPI JSON doc.
Ah, it seems like I need to wrap the regex with
()
.
a
Makes sense. I was confused too. An alternative is to use a values4k class with regex validation. Values4k is a third-party lib, but http4k has built-in support for it. For example:
Copy code
class UserCode private constructor(value: String) : StringValue(value) {
    companion object : StringValueFactory<UserCode>(::UserCode, "\\d{6}".regex)
}
and then make a lens with
Path.value(UserCode).of("user_code")