From 4901e7cdf4336ce9091915e481f749e671475782 Mon Sep 17 00:00:00 2001 From: Patrick Stevens <3138005+Smaug123@users.noreply.github.com> Date: Sat, 15 Jun 2024 21:03:59 +0100 Subject: [PATCH] Add visibility modifiers in JsonParse/Serialize (#165) --- ConsumePlugin/GeneratedJson.fs | 74 +++++++++++++++++++ ConsumePlugin/JsonRecord.fs | 22 ++++++ WoofWare.Myriad.Plugins/JsonParseGenerator.fs | 3 +- .../JsonSerializeGenerator.fs | 3 +- WoofWare.Myriad.Plugins/version.json | 11 +-- 5 files changed, 106 insertions(+), 7 deletions(-) diff --git a/ConsumePlugin/GeneratedJson.fs b/ConsumePlugin/GeneratedJson.fs index f65ac01..08f5d9f 100644 --- a/ConsumePlugin/GeneratedJson.fs +++ b/ConsumePlugin/GeneratedJson.fs @@ -4,6 +4,33 @@ //------------------------------------------------------------------------------ +namespace ConsumePlugin + +open System.Text.Json.Serialization + +/// Module containing JSON serializing methods for the InternalTypeNotExtensionSerial type +[] +module internal InternalTypeNotExtensionSerial = + /// Serialize to a JSON node + let toJsonNode (input : InternalTypeNotExtensionSerial) : System.Text.Json.Nodes.JsonNode = + let node = System.Text.Json.Nodes.JsonObject () + do node.Add ((Literals.something), System.Text.Json.Nodes.JsonValue.Create input.InternalThing2) + node :> _ +namespace ConsumePlugin + +open System.Text.Json.Serialization + +/// Module containing JSON serializing extension members for the InternalTypeExtension type +[] +module internal InternalTypeExtensionJsonSerializeExtension = + /// Extension methods for JSON parsing + type InternalTypeExtension with + + /// Serialize to a JSON node + static member toJsonNode (input : InternalTypeExtension) : System.Text.Json.Nodes.JsonNode = + let node = System.Text.Json.Nodes.JsonObject () + do node.Add ((Literals.something), System.Text.Json.Nodes.JsonValue.Create input.ExternalThing) + node :> _ namespace ConsumePlugin @@ -119,6 +146,53 @@ module JsonRecordType = } namespace ConsumePlugin +/// Module containing JSON parsing methods for the InternalTypeNotExtension type +[] +module internal InternalTypeNotExtension = + /// Parse from a JSON node. + let jsonParse (node : System.Text.Json.Nodes.JsonNode) : InternalTypeNotExtension = + let arg_0 = + (match node.[(Literals.something)] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ((Literals.something)) + ) + ) + | v -> v) + .AsValue() + .GetValue () + + { + InternalThing = arg_0 + } +namespace ConsumePlugin + +/// Module containing JSON parsing extension members for the InternalTypeExtension type +[] +module internal InternalTypeExtensionJsonParseExtension = + /// Extension methods for JSON parsing + type InternalTypeExtension with + + /// Parse from a JSON node. + static member jsonParse (node : System.Text.Json.Nodes.JsonNode) : InternalTypeExtension = + let arg_0 = + (match node.[(Literals.something)] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ((Literals.something)) + ) + ) + | v -> v) + .AsValue() + .GetValue () + + { + ExternalThing = arg_0 + } +namespace ConsumePlugin + /// Module containing JSON parsing extension members for the ToGetExtensionMethod type [] module ToGetExtensionMethodJsonParseExtension = diff --git a/ConsumePlugin/JsonRecord.fs b/ConsumePlugin/JsonRecord.fs index efe39d5..a44aa90 100644 --- a/ConsumePlugin/JsonRecord.fs +++ b/ConsumePlugin/JsonRecord.fs @@ -29,6 +29,28 @@ type JsonRecordType = F : int[] } +[] +type internal InternalTypeNotExtension = + { + [] + InternalThing : string + } + +[] +type internal InternalTypeNotExtensionSerial = + { + [] + InternalThing2 : string + } + +[] +[] +type internal InternalTypeExtension = + { + [] + ExternalThing : string + } + [] type ToGetExtensionMethod = { diff --git a/WoofWare.Myriad.Plugins/JsonParseGenerator.fs b/WoofWare.Myriad.Plugins/JsonParseGenerator.fs index 17071fc..565e431 100644 --- a/WoofWare.Myriad.Plugins/JsonParseGenerator.fs +++ b/WoofWare.Myriad.Plugins/JsonParseGenerator.fs @@ -478,7 +478,7 @@ module internal JsonParseGenerator = let (SynTypeDefn (synComponentInfo, synTypeDefnRepr, _members, _implicitCtor, _, _)) = typeDefn - let (SynComponentInfo (_attributes, _typeParams, _constraints, ident, _, _preferPostfix, _access, _)) = + let (SynComponentInfo (_attributes, _typeParams, _constraints, ident, _, _preferPostfix, access, _)) = synComponentInfo let attributes = @@ -517,6 +517,7 @@ module internal JsonParseGenerator = let info = SynComponentInfo.createLong moduleName |> SynComponentInfo.withDocString xmlDoc + |> SynComponentInfo.setAccessibility access |> SynComponentInfo.addAttributes attributes let decl = diff --git a/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs b/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs index c2d50b3..d53bd3e 100644 --- a/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs +++ b/WoofWare.Myriad.Plugins/JsonSerializeGenerator.fs @@ -323,7 +323,7 @@ module internal JsonSerializeGenerator = let (SynTypeDefn (synComponentInfo, synTypeDefnRepr, _members, _implicitCtor, _, _)) = typeDefn - let (SynComponentInfo (_attributes, _typeParams, _constraints, ident, _, _preferPostfix, _access, _)) = + let (SynComponentInfo (_attributes, _typeParams, _constraints, ident, _, _preferPostfix, access, _)) = synComponentInfo let attributes = @@ -362,6 +362,7 @@ module internal JsonSerializeGenerator = let info = SynComponentInfo.createLong moduleName |> SynComponentInfo.addAttributes attributes + |> SynComponentInfo.setAccessibility access |> SynComponentInfo.withDocString xmlDoc let decls = diff --git a/WoofWare.Myriad.Plugins/version.json b/WoofWare.Myriad.Plugins/version.json index 1586a49..1271681 100644 --- a/WoofWare.Myriad.Plugins/version.json +++ b/WoofWare.Myriad.Plugins/version.json @@ -4,10 +4,11 @@ "^refs/heads/main$" ], "pathFilters": [ - ":/", - ":^WoofWare.Myriad.Plugins.Test/", - ":^WoofWare.Myriad.Plugins.Attributes/Test/", - ":^/.github/", - ":^/CHANGELOG.md" + "./", + ":/WoofWare.Myriad.Plugins.Attributes", + "^:/WoofWare.Myriad.Plugins.Attributes/WoofWare.Myriad.Plugins.Attributes.Test", + ":/global.json", + ":/README.md", + ":/Directory.Build.props" ] }