mirror of
https://github.com/Smaug123/WoofWare.Myriad
synced 2025-10-07 04:58:41 +00:00
Accept empty Path attr (#85)
This commit is contained in:
@@ -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
|
||||
)
|
||||
)
|
||||
|
@@ -20,8 +20,8 @@ type IPureGymApi =
|
||||
[<RestEase.GetAttribute "v1/member">]
|
||||
abstract GetMember : ?ct : CancellationToken -> Member Task
|
||||
|
||||
[<RestEase.Get "v1/gyms/{gym_id}">]
|
||||
abstract GetGym : [<Path "gym_id">] gymId : int * ?ct : CancellationToken -> Task<Gym>
|
||||
[<RestEase.Get "v1/gyms/{gym}">]
|
||||
abstract GetGym : [<Path>] gym : int * ?ct : CancellationToken -> Task<Gym>
|
||||
|
||||
[<GetAttribute "v1/member/activity">]
|
||||
abstract GetMemberActivity : ?ct : CancellationToken -> Task<MemberActivityDto>
|
||||
|
@@ -20,10 +20,15 @@ module internal HttpClientGenerator =
|
||||
open Fantomas.FCS.Text.Range
|
||||
open Myriad.Core.Ast
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
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"
|
||||
|
Reference in New Issue
Block a user