I have a header that needs to be passed on every single request. I’m using a
Filter
right now to validate it, but I also want to put it on the OpenAPI contract for each route. It looks like the only way for me to require that header on every route is to copy-paste the contract header checks?
✔️ 1
Nezteb
04/23/2019, 2:09 AM
oh nevermind, this is perfect!
Copy code
package org.http4k.contract
import org.http4k.core.Filter
import org.http4k.core.Method.OPTIONS
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.UNAUTHORIZED
import org.http4k.lens.Lens
import org.http4k.lens.LensFailure
/**
* Endpoint security. Provides filter to be applied to endpoints for all requests.
*/
interface Security {
val filter: Filter
}
Nezteb
04/23/2019, 2:18 AM
Copy code
class AuthSecurity(authFilter: (RequestContexts) -> Filter, contexts: RequestContexts) : Security {
override val filter = authFilter(contexts)
}