mirror of
https://github.com/Smaug123/WoofWare.Myriad
synced 2025-10-05 20:18:43 +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
|
(match client.BaseAddress with
|
||||||
| null -> System.Uri "https://whatnot.com"
|
| null -> System.Uri "https://whatnot.com"
|
||||||
| v -> v),
|
| v -> v),
|
||||||
System.Uri ("v1/gyms/", System.UriKind.Relative)
|
System.Uri (("v1/gyms/"), System.UriKind.Relative)
|
||||||
)
|
)
|
||||||
|
|
||||||
let httpMessage =
|
let httpMessage =
|
||||||
|
@@ -11,7 +11,7 @@ open RestEase
|
|||||||
[<WoofWare.Myriad.Plugins.HttpClient>]
|
[<WoofWare.Myriad.Plugins.HttpClient>]
|
||||||
[<BaseAddress "https://whatnot.com">]
|
[<BaseAddress "https://whatnot.com">]
|
||||||
type IPureGymApi =
|
type IPureGymApi =
|
||||||
[<Get "v1/gyms/">]
|
[<Get("v1/gyms/")>]
|
||||||
abstract GetGyms : ?ct : CancellationToken -> Task<Gym list>
|
abstract GetGyms : ?ct : CancellationToken -> Task<Gym list>
|
||||||
|
|
||||||
[<Get "v1/gyms/{gym_id}/attendance">]
|
[<Get "v1/gyms/{gym_id}/attendance">]
|
||||||
|
@@ -54,8 +54,8 @@ module internal HttpClientGenerator =
|
|||||||
{
|
{
|
||||||
/// E.g. HttpMethod.Get
|
/// E.g. HttpMethod.Get
|
||||||
HttpMethod : HttpMethod
|
HttpMethod : HttpMethod
|
||||||
/// E.g. "v1/gyms/{gym_id}/attendance"
|
/// E.g. SynExpr.Const "v1/gyms/{gym_id}/attendance"
|
||||||
UrlTemplate : string
|
UrlTemplate : SynExpr
|
||||||
TaskReturnType : SynType
|
TaskReturnType : SynType
|
||||||
Args : Parameter list
|
Args : Parameter list
|
||||||
Identifier : Ident
|
Identifier : Ident
|
||||||
@@ -76,8 +76,8 @@ module internal HttpClientGenerator =
|
|||||||
elif m = HttpMethod.Trace then "Trace"
|
elif m = HttpMethod.Trace then "Trace"
|
||||||
else failwith $"Unrecognised method: %+A{m}"
|
else failwith $"Unrecognised method: %+A{m}"
|
||||||
|
|
||||||
/// E.g. converts `[<Get "blah">]` to (HttpMethod.Get, "blah")
|
/// E.g. converts `[<Get "blah">]` to (HttpMethod.Get, SynExpr.Const "blah")
|
||||||
let extractHttpInformation (attrs : SynAttribute list) : HttpMethod * string =
|
let extractHttpInformation (attrs : SynAttribute list) : HttpMethod * SynExpr =
|
||||||
let matchingAttrs =
|
let matchingAttrs =
|
||||||
attrs
|
attrs
|
||||||
|> List.choose (fun attr ->
|
|> List.choose (fun attr ->
|
||||||
@@ -118,11 +118,7 @@ module internal HttpClientGenerator =
|
|||||||
)
|
)
|
||||||
|
|
||||||
match matchingAttrs with
|
match matchingAttrs with
|
||||||
| [ (meth, arg) ] ->
|
| [ (meth, arg) ] -> 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}"
|
|
||||||
| [] -> failwith "Required exactly one recognised RestEase attribute on member, but got none"
|
| [] -> failwith "Required exactly one recognised RestEase attribute on member, but got none"
|
||||||
| matchingAttrs ->
|
| matchingAttrs ->
|
||||||
failwith $"Required exactly one recognised RestEase attribute on member, but got %i{matchingAttrs.Length}"
|
failwith $"Required exactly one recognised RestEase attribute on member, but got %i{matchingAttrs.Length}"
|
||||||
@@ -229,7 +225,7 @@ module internal HttpClientGenerator =
|
|||||||
)
|
)
|
||||||
|
|
||||||
let requestUriTrailer =
|
let requestUriTrailer =
|
||||||
(SynExpr.CreateConstString info.UrlTemplate, info.Args)
|
(info.UrlTemplate, info.Args)
|
||||||
||> List.fold (fun template arg ->
|
||> List.fold (fun template arg ->
|
||||||
(template, arg.Attributes)
|
(template, arg.Attributes)
|
||||||
||> List.fold (fun template attr ->
|
||> List.fold (fun template attr ->
|
||||||
|
Reference in New Issue
Block a user