Also allow serialising units of measure (#171)

This commit is contained in:
Patrick Stevens
2024-06-25 00:04:56 +01:00
committed by GitHub
parent 85929d49d5
commit ba31689145
11 changed files with 330 additions and 128 deletions

View File

@@ -49,7 +49,7 @@ module InnerType =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
{
Thing = arg_0
@@ -71,7 +71,7 @@ module JsonRecordType =
)
| v -> v)
.AsArray ()
|> Seq.map (fun elt -> elt.AsValue().GetValue<int> ())
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.Int32> ())
|> Array.ofSeq
let arg_4 =
@@ -84,7 +84,7 @@ module JsonRecordType =
)
| v -> v)
.AsArray ()
|> Seq.map (fun elt -> elt.AsValue().GetValue<string> ())
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> Array.ofSeq
let arg_3 =
@@ -109,7 +109,7 @@ module JsonRecordType =
)
| v -> v)
.AsArray ()
|> Seq.map (fun elt -> elt.AsValue().GetValue<int> ())
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.Int32> ())
|> List.ofSeq
let arg_1 =
@@ -122,7 +122,7 @@ module JsonRecordType =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_0 =
(match node.["a"] with
@@ -134,7 +134,7 @@ module JsonRecordType =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
{
A = arg_0
@@ -161,7 +161,7 @@ module internal InternalTypeNotExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
{
InternalThing = arg_0
@@ -186,7 +186,7 @@ module internal InternalTypeExtensionJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
{
ExternalThing = arg_0
@@ -345,7 +345,7 @@ module ToGetExtensionMethodJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_7 =
(match node.["hotel"] with
@@ -417,7 +417,7 @@ module ToGetExtensionMethodJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<float> ()
.GetValue<System.Double> ()
let arg_1 =
(match node.["bravo"] with
@@ -442,7 +442,7 @@ module ToGetExtensionMethodJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
{
Alpha = arg_0

View File

@@ -55,7 +55,7 @@ module GymOpeningHours =
)
| v -> v)
.AsArray ()
|> Seq.map (fun elt -> elt.AsValue().GetValue<string> ())
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> List.ofSeq
let arg_0 =
@@ -68,7 +68,7 @@ module GymOpeningHours =
)
| v -> v)
.AsValue()
.GetValue<bool> ()
.GetValue<System.Boolean> ()
{
IsAlwaysOpen = arg_0
@@ -91,7 +91,7 @@ module GymAccessOptions =
)
| v -> v)
.AsValue()
.GetValue<bool> ()
.GetValue<System.Boolean> ()
let arg_0 =
(match node.["pinAccess"] with
@@ -103,7 +103,7 @@ module GymAccessOptions =
)
| v -> v)
.AsValue()
.GetValue<bool> ()
.GetValue<System.Boolean> ()
{
PinAccess = arg_0
@@ -127,7 +127,7 @@ module GymLocation =
)
| v -> v)
.AsValue()
.GetValue<float> ()
.GetValue<System.Double> ()
with :? System.InvalidOperationException as exc ->
if exc.Message.Contains "cannot be converted to" then
if
@@ -161,7 +161,7 @@ module GymLocation =
)
| v -> v)
.AsValue()
.GetValue<float> ()
.GetValue<System.Double> ()
with :? System.InvalidOperationException as exc ->
if exc.Message.Contains "cannot be converted to" then
if
@@ -204,12 +204,12 @@ module GymAddress =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_4 =
match node.["county"] with
| null -> None
| v -> v.AsValue().GetValue<string> () |> Some
| v -> v.AsValue().GetValue<System.String> () |> Some
let arg_3 =
(match node.["town"] with
@@ -221,17 +221,17 @@ module GymAddress =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_2 =
match node.["addressLine3"] with
| null -> None
| v -> v.AsValue().GetValue<string> () |> Some
| v -> v.AsValue().GetValue<System.String> () |> Some
let arg_1 =
match node.["addressLine2"] with
| null -> None
| v -> v.AsValue().GetValue<string> () |> Some
| v -> v.AsValue().GetValue<System.String> () |> Some
let arg_0 =
(match node.["addressLine1"] with
@@ -243,7 +243,7 @@ module GymAddress =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
{
AddressLine1 = arg_0
@@ -270,7 +270,7 @@ module Gym =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_9 =
(match node.["timeZone"] with
@@ -282,7 +282,7 @@ module Gym =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_8 =
GymLocation.jsonParse (
@@ -330,7 +330,7 @@ module Gym =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_4 =
(match node.["phoneNumber"] with
@@ -342,7 +342,7 @@ module Gym =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_3 =
GymAddress.jsonParse (
@@ -366,7 +366,7 @@ module Gym =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_1 =
(match node.["id"] with
@@ -378,7 +378,7 @@ module Gym =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_0 =
(match node.["name"] with
@@ -390,7 +390,7 @@ module Gym =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
{
Name = arg_0
@@ -425,7 +425,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_13 =
(match node.["suspendedReason"] with
@@ -437,7 +437,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_12 =
(match node.["membershipLevel"] with
@@ -449,7 +449,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_11 =
(match node.["membershipName"] with
@@ -461,7 +461,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_10 =
(match node.["postCode"] with
@@ -473,7 +473,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_9 =
(match node.["mobileNumber"] with
@@ -485,7 +485,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_8 =
(match node.["dateofBirth"] with
@@ -510,7 +510,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_6 =
(match node.["emailAddress"] with
@@ -522,7 +522,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_5 =
(match node.["homeGymName"] with
@@ -534,7 +534,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_4 =
(match node.["homeGymId"] with
@@ -546,7 +546,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_3 =
(match node.["lastName"] with
@@ -558,7 +558,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_2 =
(match node.["firstName"] with
@@ -570,7 +570,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_1 =
(match node.["compoundMemberId"] with
@@ -582,7 +582,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_0 =
(match node.["id"] with
@@ -594,7 +594,7 @@ module MemberJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
{
Id = arg_0
@@ -630,7 +630,7 @@ module GymAttendance =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_7 =
(match node.["lastRefreshedPeopleInClasses"] with
@@ -681,12 +681,12 @@ module GymAttendance =
)
| v -> v)
.AsValue()
.GetValue<bool> ()
.GetValue<System.Boolean> ()
let arg_3 =
match node.["totalPeopleSuffix"] with
| null -> None
| v -> v.AsValue().GetValue<string> () |> Some
| v -> v.AsValue().GetValue<System.String> () |> Some
let arg_2 =
(match node.["totalPeopleInClasses"] with
@@ -698,7 +698,7 @@ module GymAttendance =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_1 =
(match node.["totalPeopleInGym"] with
@@ -710,7 +710,7 @@ module GymAttendance =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_0 =
(match node.["description"] with
@@ -722,7 +722,7 @@ module GymAttendance =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
{
Description = arg_0
@@ -765,7 +765,7 @@ module MemberActivityDto =
)
| v -> v)
.AsValue()
.GetValue<bool> ()
.GetValue<System.Boolean> ()
let arg_3 =
(match node.["totalClasses"] with
@@ -777,7 +777,7 @@ module MemberActivityDto =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_2 =
(match node.["totalVisits"] with
@@ -789,7 +789,7 @@ module MemberActivityDto =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_1 =
(match node.["averageDuration"] with
@@ -801,7 +801,7 @@ module MemberActivityDto =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_0 =
(match node.["totalDuration"] with
@@ -813,7 +813,7 @@ module MemberActivityDto =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
{
TotalDuration = arg_0
@@ -840,7 +840,7 @@ module SessionsAggregate =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_1 =
(match node.["Visits"] with
@@ -852,7 +852,7 @@ module SessionsAggregate =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_0 =
(match node.["Activities"] with
@@ -864,7 +864,7 @@ module SessionsAggregate =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
{
Activities = arg_0
@@ -888,7 +888,7 @@ module VisitGym =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_1 =
(match node.["Name"] with
@@ -900,7 +900,7 @@ module VisitGym =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_0 =
(match node.["Id"] with
@@ -912,7 +912,7 @@ module VisitGym =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
{
Id = arg_0
@@ -948,7 +948,7 @@ module Visit =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_1 =
(match node.["StartTime"] with
@@ -973,7 +973,7 @@ module Visit =
)
| v -> v)
.AsValue()
.GetValue<bool> ()
.GetValue<System.Boolean> ()
{
IsDurationEstimated = arg_0

View File

@@ -302,7 +302,7 @@ module PureGymApi =
v.AsObject ()
|> Seq.map (fun kvp ->
let key = (kvp.Key)
let value = (kvp.Value).AsValue().GetValue<string> ()
let value = (kvp.Value).AsValue().GetValue<System.String> ()
key, value
)
|> Map.ofSeq

View File

@@ -136,7 +136,7 @@ module JsonRecordTypeWithBothJsonSerializeExtension =
)
node.Add (
"f",
"arr",
(fun field ->
let arr = System.Text.Json.Nodes.JsonArray ()
@@ -145,9 +145,21 @@ module JsonRecordTypeWithBothJsonSerializeExtension =
arr
)
input.F
input.Arr
)
node.Add ("byte", System.Text.Json.Nodes.JsonValue.Create<byte<measure>> input.Byte)
node.Add ("sbyte", System.Text.Json.Nodes.JsonValue.Create<sbyte<measure>> input.Sbyte)
node.Add ("i", System.Text.Json.Nodes.JsonValue.Create<int<measure>> input.I)
node.Add ("i32", System.Text.Json.Nodes.JsonValue.Create<int32<measure>> input.I32)
node.Add ("i64", System.Text.Json.Nodes.JsonValue.Create<int64<measure>> input.I64)
node.Add ("u", System.Text.Json.Nodes.JsonValue.Create<uint<measure>> input.U)
node.Add ("u32", System.Text.Json.Nodes.JsonValue.Create<uint32<measure>> input.U32)
node.Add ("u64", System.Text.Json.Nodes.JsonValue.Create<uint64<measure>> input.U64)
node.Add ("f", System.Text.Json.Nodes.JsonValue.Create<float<measure>> input.F)
node.Add ("f32", System.Text.Json.Nodes.JsonValue.Create<float32<measure>> input.F32)
node.Add ("single", System.Text.Json.Nodes.JsonValue.Create<single<measure>> input.Single)
node :> _
namespace ConsumePlugin
@@ -221,7 +233,7 @@ module InnerTypeWithBothJsonParseExtension =
.AsObject ()
|> Seq.map (fun kvp ->
let key = (kvp.Key) |> System.Uri
let value = (kvp.Value).AsValue().GetValue<bool> ()
let value = (kvp.Value).AsValue().GetValue<System.Boolean> ()
key, value
)
|> dict
@@ -295,7 +307,33 @@ module JsonRecordTypeWithBothJsonParseExtension =
/// Parse from a JSON node.
static member jsonParse (node : System.Text.Json.Nodes.JsonNode) : JsonRecordTypeWithBoth =
let arg_5 =
let arg_16 =
(match node.["single"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("single")
)
)
| v -> v)
.AsValue()
.GetValue<System.Single> ()
|> LanguagePrimitives.Float32WithMeasure
let arg_15 =
(match node.["f32"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("f32")
)
)
| v -> v)
.AsValue()
.GetValue<System.Single> ()
|> LanguagePrimitives.Float32WithMeasure
let arg_14 =
(match node.["f"] with
| null ->
raise (
@@ -303,9 +341,126 @@ module JsonRecordTypeWithBothJsonParseExtension =
sprintf "Required key '%s' not found on JSON object" ("f")
)
)
| v -> v)
.AsValue()
.GetValue<System.Double> ()
|> LanguagePrimitives.FloatWithMeasure
let arg_13 =
(match node.["u64"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("u64")
)
)
| v -> v)
.AsValue()
.GetValue<System.UInt64> ()
|> LanguagePrimitives.UInt64WithMeasure
let arg_12 =
(match node.["u32"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("u32")
)
)
| v -> v)
.AsValue()
.GetValue<System.UInt32> ()
|> LanguagePrimitives.UInt32WithMeasure
let arg_11 =
(match node.["u"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("u")
)
)
| v -> v)
.AsValue()
.GetValue<System.UInt32> ()
|> LanguagePrimitives.UInt32WithMeasure
let arg_10 =
(match node.["i64"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("i64")
)
)
| v -> v)
.AsValue()
.GetValue<System.Int64> ()
|> LanguagePrimitives.Int64WithMeasure
let arg_9 =
(match node.["i32"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("i32")
)
)
| v -> v)
.AsValue()
.GetValue<System.Int32> ()
|> LanguagePrimitives.Int32WithMeasure
let arg_8 =
(match node.["i"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("i")
)
)
| v -> v)
.AsValue()
.GetValue<System.Int32> ()
|> LanguagePrimitives.Int32WithMeasure
let arg_7 =
(match node.["sbyte"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("sbyte")
)
)
| v -> v)
.AsValue()
.GetValue<System.SByte> ()
|> LanguagePrimitives.SByteWithMeasure
let arg_6 =
(match node.["byte"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("byte")
)
)
| v -> v)
.AsValue()
.GetValue<System.Byte> ()
|> LanguagePrimitives.ByteWithMeasure
let arg_5 =
(match node.["arr"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("arr")
)
)
| v -> v)
.AsArray ()
|> Seq.map (fun elt -> elt.AsValue().GetValue<int> ())
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.Int32> ())
|> Array.ofSeq
let arg_4 =
@@ -318,7 +473,7 @@ module JsonRecordTypeWithBothJsonParseExtension =
)
| v -> v)
.AsArray ()
|> Seq.map (fun elt -> elt.AsValue().GetValue<string> ())
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> Array.ofSeq
let arg_3 =
@@ -343,7 +498,7 @@ module JsonRecordTypeWithBothJsonParseExtension =
)
| v -> v)
.AsArray ()
|> Seq.map (fun elt -> elt.AsValue().GetValue<int> ())
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.Int32> ())
|> List.ofSeq
let arg_1 =
@@ -356,7 +511,7 @@ module JsonRecordTypeWithBothJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_0 =
(match node.["a"] with
@@ -368,7 +523,7 @@ module JsonRecordTypeWithBothJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
{
A = arg_0
@@ -376,7 +531,18 @@ module JsonRecordTypeWithBothJsonParseExtension =
C = arg_2
D = arg_3
E = arg_4
F = arg_5
Arr = arg_5
Byte = arg_6
Sbyte = arg_7
I = arg_8
I32 = arg_9
I64 = arg_10
U = arg_11
U32 = arg_12
U64 = arg_13
F = arg_14
F32 = arg_15
Single = arg_16
}
namespace ConsumePlugin
@@ -422,7 +588,7 @@ module FirstDuJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
)
| "case2" ->
let node =
@@ -455,6 +621,6 @@ module FirstDuJsonParseExtension =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
)
| v -> failwith ("Unrecognised 'type' field value: " + v)

View File

@@ -22,7 +22,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_9 =
(match node.["orphan"] with
@@ -34,7 +34,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsValue()
.GetValue<bool> ()
.GetValue<System.Boolean> ()
let arg_8 =
(match node.["entity_id"] with
@@ -46,7 +46,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_7 =
(match node.["token_type"] with
@@ -58,7 +58,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_6 =
(match node.["renewable"] with
@@ -70,7 +70,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsValue()
.GetValue<bool> ()
.GetValue<System.Boolean> ()
let arg_5 =
(match node.["lease_duration"] with
@@ -82,7 +82,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_4 =
(match node.["identity_policies"] with
@@ -94,7 +94,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsArray ()
|> Seq.map (fun elt -> elt.AsValue().GetValue<string> ())
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> List.ofSeq
let arg_3 =
@@ -107,7 +107,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsArray ()
|> Seq.map (fun elt -> elt.AsValue().GetValue<string> ())
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> List.ofSeq
let arg_2 =
@@ -120,7 +120,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsArray ()
|> Seq.map (fun elt -> elt.AsValue().GetValue<string> ())
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> List.ofSeq
let arg_1 =
@@ -133,7 +133,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_0 =
(match node.["client_token"] with
@@ -145,7 +145,7 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
{
ClientToken = arg_0
@@ -189,7 +189,7 @@ module JwtVaultResponse =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_2 =
(match node.["renewable"] with
@@ -201,7 +201,7 @@ module JwtVaultResponse =
)
| v -> v)
.AsValue()
.GetValue<bool> ()
.GetValue<System.Boolean> ()
let arg_1 =
(match node.["lease_id"] with
@@ -213,7 +213,7 @@ module JwtVaultResponse =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_0 =
(match node.["request_id"] with
@@ -225,7 +225,7 @@ module JwtVaultResponse =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
{
RequestId = arg_0
@@ -271,7 +271,7 @@ module JwtSecretResponse =
.AsObject ()
|> Seq.map (fun kvp ->
let key = (kvp.Key)
let value = (kvp.Value).AsValue().GetValue<int> ()
let value = (kvp.Value).AsValue().GetValue<System.Int32> ()
key, value
)
|> Map.ofSeq
@@ -288,7 +288,7 @@ module JwtSecretResponse =
.AsObject ()
|> Seq.map (fun kvp ->
let key = (kvp.Key) |> System.Uri
let value = (kvp.Value).AsValue().GetValue<string> ()
let value = (kvp.Value).AsValue().GetValue<System.String> ()
key, value
)
|> dict
@@ -305,7 +305,7 @@ module JwtSecretResponse =
.AsObject ()
|> Seq.map (fun kvp ->
let key = (kvp.Key) |> System.Uri
let value = (kvp.Value).AsValue().GetValue<string> ()
let value = (kvp.Value).AsValue().GetValue<System.String> ()
key, value
)
|> readOnlyDict
@@ -322,7 +322,7 @@ module JwtSecretResponse =
.AsObject ()
|> Seq.map (fun kvp ->
let key = (kvp.Key)
let value = (kvp.Value).AsValue().GetValue<string> ()
let value = (kvp.Value).AsValue().GetValue<System.String> ()
key, value
)
|> Map.ofSeq
@@ -339,7 +339,7 @@ module JwtSecretResponse =
.AsObject ()
|> Seq.map (fun kvp ->
let key = (kvp.Key)
let value = (kvp.Value).AsValue().GetValue<string> ()
let value = (kvp.Value).AsValue().GetValue<System.String> ()
key, value
)
|> Seq.map System.Collections.Generic.KeyValuePair
@@ -357,7 +357,7 @@ module JwtSecretResponse =
.AsObject ()
|> Seq.map (fun kvp ->
let key = (kvp.Key)
let value = (kvp.Value).AsValue().GetValue<string> ()
let value = (kvp.Value).AsValue().GetValue<System.String> ()
key, value
)
|> dict
@@ -374,7 +374,7 @@ module JwtSecretResponse =
.AsObject ()
|> Seq.map (fun kvp ->
let key = (kvp.Key)
let value = (kvp.Value).AsValue().GetValue<string> ()
let value = (kvp.Value).AsValue().GetValue<System.String> ()
key, value
)
|> readOnlyDict
@@ -389,7 +389,7 @@ module JwtSecretResponse =
)
| v -> v)
.AsValue()
.GetValue<int> ()
.GetValue<System.Int32> ()
let arg_2 =
(match node.["renewable"] with
@@ -401,7 +401,7 @@ module JwtSecretResponse =
)
| v -> v)
.AsValue()
.GetValue<bool> ()
.GetValue<System.Boolean> ()
let arg_1 =
(match node.["lease_id"] with
@@ -413,7 +413,7 @@ module JwtSecretResponse =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
let arg_0 =
(match node.["request_id"] with
@@ -425,7 +425,7 @@ module JwtSecretResponse =
)
| v -> v)
.AsValue()
.GetValue<string> ()
.GetValue<System.String> ()
{
RequestId = arg_0

View File

@@ -16,6 +16,9 @@ type InnerTypeWithBoth =
ConcreteDict : Dictionary<string, InnerTypeWithBoth>
}
[<Measure>]
type measure
[<WoofWare.Myriad.Plugins.JsonParse true>]
[<WoofWare.Myriad.Plugins.JsonSerialize true>]
type JsonRecordTypeWithBoth =
@@ -25,7 +28,18 @@ type JsonRecordTypeWithBoth =
C : int list
D : InnerTypeWithBoth
E : string array
F : int[]
Arr : int[]
Byte : byte<measure>
Sbyte : sbyte<measure>
I : int<measure>
I32 : int32<measure>
I64 : int64<measure>
U : uint<measure>
U32 : uint32<measure>
U64 : uint64<measure>
F : float<measure>
F32 : float32<measure>
Single : single<measure>
}
[<WoofWare.Myriad.Plugins.JsonSerialize true>]

View File

@@ -77,7 +77,18 @@ module TestJsonSerde =
let! depth = Gen.choose (0, 2)
let! d = innerGen depth
let! e = Gen.arrayOf Arb.generate<NonNull<string>>
let! f = Gen.arrayOf Arb.generate<int>
let! arr = Gen.arrayOf Arb.generate<int>
let! byte = Arb.generate
let! sbyte = Arb.generate
let! i = Arb.generate
let! i32 = Arb.generate
let! i64 = Arb.generate
let! u = Arb.generate
let! u32 = Arb.generate
let! u64 = Arb.generate
let! f = Arb.generate |> Gen.filter (fun s -> Double.IsFinite (s / 1.0<measure>))
let! f32 = Arb.generate |> Gen.filter (fun s -> Single.IsFinite (s / 1.0f<measure>))
let! single = Arb.generate |> Gen.filter (fun s -> Single.IsFinite (s / 1.0f<measure>))
return
{
@@ -86,7 +97,18 @@ module TestJsonSerde =
C = c
D = d
E = e |> Array.map _.Get
Arr = arr
Byte = byte
Sbyte = sbyte
I = i
I32 = i32
I64 = i64
U = u
U32 = u32
U64 = u64
F = f
F32 = f32
Single = single
}
}
@@ -140,8 +162,7 @@ module TestJsonSerde =
}
let sanitiseRec (r : JsonRecordTypeWithBoth) : JsonRecordTypeWithBoth =
{
A = r.A
{ r with
B = if isNull r.B then "<null>" else r.B
C =
if Object.ReferenceEquals (r.C, (null : obj)) then
@@ -150,11 +171,11 @@ module TestJsonSerde =
r.C
D = sanitiseInner r.D
E = if isNull r.E then [||] else r.E
F =
if Object.ReferenceEquals (r.F, (null : obj)) then
Arr =
if Object.ReferenceEquals (r.Arr, (null : obj)) then
[||]
else
r.F
r.Arr
}
let duGen =

View File

@@ -106,14 +106,8 @@ module internal JsonParseGenerator =
]
|> SynExpr.createMatch node
/// Given e.g. "float", returns "System.Double.Parse"
let parseFunction (typeName : string) : LongIdent =
let qualified =
match Primitives.qualifyType typeName with
| Some x -> x
| None -> failwith $"Could not recognise type %s{typeName} as a primitive."
List.append qualified [ Ident.create "Parse" ]
let dotParse (typeName : LongIdent) : LongIdent =
List.append typeName [ Ident.create "Parse" ]
/// fun kvp -> let key = {key(kvp)} in let value = {value(kvp)} in (key, value))
/// The inputs will be fed with appropriate SynExprs to apply them to the `kvp.Key` and `kvp.Value` args.
@@ -144,9 +138,9 @@ module internal JsonParseGenerator =
(options : JsonParseOption)
(propertyName : SynExpr option)
(node : SynExpr)
(typeName : string)
(typeName : LongIdent)
=
let basic = asValueGetValue propertyName typeName node
let basic = asValueGetValueIdent propertyName typeName node
match options.JsonNumberHandlingArg with
| None -> basic
@@ -157,7 +151,7 @@ module internal JsonParseGenerator =
let handler =
asValueGetValue propertyName "string" node
|> SynExpr.pipeThroughFunction (SynExpr.createLongIdent' (parseFunction typeName))
|> SynExpr.pipeThroughFunction (SynExpr.createLongIdent' (typeName |> dotParse))
|> SynExpr.ifThenElse
(SynExpr.equals
option
@@ -269,13 +263,8 @@ module internal JsonParseGenerator =
|> SynExpr.paren
|> SynExpr.applyFunction (SynExpr.createLongIdent [ "System" ; "Numerics" ; "BigInteger" ; "Parse" ])
| Measure (_measure, primType) ->
let qualified =
match Primitives.qualifyType primType with
| None -> failwith $"did not recognise type %s{primType} to assign measure"
| Some t -> t
parseNumberType options propertyName node primType
|> SynExpr.pipeThroughFunction (Measure.getLanguagePrimitivesMeasure qualified)
|> SynExpr.pipeThroughFunction (Measure.getLanguagePrimitivesMeasure primType)
| _ ->
// Let's just hope that we've also got our own type annotation!
let typeName =

View File

@@ -21,6 +21,7 @@ module internal JsonSerializeGenerator =
| DateOnly
| DateTime
| NumberType _
| Measure _
| PrimitiveType _
| Guid
| Uri ->

View File

@@ -26,5 +26,7 @@ module internal Primitives =
| "uint64" -> [ "System" ; "UInt64" ] |> Some
| "char" -> [ "System" ; "Char" ] |> Some
| "decimal" -> [ "System" ; "Decimal" ] |> Some
| "string" -> [ "System" ; "String" ] |> Some
| "bool" -> [ "System" ; "Boolean" ] |> Some
| _ -> None
|> Option.map (List.map (fun i -> (Ident (i, range0))))

View File

@@ -193,11 +193,20 @@ module internal SynTypePatterns =
match fieldType with
| SynType.LongIdent ident ->
match ident.LongIdent with
| [ i ] -> [ "string" ; "float" ; "int" ; "bool" ] |> List.tryFind (fun s -> s = i.idText)
| [ i ] ->
// We won't bother with the case that the user has done e.g. `Single` (relying on `System` being open).
match Primitives.qualifyType i.idText with
| Some qualified ->
match i.idText with
| "char"
| "string" -> None
| _ -> Some qualified
| None -> None
| _ -> None
| _ -> None
let (|Measure|_|) (fieldType : SynType) : (Ident * string) option =
/// Returns the name of the measure, and the outer type.
let (|Measure|_|) (fieldType : SynType) : (Ident * LongIdent) option =
match fieldType with
| SynType.App (NumberType outer,
_,