From 27bf4d2463777c73b1fb60c045f3fe63cac9c0dd Mon Sep 17 00:00:00 2001 From: Lucas Teles Date: Tue, 26 Dec 2023 12:54:44 -0300 Subject: [PATCH] minor: better filter support --- BasicApi/Program.fs | 2 +- FSharp.MinimalApi/Builder/Builders.fs | 2 +- FSharp.MinimalApi/Builder/EndpointsBuilder.fs | 9 +++++++-- GitVersion.yml | 1 - README.md | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/BasicApi/Program.fs b/BasicApi/Program.fs index a2e8413..0ccdaca 100644 --- a/BasicApi/Program.fs +++ b/BasicApi/Program.fs @@ -108,7 +108,7 @@ let routes = | None -> return !! NotFound() }) - routeGroup "profile" { + withGroup "profile" { allowAnonymous post diff --git a/FSharp.MinimalApi/Builder/Builders.fs b/FSharp.MinimalApi/Builder/Builders.fs index e15fa80..905cd37 100644 --- a/FSharp.MinimalApi/Builder/Builders.fs +++ b/FSharp.MinimalApi/Builder/Builders.fs @@ -7,4 +7,4 @@ let inline private implicit (x: ^a) : ^b = let inline (!!) v = implicit v let endpoints = EndpointsBuilder() -let routeGroup groupName = EndpointsBuilder groupName +let withGroup groupName = EndpointsBuilder groupName diff --git a/FSharp.MinimalApi/Builder/EndpointsBuilder.fs b/FSharp.MinimalApi/Builder/EndpointsBuilder.fs index 2a4c28d..67e55f7 100644 --- a/FSharp.MinimalApi/Builder/EndpointsBuilder.fs +++ b/FSharp.MinimalApi/Builder/EndpointsBuilder.fs @@ -117,11 +117,16 @@ type EndpointsBuilder(?groupName: string) = { state with MapFn = state.MapFn >> (fun e -> e.RequireAuthorization(policy)) } - [] - member _.AddFilter<'f when 'f :> IEndpointFilter>(state) = + [] + member _.Filter<'args, 'f when 'f :> IEndpointFilter>(state, ctor: 'args -> 'f) = { state with MapFn = state.MapFn >> (fun e -> e.AddEndpointFilter<'f>()) } + [] + member _.Filter<'f when 'f :> IEndpointFilter>(state, filter: 'f) = + { state with + MapFn = state.MapFn >> (fun e -> e.AddEndpointFilter(filter)) } + [] member _.Filter ( diff --git a/GitVersion.yml b/GitVersion.yml index 6bbbac8..d1301e2 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -8,6 +8,5 @@ no-bump-message: "^(none|skip):" branches: master: - tag: beta is-mainline: true source-branches: [] diff --git a/README.md b/README.md index 3f349fd..f253b3c 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ let routes = }) // group mappping - routeGroup "profile" { + withGroup "profile" { allowAnonymous post