Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naming parameters in endpoint path #611

Open
pir2o61 opened this issue Aug 11, 2024 · 0 comments
Open

Naming parameters in endpoint path #611

pir2o61 opened this issue Aug 11, 2024 · 0 comments

Comments

@pir2o61
Copy link

pir2o61 commented Aug 11, 2024

It seems that there is no way to name parameters in path (mainly for use in Swagger).
Something like {petId:%i} in https://github.com/hvester/EndpointBuilder will be very nice.
image

One way that it can be done is via changing convertToRouteTemplate function in EndpointRouting. Something like below should be enough:

            | '%' :: c :: tail ->
                let (placeholderName, placeholderTemplate), newTail = 
                    match tail with
                    | ':' :: stail ->
                        let splitIndex = stail |> List.tryFindIndex (fun c -> c = '/')
                        match splitIndex with
                        | Some splitIndex ->
                            let name , newTail = 
                                stail 
                                |> List.splitAt splitIndex
                            getConstraint i c (Some (System.String.Concat(Array.ofList(name)))), newTail
                        | None -> 
                            getConstraint i c (Some (System.String.Concat(Array.ofList(stail)))), []
                    | _ ->
                        getConstraint i c None, tail
                let template, mappings = convert (i + 1) newTail
                placeholderTemplate + template, (placeholderName, c) :: mappings

where getConstraint is changed like this

    let private getConstraint (i : int) (c : char) (name : string option) =
        let name = Option.defaultValue (sprintf "%c%i" c i) name
  1. Do we want this feature?
  2. On what scope it should work? (what names do we allow, do we want to have it in format %c:name. `name:%c' or different
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant