From e453a6f07ca8a13b6b9f800185f93384da94f996 Mon Sep 17 00:00:00 2001 From: Patrick Stevens <3138005+Smaug123@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:43:45 +0000 Subject: [PATCH] Allow general expressions in GET attribute arg (#81) --- ConsumePlugin/GeneratedRestClient.fs | 2 +- ConsumePlugin/RestApiExample.fs | 2 +- WoofWare.Myriad.Plugins/HttpClientGenerator.fs | 16 ++++++---------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/ConsumePlugin/GeneratedRestClient.fs b/ConsumePlugin/GeneratedRestClient.fs index 0ba6fb9..994578c 100644 --- a/ConsumePlugin/GeneratedRestClient.fs +++ b/ConsumePlugin/GeneratedRestClient.fs @@ -32,7 +32,7 @@ module PureGymApi = (match client.BaseAddress with | null -> System.Uri "https://whatnot.com" | v -> v), - System.Uri ("v1/gyms/", System.UriKind.Relative) + System.Uri (("v1/gyms/"), System.UriKind.Relative) ) let httpMessage = diff --git a/ConsumePlugin/RestApiExample.fs b/ConsumePlugin/RestApiExample.fs index 6a62c46..c9c6582 100644 --- a/ConsumePlugin/RestApiExample.fs +++ b/ConsumePlugin/RestApiExample.fs @@ -11,7 +11,7 @@ open RestEase [] [] type IPureGymApi = - [] + [] abstract GetGyms : ?ct : CancellationToken -> Task [] diff --git a/WoofWare.Myriad.Plugins/HttpClientGenerator.fs b/WoofWare.Myriad.Plugins/HttpClientGenerator.fs index 17ebd55..a2f3a69 100644 --- a/WoofWare.Myriad.Plugins/HttpClientGenerator.fs +++ b/WoofWare.Myriad.Plugins/HttpClientGenerator.fs @@ -54,8 +54,8 @@ module internal HttpClientGenerator = { /// E.g. HttpMethod.Get HttpMethod : HttpMethod - /// E.g. "v1/gyms/{gym_id}/attendance" - UrlTemplate : string + /// E.g. SynExpr.Const "v1/gyms/{gym_id}/attendance" + UrlTemplate : SynExpr TaskReturnType : SynType Args : Parameter list Identifier : Ident @@ -76,8 +76,8 @@ module internal HttpClientGenerator = elif m = HttpMethod.Trace then "Trace" else failwith $"Unrecognised method: %+A{m}" - /// E.g. converts `[]` to (HttpMethod.Get, "blah") - let extractHttpInformation (attrs : SynAttribute list) : HttpMethod * string = + /// E.g. converts `[]` to (HttpMethod.Get, SynExpr.Const "blah") + let extractHttpInformation (attrs : SynAttribute list) : HttpMethod * SynExpr = let matchingAttrs = attrs |> List.choose (fun attr -> @@ -118,11 +118,7 @@ module internal HttpClientGenerator = ) match matchingAttrs with - | [ (meth, arg) ] -> - match arg with - | SynExpr.Const (SynConst.String (text, SynStringKind.Regular, _), _) -> meth, text - | arg -> - failwith $"Unrecognised AST member in attribute argument. Only regular strings are supported: %+A{arg}" + | [ (meth, arg) ] -> meth, arg | [] -> failwith "Required exactly one recognised RestEase attribute on member, but got none" | matchingAttrs -> failwith $"Required exactly one recognised RestEase attribute on member, but got %i{matchingAttrs.Length}" @@ -229,7 +225,7 @@ module internal HttpClientGenerator = ) let requestUriTrailer = - (SynExpr.CreateConstString info.UrlTemplate, info.Args) + (info.UrlTemplate, info.Args) ||> List.fold (fun template arg -> (template, arg.Attributes) ||> List.fold (fun template attr ->