Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,072 changes: 1,343 additions & 729 deletions ConsumePlugin/Generated2SwaggerGitea.fs

Large diffs are not rendered by default.

295 changes: 281 additions & 14 deletions ConsumePlugin/GeneratedRestClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -427,21 +427,31 @@ module PureGymApi =
async {
let! ct = Async.CancellationToken

let queryString =
[
[
"fromDate=" + ((fromDate.ToString "yyyy-MM-dd") |> System.Uri.EscapeDataString)
]
[ "toDate=" + ((toDate.ToString "yyyy-MM-dd") |> System.Uri.EscapeDataString) ]
]
|> List.concat
|> String.concat "&"

let uri =
System.Uri (
(match client.BaseAddress with
| null -> System.Uri "https://whatnot.com/"
| v -> v),
System.Uri (
("/v2/gymSessions/member"
+ (if "/v2/gymSessions/member".IndexOf (char 63) >= 0 then
"&"
+ (if queryString = "" then
""
else
"?")
+ "fromDate="
+ ((fromDate.ToString "yyyy-MM-dd") |> System.Uri.EscapeDataString)
+ "&toDate="
+ ((toDate.ToString "yyyy-MM-dd") |> System.Uri.EscapeDataString)),
((if "/v2/gymSessions/member".IndexOf (char 63) >= 0 then
"&"
else
"?")
+ queryString))),
System.UriKind.Relative
)
)
Expand Down Expand Up @@ -478,21 +488,31 @@ module PureGymApi =
async {
let! ct = Async.CancellationToken

let queryString =
[
[
"fromDate=" + ((fromDate.ToString "yyyy-MM-dd") |> System.Uri.EscapeDataString)
]
[ "toDate=" + ((toDate.ToString "yyyy-MM-dd") |> System.Uri.EscapeDataString) ]
]
|> List.concat
|> String.concat "&"

let uri =
System.Uri (
(match client.BaseAddress with
| null -> System.Uri "https://whatnot.com/"
| v -> v),
System.Uri (
("/v2/gymSessions/member?foo=1"
+ (if "/v2/gymSessions/member?foo=1".IndexOf (char 63) >= 0 then
"&"
+ (if queryString = "" then
""
else
"?")
+ "fromDate="
+ ((fromDate.ToString "yyyy-MM-dd") |> System.Uri.EscapeDataString)
+ "&toDate="
+ ((toDate.ToString "yyyy-MM-dd") |> System.Uri.EscapeDataString)),
((if "/v2/gymSessions/member?foo=1".IndexOf (char 63) >= 0 then
"&"
else
"?")
+ queryString))),
System.UriKind.Relative
)
)
Expand Down Expand Up @@ -1967,6 +1987,253 @@ open System.Net
open System.Net.Http
open RestEase

/// Module for constructing a REST client.
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix) ; RequireQualifiedAccess>]
module ApiWithListQuery =
/// Create a REST client.
let make (client : System.Net.Http.HttpClient) : IApiWithListQuery =
{ new IApiWithListQuery with
member _.GetWithListQuery (tags : string list, limit : int, ct : CancellationToken option) =
async {
let! ct = Async.CancellationToken

let queryString =
[
tags
|> List.map (fun queryParam ->
"tag=" + ((queryParam.ToString ()) |> System.Uri.EscapeDataString)
)
[ "limit=" + ((limit.ToString ()) |> System.Uri.EscapeDataString) ]
]
|> List.concat
|> String.concat "&"

let uri =
System.Uri (
(match client.BaseAddress with
| null -> System.Uri "https://whatnot.com/"
| v -> v),
System.Uri (
("endpoint"
+ (if queryString = "" then
""
else
((if "endpoint".IndexOf (char 63) >= 0 then "&" else "?") + queryString))),
System.UriKind.Relative
)
)

use httpMessage =
new System.Net.Http.HttpRequestMessage (
Method = System.Net.Http.HttpMethod.Get,
RequestUri = uri
)

let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask
let response = response.EnsureSuccessStatusCode ()
use response = response
let! responseString = response.Content.ReadAsStringAsync ct |> Async.AwaitTask
return responseString
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))

member _.GetWithSoleListQuery (tags : string list, ct : CancellationToken option) =
async {
let! ct = Async.CancellationToken

let queryString =
[
tags
|> List.map (fun queryParam ->
"tag=" + ((queryParam.ToString ()) |> System.Uri.EscapeDataString)
)
]
|> List.concat
|> String.concat "&"

let uri =
System.Uri (
(match client.BaseAddress with
| null -> System.Uri "https://whatnot.com/"
| v -> v),
System.Uri (
("endpoint"
+ (if queryString = "" then
""
else
((if "endpoint".IndexOf (char 63) >= 0 then "&" else "?") + queryString))),
System.UriKind.Relative
)
)

use httpMessage =
new System.Net.Http.HttpRequestMessage (
Method = System.Net.Http.HttpMethod.Get,
RequestUri = uri
)

let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask
let response = response.EnsureSuccessStatusCode ()
use response = response
let! responseString = response.Content.ReadAsStringAsync ct |> Async.AwaitTask
return responseString
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))

member _.GetWithArrayQuery (ids : int[], ct : CancellationToken option) =
async {
let! ct = Async.CancellationToken

let queryString =
[
ids
|> Seq.map (fun queryParam ->
"id=" + ((queryParam.ToString ()) |> System.Uri.EscapeDataString)
)
|> List.ofSeq
]
|> List.concat
|> String.concat "&"

let uri =
System.Uri (
(match client.BaseAddress with
| null -> System.Uri "https://whatnot.com/"
| v -> v),
System.Uri (
("endpoint"
+ (if queryString = "" then
""
else
((if "endpoint".IndexOf (char 63) >= 0 then "&" else "?") + queryString))),
System.UriKind.Relative
)
)

use httpMessage =
new System.Net.Http.HttpRequestMessage (
Method = System.Net.Http.HttpMethod.Get,
RequestUri = uri
)

let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask
let response = response.EnsureSuccessStatusCode ()
use response = response
let! responseString = response.Content.ReadAsStringAsync ct |> Async.AwaitTask
return responseString
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
}
namespace PureGym

open System
open System.Threading
open System.Threading.Tasks
open System.IO
open System.Net
open System.Net.Http
open RestEase

/// Module for constructing a REST client.
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix) ; RequireQualifiedAccess>]
module ApiShadowingGeneratedNames =
/// Create a REST client.
let make (client : System.Net.Http.HttpClient) : IApiShadowingGeneratedNames =
{ new IApiShadowingGeneratedNames with
member _.GetWithPathNamedQueryString (queryString : string, limit : int, ct : CancellationToken option) =
async {
let! ct = Async.CancellationToken

let queryString1 =
[ [ "limit=" + ((limit.ToString ()) |> System.Uri.EscapeDataString) ] ]
|> List.concat
|> String.concat "&"

let uri =
System.Uri (
(match client.BaseAddress with
| null -> System.Uri "https://whatnot.com/"
| v -> v),
System.Uri (
("endpoint/{queryString}"
.Replace ("{queryString}", queryString.ToString () |> System.Uri.EscapeDataString)
+ (if queryString1 = "" then
""
else
((if "endpoint/{queryString}".IndexOf (char 63) >= 0 then
"&"
else
"?")
+ queryString1))),
System.UriKind.Relative
)
)

use httpMessage =
new System.Net.Http.HttpRequestMessage (
Method = System.Net.Http.HttpMethod.Get,
RequestUri = uri
)

let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask
let response = response.EnsureSuccessStatusCode ()
use response = response
let! responseString = response.Content.ReadAsStringAsync ct |> Async.AwaitTask
return responseString
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))

member _.GetWithQueryNamedQueryString (queryString : string, limit : int, ct : CancellationToken option) =
async {
let! ct = Async.CancellationToken

let queryString1 =
[
[ "queryString=" + ((queryString.ToString ()) |> System.Uri.EscapeDataString) ]
[ "limit=" + ((limit.ToString ()) |> System.Uri.EscapeDataString) ]
]
|> List.concat
|> String.concat "&"

let uri =
System.Uri (
(match client.BaseAddress with
| null -> System.Uri "https://whatnot.com/"
| v -> v),
System.Uri (
("endpoint"
+ (if queryString1 = "" then
""
else
((if "endpoint".IndexOf (char 63) >= 0 then "&" else "?") + queryString1))),
System.UriKind.Relative
)
)

use httpMessage =
new System.Net.Http.HttpRequestMessage (
Method = System.Net.Http.HttpMethod.Get,
RequestUri = uri
)

let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask
let response = response.EnsureSuccessStatusCode ()
use response = response
let! responseString = response.Content.ReadAsStringAsync ct |> Async.AwaitTask
return responseString
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
}
namespace PureGym

open System
open System.Threading
open System.Threading.Tasks
open System.IO
open System.Net
open System.Net.Http
open RestEase

/// Module for constructing a REST client.
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix) ; RequireQualifiedAccess>]
module ClientWithStringBody =
Expand Down
30 changes: 30 additions & 0 deletions ConsumePlugin/RestApiExample.fs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,36 @@ type IClientWithJsonBodyOverridden =
?ct : CancellationToken ->
Task<string>

[<WoofWare.Myriad.Plugins.HttpClient>]
[<BaseAddress "https://whatnot.com">]
type IApiWithListQuery =
// A list-typed query parameter contributes one key=value pair per element.
[<Get "endpoint">]
abstract GetWithListQuery :
[<Query "tag">] tags : string list * [<Query "limit">] limit : int * ?ct : CancellationToken -> Task<string>

[<Get "endpoint">]
abstract GetWithSoleListQuery : [<Query "tag">] tags : string list * ?ct : CancellationToken -> Task<string>

[<Get "endpoint">]
abstract GetWithArrayQuery : [<Query "id">] ids : int[] * ?ct : CancellationToken -> Task<string>

[<WoofWare.Myriad.Plugins.HttpClient>]
[<BaseAddress "https://whatnot.com">]
type IApiShadowingGeneratedNames =
// The generator emits a local binding holding the serialised query string. That binding
// must not shadow a user parameter which happens to share its name.
[<Get "endpoint/{queryString}">]
abstract GetWithPathNamedQueryString :
[<Path "queryString">] queryString : string * [<Query "limit">] limit : int * ?ct : CancellationToken ->
Task<string>

// Same, but the colliding parameter is itself a query parameter.
[<Get "endpoint">]
abstract GetWithQueryNamedQueryString :
[<Query "queryString">] queryString : string * [<Query "limit">] limit : int * ?ct : CancellationToken ->
Task<string>

[<WoofWare.Myriad.Plugins.HttpClient>]
type IClientWithStringBody =
// As a POST request of a bare string body, we don't override the Content-Type.
Expand Down
Loading
Loading