diff --git a/ConsumePlugin/GeneratedRestClient.fs b/ConsumePlugin/GeneratedRestClient.fs index af40ccc..3c29f51 100644 --- a/ConsumePlugin/GeneratedRestClient.fs +++ b/ConsumePlugin/GeneratedRestClient.fs @@ -117,7 +117,7 @@ module PureGymApi = } |> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct)) - member _.GetGym (gymId : int, ct : CancellationToken option) = + member _.GetGym (gym : int, ct : CancellationToken option) = async { let! ct = Async.CancellationToken @@ -127,8 +127,8 @@ module PureGymApi = | null -> System.Uri "https://whatnot.com" | v -> v), System.Uri ( - "v1/gyms/{gym_id}" - .Replace ("{gym_id}", gymId.ToString () |> System.Web.HttpUtility.UrlEncode), + "v1/gyms/{gym}" + .Replace ("{gym}", gym.ToString () |> System.Web.HttpUtility.UrlEncode), System.UriKind.Relative ) ) diff --git a/ConsumePlugin/RestApiExample.fs b/ConsumePlugin/RestApiExample.fs index ec741cd..aa6f933 100644 --- a/ConsumePlugin/RestApiExample.fs +++ b/ConsumePlugin/RestApiExample.fs @@ -20,8 +20,8 @@ type IPureGymApi = [] abstract GetMember : ?ct : CancellationToken -> Member Task - [] - abstract GetGym : [] gymId : int * ?ct : CancellationToken -> Task + [] + abstract GetGym : [] gym : int * ?ct : CancellationToken -> Task [] abstract GetMemberActivity : ?ct : CancellationToken -> Task diff --git a/WoofWare.Myriad.Plugins/HttpClientGenerator.fs b/WoofWare.Myriad.Plugins/HttpClientGenerator.fs index 510e118..24bf0d3 100644 --- a/WoofWare.Myriad.Plugins/HttpClientGenerator.fs +++ b/WoofWare.Myriad.Plugins/HttpClientGenerator.fs @@ -20,10 +20,15 @@ module internal HttpClientGenerator = open Fantomas.FCS.Text.Range open Myriad.Core.Ast + [] + type PathSpec = + | Verbatim of string + | MatchArgName + type HttpAttribute = // TODO: Format parameter to these attrs | Query of string option - | Path of string + | Path of PathSpec | Body type Parameter = @@ -230,18 +235,23 @@ module internal HttpClientGenerator = (template, arg.Attributes) ||> List.fold (fun template attr -> match attr with - | HttpAttribute.Path s -> + | HttpAttribute.Path spec -> let varName = match arg.Id with | None -> failwith "TODO: anonymous args" | Some id -> id + let substituteId = + match spec with + | PathSpec.Verbatim s -> s + | PathSpec.MatchArgName -> varName.idText + template |> SynExpr.callMethodArg "Replace" (SynExpr.CreateParenedTuple [ - SynExpr.CreateConstString ("{" + s + "}") + SynExpr.CreateConstString ("{" + substituteId + "}") SynExpr.callMethod "ToString" (SynExpr.CreateIdent varName) |> SynExpr.pipeThroughFunction ( SynExpr.CreateLongIdent ( @@ -710,7 +720,9 @@ module internal HttpClientGenerator = | "Path" | "PathAttribute" -> match attr.ArgExpr with - | SynExpr.Const (SynConst.String (s, SynStringKind.Regular, _), _) -> Some (HttpAttribute.Path s) + | SynExpr.Const (SynConst.String (s, SynStringKind.Regular, _), _) -> + Some (HttpAttribute.Path (PathSpec.Verbatim s)) + | SynExpr.Const (SynConst.Unit, _) -> Some (HttpAttribute.Path PathSpec.MatchArgName) | SynExpr.Const (a, _) -> failwith $"unrecognised constant arg to the Path attribute: %+A{a}" | _ -> None | "Body"