From ba31689145a5c46a3c7fdc0ed5ad4d7760684e83 Mon Sep 17 00:00:00 2001 From: Patrick Stevens <3138005+Smaug123@users.noreply.github.com> Date: Tue, 25 Jun 2024 00:04:56 +0100 Subject: [PATCH] Also allow serialising units of measure (#171) --- ConsumePlugin/GeneratedJson.fs | 22 +- ConsumePlugin/GeneratedPureGymDto.fs | 104 +++++----- ConsumePlugin/GeneratedRestClient.fs | 2 +- ConsumePlugin/GeneratedSerde.fs | 190 ++++++++++++++++-- ConsumePlugin/GeneratedVault.fs | 52 ++--- .../SerializationAndDeserialization.fs | 16 +- .../TestJsonSerialize/TestJsonSerde.fs | 33 ++- WoofWare.Myriad.Plugins/JsonParseGenerator.fs | 23 +-- .../JsonSerializeGenerator.fs | 1 + WoofWare.Myriad.Plugins/Primitives.fs | 2 + WoofWare.Myriad.Plugins/SynExpr/SynType.fs | 13 +- 11 files changed, 330 insertions(+), 128 deletions(-) diff --git a/ConsumePlugin/GeneratedJson.fs b/ConsumePlugin/GeneratedJson.fs index 08f5d9f..daf9186 100644 --- a/ConsumePlugin/GeneratedJson.fs +++ b/ConsumePlugin/GeneratedJson.fs @@ -49,7 +49,7 @@ module InnerType = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { Thing = arg_0 @@ -71,7 +71,7 @@ module JsonRecordType = ) | v -> v) .AsArray () - |> Seq.map (fun elt -> elt.AsValue().GetValue ()) + |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> Array.ofSeq let arg_4 = @@ -84,7 +84,7 @@ module JsonRecordType = ) | v -> v) .AsArray () - |> Seq.map (fun elt -> elt.AsValue().GetValue ()) + |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> Array.ofSeq let arg_3 = @@ -109,7 +109,7 @@ module JsonRecordType = ) | v -> v) .AsArray () - |> Seq.map (fun elt -> elt.AsValue().GetValue ()) + |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> List.ofSeq let arg_1 = @@ -122,7 +122,7 @@ module JsonRecordType = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["a"] with @@ -134,7 +134,7 @@ module JsonRecordType = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { A = arg_0 @@ -161,7 +161,7 @@ module internal InternalTypeNotExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { InternalThing = arg_0 @@ -186,7 +186,7 @@ module internal InternalTypeExtensionJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { ExternalThing = arg_0 @@ -345,7 +345,7 @@ module ToGetExtensionMethodJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_7 = (match node.["hotel"] with @@ -417,7 +417,7 @@ module ToGetExtensionMethodJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_1 = (match node.["bravo"] with @@ -442,7 +442,7 @@ module ToGetExtensionMethodJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { Alpha = arg_0 diff --git a/ConsumePlugin/GeneratedPureGymDto.fs b/ConsumePlugin/GeneratedPureGymDto.fs index b9931c4..8280460 100644 --- a/ConsumePlugin/GeneratedPureGymDto.fs +++ b/ConsumePlugin/GeneratedPureGymDto.fs @@ -55,7 +55,7 @@ module GymOpeningHours = ) | v -> v) .AsArray () - |> Seq.map (fun elt -> elt.AsValue().GetValue ()) + |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> List.ofSeq let arg_0 = @@ -68,7 +68,7 @@ module GymOpeningHours = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { IsAlwaysOpen = arg_0 @@ -91,7 +91,7 @@ module GymAccessOptions = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["pinAccess"] with @@ -103,7 +103,7 @@ module GymAccessOptions = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { PinAccess = arg_0 @@ -127,7 +127,7 @@ module GymLocation = ) | v -> v) .AsValue() - .GetValue () + .GetValue () 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 () + .GetValue () 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 () + .GetValue () let arg_4 = match node.["county"] with | null -> None - | v -> v.AsValue().GetValue () |> Some + | v -> v.AsValue().GetValue () |> Some let arg_3 = (match node.["town"] with @@ -221,17 +221,17 @@ module GymAddress = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_2 = match node.["addressLine3"] with | null -> None - | v -> v.AsValue().GetValue () |> Some + | v -> v.AsValue().GetValue () |> Some let arg_1 = match node.["addressLine2"] with | null -> None - | v -> v.AsValue().GetValue () |> Some + | v -> v.AsValue().GetValue () |> Some let arg_0 = (match node.["addressLine1"] with @@ -243,7 +243,7 @@ module GymAddress = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { AddressLine1 = arg_0 @@ -270,7 +270,7 @@ module Gym = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_9 = (match node.["timeZone"] with @@ -282,7 +282,7 @@ module Gym = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_8 = GymLocation.jsonParse ( @@ -330,7 +330,7 @@ module Gym = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_4 = (match node.["phoneNumber"] with @@ -342,7 +342,7 @@ module Gym = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_3 = GymAddress.jsonParse ( @@ -366,7 +366,7 @@ module Gym = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_1 = (match node.["id"] with @@ -378,7 +378,7 @@ module Gym = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["name"] with @@ -390,7 +390,7 @@ module Gym = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { Name = arg_0 @@ -425,7 +425,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_13 = (match node.["suspendedReason"] with @@ -437,7 +437,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_12 = (match node.["membershipLevel"] with @@ -449,7 +449,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_11 = (match node.["membershipName"] with @@ -461,7 +461,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_10 = (match node.["postCode"] with @@ -473,7 +473,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_9 = (match node.["mobileNumber"] with @@ -485,7 +485,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_8 = (match node.["dateofBirth"] with @@ -510,7 +510,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_6 = (match node.["emailAddress"] with @@ -522,7 +522,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_5 = (match node.["homeGymName"] with @@ -534,7 +534,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_4 = (match node.["homeGymId"] with @@ -546,7 +546,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_3 = (match node.["lastName"] with @@ -558,7 +558,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_2 = (match node.["firstName"] with @@ -570,7 +570,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_1 = (match node.["compoundMemberId"] with @@ -582,7 +582,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["id"] with @@ -594,7 +594,7 @@ module MemberJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { Id = arg_0 @@ -630,7 +630,7 @@ module GymAttendance = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_7 = (match node.["lastRefreshedPeopleInClasses"] with @@ -681,12 +681,12 @@ module GymAttendance = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_3 = match node.["totalPeopleSuffix"] with | null -> None - | v -> v.AsValue().GetValue () |> Some + | v -> v.AsValue().GetValue () |> Some let arg_2 = (match node.["totalPeopleInClasses"] with @@ -698,7 +698,7 @@ module GymAttendance = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_1 = (match node.["totalPeopleInGym"] with @@ -710,7 +710,7 @@ module GymAttendance = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["description"] with @@ -722,7 +722,7 @@ module GymAttendance = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { Description = arg_0 @@ -765,7 +765,7 @@ module MemberActivityDto = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_3 = (match node.["totalClasses"] with @@ -777,7 +777,7 @@ module MemberActivityDto = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_2 = (match node.["totalVisits"] with @@ -789,7 +789,7 @@ module MemberActivityDto = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_1 = (match node.["averageDuration"] with @@ -801,7 +801,7 @@ module MemberActivityDto = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["totalDuration"] with @@ -813,7 +813,7 @@ module MemberActivityDto = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { TotalDuration = arg_0 @@ -840,7 +840,7 @@ module SessionsAggregate = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_1 = (match node.["Visits"] with @@ -852,7 +852,7 @@ module SessionsAggregate = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["Activities"] with @@ -864,7 +864,7 @@ module SessionsAggregate = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { Activities = arg_0 @@ -888,7 +888,7 @@ module VisitGym = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_1 = (match node.["Name"] with @@ -900,7 +900,7 @@ module VisitGym = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["Id"] with @@ -912,7 +912,7 @@ module VisitGym = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { Id = arg_0 @@ -948,7 +948,7 @@ module Visit = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_1 = (match node.["StartTime"] with @@ -973,7 +973,7 @@ module Visit = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { IsDurationEstimated = arg_0 diff --git a/ConsumePlugin/GeneratedRestClient.fs b/ConsumePlugin/GeneratedRestClient.fs index 85d5ce9..5d79278 100644 --- a/ConsumePlugin/GeneratedRestClient.fs +++ b/ConsumePlugin/GeneratedRestClient.fs @@ -302,7 +302,7 @@ module PureGymApi = v.AsObject () |> Seq.map (fun kvp -> let key = (kvp.Key) - let value = (kvp.Value).AsValue().GetValue () + let value = (kvp.Value).AsValue().GetValue () key, value ) |> Map.ofSeq diff --git a/ConsumePlugin/GeneratedSerde.fs b/ConsumePlugin/GeneratedSerde.fs index 104819a..3e37072 100644 --- a/ConsumePlugin/GeneratedSerde.fs +++ b/ConsumePlugin/GeneratedSerde.fs @@ -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> input.Byte) + node.Add ("sbyte", System.Text.Json.Nodes.JsonValue.Create> input.Sbyte) + node.Add ("i", System.Text.Json.Nodes.JsonValue.Create> input.I) + node.Add ("i32", System.Text.Json.Nodes.JsonValue.Create> input.I32) + node.Add ("i64", System.Text.Json.Nodes.JsonValue.Create> input.I64) + node.Add ("u", System.Text.Json.Nodes.JsonValue.Create> input.U) + node.Add ("u32", System.Text.Json.Nodes.JsonValue.Create> input.U32) + node.Add ("u64", System.Text.Json.Nodes.JsonValue.Create> input.U64) + node.Add ("f", System.Text.Json.Nodes.JsonValue.Create> input.F) + node.Add ("f32", System.Text.Json.Nodes.JsonValue.Create> input.F32) + node.Add ("single", System.Text.Json.Nodes.JsonValue.Create> 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 () + let value = (kvp.Value).AsValue().GetValue () 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 () + |> 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 () + |> 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 () + |> 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 () + |> 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 () + |> 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 () + |> 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 () + |> 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 () + |> 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 () + |> 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 () + |> 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 () + |> 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 ()) + |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> Array.ofSeq let arg_4 = @@ -318,7 +473,7 @@ module JsonRecordTypeWithBothJsonParseExtension = ) | v -> v) .AsArray () - |> Seq.map (fun elt -> elt.AsValue().GetValue ()) + |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> Array.ofSeq let arg_3 = @@ -343,7 +498,7 @@ module JsonRecordTypeWithBothJsonParseExtension = ) | v -> v) .AsArray () - |> Seq.map (fun elt -> elt.AsValue().GetValue ()) + |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> List.ofSeq let arg_1 = @@ -356,7 +511,7 @@ module JsonRecordTypeWithBothJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["a"] with @@ -368,7 +523,7 @@ module JsonRecordTypeWithBothJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { 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 () + .GetValue () ) | "case2" -> let node = @@ -455,6 +621,6 @@ module FirstDuJsonParseExtension = ) | v -> v) .AsValue() - .GetValue () + .GetValue () ) | v -> failwith ("Unrecognised 'type' field value: " + v) diff --git a/ConsumePlugin/GeneratedVault.fs b/ConsumePlugin/GeneratedVault.fs index 24d5efa..eb0e69d 100644 --- a/ConsumePlugin/GeneratedVault.fs +++ b/ConsumePlugin/GeneratedVault.fs @@ -22,7 +22,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_9 = (match node.["orphan"] with @@ -34,7 +34,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_8 = (match node.["entity_id"] with @@ -46,7 +46,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_7 = (match node.["token_type"] with @@ -58,7 +58,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_6 = (match node.["renewable"] with @@ -70,7 +70,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_5 = (match node.["lease_duration"] with @@ -82,7 +82,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_4 = (match node.["identity_policies"] with @@ -94,7 +94,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsArray () - |> Seq.map (fun elt -> elt.AsValue().GetValue ()) + |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> List.ofSeq let arg_3 = @@ -107,7 +107,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsArray () - |> Seq.map (fun elt -> elt.AsValue().GetValue ()) + |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> List.ofSeq let arg_2 = @@ -120,7 +120,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsArray () - |> Seq.map (fun elt -> elt.AsValue().GetValue ()) + |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> List.ofSeq let arg_1 = @@ -133,7 +133,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["client_token"] with @@ -145,7 +145,7 @@ module JwtVaultAuthResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { ClientToken = arg_0 @@ -189,7 +189,7 @@ module JwtVaultResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_2 = (match node.["renewable"] with @@ -201,7 +201,7 @@ module JwtVaultResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_1 = (match node.["lease_id"] with @@ -213,7 +213,7 @@ module JwtVaultResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["request_id"] with @@ -225,7 +225,7 @@ module JwtVaultResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { RequestId = arg_0 @@ -271,7 +271,7 @@ module JwtSecretResponse = .AsObject () |> Seq.map (fun kvp -> let key = (kvp.Key) - let value = (kvp.Value).AsValue().GetValue () + let value = (kvp.Value).AsValue().GetValue () 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 () + let value = (kvp.Value).AsValue().GetValue () 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 () + let value = (kvp.Value).AsValue().GetValue () key, value ) |> readOnlyDict @@ -322,7 +322,7 @@ module JwtSecretResponse = .AsObject () |> Seq.map (fun kvp -> let key = (kvp.Key) - let value = (kvp.Value).AsValue().GetValue () + let value = (kvp.Value).AsValue().GetValue () 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 () + let value = (kvp.Value).AsValue().GetValue () 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 () + let value = (kvp.Value).AsValue().GetValue () key, value ) |> dict @@ -374,7 +374,7 @@ module JwtSecretResponse = .AsObject () |> Seq.map (fun kvp -> let key = (kvp.Key) - let value = (kvp.Value).AsValue().GetValue () + let value = (kvp.Value).AsValue().GetValue () key, value ) |> readOnlyDict @@ -389,7 +389,7 @@ module JwtSecretResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_2 = (match node.["renewable"] with @@ -401,7 +401,7 @@ module JwtSecretResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_1 = (match node.["lease_id"] with @@ -413,7 +413,7 @@ module JwtSecretResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () let arg_0 = (match node.["request_id"] with @@ -425,7 +425,7 @@ module JwtSecretResponse = ) | v -> v) .AsValue() - .GetValue () + .GetValue () { RequestId = arg_0 diff --git a/ConsumePlugin/SerializationAndDeserialization.fs b/ConsumePlugin/SerializationAndDeserialization.fs index f01db10..08be311 100644 --- a/ConsumePlugin/SerializationAndDeserialization.fs +++ b/ConsumePlugin/SerializationAndDeserialization.fs @@ -16,6 +16,9 @@ type InnerTypeWithBoth = ConcreteDict : Dictionary } +[] +type measure + [] [] type JsonRecordTypeWithBoth = @@ -25,7 +28,18 @@ type JsonRecordTypeWithBoth = C : int list D : InnerTypeWithBoth E : string array - F : int[] + Arr : int[] + Byte : byte + Sbyte : sbyte + I : int + I32 : int32 + I64 : int64 + U : uint + U32 : uint32 + U64 : uint64 + F : float + F32 : float32 + Single : single } [] diff --git a/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs b/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs index f9c0f86..d044c48 100644 --- a/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs +++ b/WoofWare.Myriad.Plugins.Test/TestJsonSerialize/TestJsonSerde.fs @@ -77,7 +77,18 @@ module TestJsonSerde = let! depth = Gen.choose (0, 2) let! d = innerGen depth let! e = Gen.arrayOf Arb.generate> - let! f = Gen.arrayOf Arb.generate + let! arr = Gen.arrayOf Arb.generate + 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)) + let! f32 = Arb.generate |> Gen.filter (fun s -> Single.IsFinite (s / 1.0f)) + let! single = Arb.generate |> Gen.filter (fun s -> Single.IsFinite (s / 1.0f)) 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 "" 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 = diff --git a/WoofWare.Myriad.Plugins/JsonParseGenerator.fs b/WoofWare.Myriad.Plugins/JsonParseGenerator.fs index d942716..01a7bd7 100644 --- a/WoofWare.Myriad.Plugins/JsonParseGenerator.fs +++ b/WoofWare.Myriad.Plugins/JsonParseGenerator.fs @@ -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 = diff --git a/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs b/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs index d53bd3e..adb5493 100644 --- a/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs +++ b/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs @@ -21,6 +21,7 @@ module internal JsonSerializeGenerator = | DateOnly | DateTime | NumberType _ + | Measure _ | PrimitiveType _ | Guid | Uri -> diff --git a/WoofWare.Myriad.Plugins/Primitives.fs b/WoofWare.Myriad.Plugins/Primitives.fs index 2bfb4e3..5d19d80 100644 --- a/WoofWare.Myriad.Plugins/Primitives.fs +++ b/WoofWare.Myriad.Plugins/Primitives.fs @@ -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)))) diff --git a/WoofWare.Myriad.Plugins/SynExpr/SynType.fs b/WoofWare.Myriad.Plugins/SynExpr/SynType.fs index 12586cd..5efbe9e 100644 --- a/WoofWare.Myriad.Plugins/SynExpr/SynType.fs +++ b/WoofWare.Myriad.Plugins/SynExpr/SynType.fs @@ -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, _,