Hello :wave:, I am looking into the contract spec ...
# http4k
r
Hello 👋, I am looking into the contract spec and I was wondering if there is a way to specify the min/max length of a string parameter field using the contracts? https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#items-object-examples
d
Not currently, as we generate the entire thing from code examples and not annotations, so the format based parts of the contract are not representable. You can enforce the contract in the code though to ensure adherence to the desired spec of length/format - use the Lens system to enforce it for headers and queries through map() calls For body elements, you can write simple wrapper data class types to enforce the contract and add them as custom mappings into your Jackson config. For.both of these you will at least get the safety of parsing the input correctly or blowing up with a 400.
r
Hmm not sure if I follow, if there an example or a link to one?
d
There's a guide to mapping lenses in the core module docs. Have a look and come back if still stuck 🙃 . https://www.http4k.org/guide/modules/core/#typesafe-parameter-destructuringconstruction-of-http-messages-with-lenses
r
Thanks David!
👍 1