mirror of
https://github.com/Smaug123/WoofWare.Myriad
synced 2025-10-05 03:58:40 +00:00
Allow general expressions in GET attribute arg (#81)
This commit is contained in:
@@ -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 =
|
||||
|
@@ -11,7 +11,7 @@ open RestEase
|
||||
[<WoofWare.Myriad.Plugins.HttpClient>]
|
||||
[<BaseAddress "https://whatnot.com">]
|
||||
type IPureGymApi =
|
||||
[<Get "v1/gyms/">]
|
||||
[<Get("v1/gyms/")>]
|
||||
abstract GetGyms : ?ct : CancellationToken -> Task<Gym list>
|
||||
|
||||
[<Get "v1/gyms/{gym_id}/attendance">]
|
||||
|
@@ -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 `[<Get "blah">]` to (HttpMethod.Get, "blah")
|
||||
let extractHttpInformation (attrs : SynAttribute list) : HttpMethod * string =
|
||||
/// E.g. converts `[<Get "blah">]` 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 ->
|
||||
|
Reference in New Issue
Block a user