Compare commits

..

1 Commits

Author SHA1 Message Date
Patrick Stevens
7930039ad1 Revert "Some fixes to nullability (#365)" (#366)
This reverts commit 8d275f0047.
2025-04-20 17:02:40 +00:00
14 changed files with 65 additions and 1697 deletions

View File

@@ -11,10 +11,6 @@
<ItemGroup>
<None Include="myriad.toml"/>
<Compile Include="JsonParseNullness.fs" />
<Compile Include="GeneratedJsonParseNullness.fs">
<MyriadFile>JsonParseNullness.fs</MyriadFile>
</Compile>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="RecordFile.fs"/>
<Compile Include="GeneratedRecord.fs">

File diff suppressed because it is too large Load Diff

View File

@@ -71,7 +71,6 @@ module JsonRecordType =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.Int32> ())
|> Array.ofSeq
@@ -85,7 +84,6 @@ module JsonRecordType =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> Array.ofSeq
@@ -111,7 +109,6 @@ module JsonRecordType =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.Int32> ())
|> List.ofSeq
@@ -204,15 +201,7 @@ module ToGetExtensionMethodJsonParseExtension =
/// Parse from a JSON node.
static member jsonParse (node : System.Text.Json.Nodes.JsonNode) : ToGetExtensionMethod =
let arg_20 =
let v = node.["whiskey"]
System.Numerics.BigInteger.Parse (
(match v with
| null -> raise (System.ArgumentNullException ())
| v -> v)
.ToJsonString ()
)
let arg_20 = System.Numerics.BigInteger.Parse (node.["whiskey"].ToJsonString ())
let arg_19 =
(match node.["victor"] with

View File

@@ -1,53 +0,0 @@
//------------------------------------------------------------------------------
// This code was generated by myriad.
// Changes to this file will be lost when the code is regenerated.
//------------------------------------------------------------------------------
namespace ConsumePlugin
/// Module containing JSON parsing methods for the InnerStruct type
[<RequireQualifiedAccess ; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module InnerStruct =
/// Parse from a JSON node.
let jsonParse (node : System.Text.Json.Nodes.JsonNode) : InnerStruct =
let arg_0 =
(match node.["a"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("a")
)
)
| v -> v)
.AsValue()
.GetValue<System.Int32> ()
{
A = arg_0
}
namespace ConsumePlugin
/// Module containing JSON parsing methods for the ArrayOfInnerStruct type
[<RequireQualifiedAccess ; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module ArrayOfInnerStruct =
/// Parse from a JSON node.
let jsonParse (node : System.Text.Json.Nodes.JsonNode) : ArrayOfInnerStruct =
let arg_0 =
(match node.["b"] with
| null ->
raise (
System.Collections.Generic.KeyNotFoundException (
sprintf "Required key '%s' not found on JSON object" ("b")
)
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> InnerStruct.jsonParse elt)
|> Array.ofSeq
{
B = arg_0
}

View File

@@ -60,7 +60,6 @@ module GymOpeningHours =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> List.ofSeq
@@ -1039,7 +1038,6 @@ module Sessions =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> Visit.jsonParse elt)
|> List.ofSeq

View File

@@ -48,16 +48,7 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return
jsonNode.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> Gym.jsonParse elt)
|> List.ofSeq
return jsonNode.AsArray () |> Seq.map (fun elt -> Gym.jsonParse elt) |> List.ofSeq
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -91,11 +82,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return GymAttendance.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -130,11 +116,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return GymAttendance.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -165,11 +146,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return Member.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -203,11 +179,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return Gym.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -238,11 +209,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return MemberActivityDto.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -273,11 +239,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return UriThing.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -333,11 +294,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return
match jsonNode with
| null -> None
@@ -390,11 +346,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return Sessions.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -436,11 +387,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return Sessions.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -932,11 +878,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return
new RestEase.Response<_> (
responseString,
@@ -973,11 +914,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return
new RestEase.Response<_> (
responseString,
@@ -1014,11 +950,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return
new RestEase.Response<_> (
responseString,
@@ -1055,11 +986,6 @@ module PureGymApi =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return
new RestEase.Response<_> (
responseString,

View File

@@ -408,7 +408,6 @@ module InnerTypeWithBothJsonParseExtension =
let value =
(kvp.Value).AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.Char> ())
|> List.ofSeq
@@ -677,7 +676,6 @@ module JsonRecordTypeWithBothJsonParseExtension =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.Int32> ())
|> Array.ofSeq
@@ -691,7 +689,6 @@ module JsonRecordTypeWithBothJsonParseExtension =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> Array.ofSeq
@@ -717,7 +714,6 @@ module JsonRecordTypeWithBothJsonParseExtension =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.Int32> ())
|> List.ofSeq

View File

@@ -94,7 +94,6 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> List.ofSeq
@@ -108,7 +107,6 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> List.ofSeq
@@ -122,7 +120,6 @@ module JwtVaultAuthResponse =
)
| v -> v)
.AsArray ()
|> Seq.cast<System.Text.Json.Nodes.JsonNode>
|> Seq.map (fun elt -> elt.AsValue().GetValue<System.String> ())
|> List.ofSeq
@@ -499,11 +496,6 @@ module VaultClient =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return JwtSecretResponse.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -540,11 +532,6 @@ module VaultClient =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return JwtVaultResponse.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -603,11 +590,6 @@ module VaultClientNonExtensionMethod =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return JwtSecretResponse.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -644,11 +626,6 @@ module VaultClientNonExtensionMethod =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return JwtVaultResponse.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -710,11 +687,6 @@ module VaultClientExtensionMethodHttpClientExtension =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return JwtSecretResponse.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
@@ -751,11 +723,6 @@ module VaultClientExtensionMethodHttpClientExtension =
System.Text.Json.Nodes.JsonNode.ParseAsync (responseStream, cancellationToken = ct)
|> Async.AwaitTask
let jsonNode =
match jsonNode with
| null -> raise (System.ArgumentNullException ())
| v -> v
return JwtVaultResponse.jsonParse jsonNode
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))

View File

@@ -1,13 +0,0 @@
namespace ConsumePlugin
[<WoofWare.Myriad.Plugins.JsonParse>]
type InnerStruct =
{
A : int
}
[<WoofWare.Myriad.Plugins.JsonParse>]
type ArrayOfInnerStruct =
{
B : InnerStruct array
}

View File

@@ -1,23 +0,0 @@
namespace WoofWare.Myriad.Plugins.Test
open System.Text.Json.Nodes
open FsUnitTyped
open NUnit.Framework
open ConsumePlugin
[<TestFixture>]
module TestJsonNullability =
[<Test>]
let ``Can consume JsonParseNullness`` () =
let options = JsonNodeOptions (PropertyNameCaseInsensitive = true)
"""{
"b": null
}"""
|> fun s -> JsonNode.Parse (s, options)
|> ArrayOfInnerStruct.jsonParse
|> shouldEqual
{
B = null
}

View File

@@ -18,7 +18,6 @@
<Compile Include="TestJsonParse\TestJsonParse.fs" />
<Compile Include="TestJsonParse\TestPureGymJson.fs" />
<Compile Include="TestJsonParse\TestExtensionMethod.fs" />
<Compile Include="TestJsonParse\TestJsonNullability.fs" />
<Compile Include="TestHttpClient\TestPureGymRestApi.fs" />
<Compile Include="TestHttpClient\TestPathParam.fs" />
<Compile Include="TestHttpClient\TestReturnTypes.fs" />

View File

@@ -356,19 +356,3 @@ module internal AstHelper =
}
)
| _ -> failwithf "Failed to get record elements for type that was: %+A" repr
let raiseIfNull (variable : Ident) : SynExpr =
SynExpr.createMatch
(SynExpr.createIdent' variable)
[
SynMatchClause.create
SynPat.createNull
(SynExpr.applyFunction
(SynExpr.createIdent "raise")
(SynExpr.paren (
SynExpr.applyFunction
(SynExpr.createLongIdent [ "System" ; "ArgumentNullException" ])
(SynExpr.CreateConst ())
)))
SynMatchClause.create (SynPat.named "v") (SynExpr.createIdent "v")
]

View File

@@ -1,5 +1,6 @@
namespace WoofWare.Myriad.Plugins
open System.IO
open System.Net.Http
open Fantomas.FCS.Syntax
open WoofWare.Whippet.Fantomas
@@ -13,6 +14,17 @@ type internal HttpClientGeneratorOutputSpec =
module internal HttpClientGenerator =
open Fantomas.FCS.Text.Range
let outputFile = FileInfo "/tmp/output.txt"
// do
// use _ = File.Create outputFile.FullName
// ()
let log (line : string) =
// use w = outputFile.AppendText ()
// w.WriteLine line
()
[<RequireQualifiedAccess>]
type PathSpec =
| Verbatim of string
@@ -556,9 +568,6 @@ module internal HttpClientGenerator =
)
)
let jsonNodeNotNull =
Let ("jsonNode", AstHelper.raiseIfNull (Ident.create "jsonNode"))
let setVariableHeaders =
variableHeaders
|> List.map (fun (headerName, callToGetValue) ->
@@ -633,7 +642,6 @@ module internal HttpClientGenerator =
yield responseString
yield responseStream
yield jsonNode
yield jsonNodeNotNull
| String -> yield responseString
| Stream -> yield responseStream
| UnitType ->
@@ -642,7 +650,6 @@ module internal HttpClientGenerator =
| _ ->
yield responseStream
yield jsonNode
yield jsonNodeNotNull
]
|> SynExpr.createCompExpr "async" returnExpr
|> SynExpr.startAsTask cancellationTokenArg
@@ -907,6 +914,10 @@ module internal HttpClientGenerator =
"Create a REST client. The input functions will be re-evaluated on every HTTP request to obtain the required values for the corresponding header properties."
|> PreXmlDoc.create
let functionName = Ident.create "client"
let pattern = SynLongIdent.createS "make"
let returnInfo = SynType.createLongIdent interfaceType.Name
let nameWithoutLeadingI =

View File

@@ -78,7 +78,6 @@ module internal JsonParseGenerator =
/// collectionType is e.g. "List"; we'll be calling `ofSeq` on it.
/// body is the body of a lambda which takes a parameter `elt`.
/// {assertNotNull node}.AsArray()
/// |> Seq.cast<JsonNode>
/// |> Seq.map (fun elt -> {body})
/// |> {collectionType}.ofSeq
let asArrayMapped
@@ -92,13 +91,6 @@ module internal JsonParseGenerator =
| None -> node
| Some propertyName -> assertNotNull propertyName node
|> SynExpr.callMethod "AsArray"
|> SynExpr.pipeThroughFunction (
SynExpr.createLongIdent [ "Seq" ; "cast" ]
|> SynExpr.typeApp
[
SynType.createLongIdent' [ "System" ; "Text" ; "Json" ; "Nodes" ; "JsonNode" ]
]
)
|> SynExpr.pipeThroughFunction (
SynExpr.applyFunction (SynExpr.createLongIdent [ "Seq" ; "map" ]) (SynExpr.createLambda "elt" body)
)
@@ -281,12 +273,10 @@ module internal JsonParseGenerator =
)
|> SynExpr.pipeThroughFunction (SynExpr.createLongIdent [ "Map" ; "ofSeq" ])
| BigInt ->
AstHelper.raiseIfNull (Ident.create "v")
|> SynExpr.paren
node
|> SynExpr.callMethod "ToJsonString"
|> SynExpr.paren
|> SynExpr.applyFunction (SynExpr.createLongIdent [ "System" ; "Numerics" ; "BigInteger" ; "Parse" ])
|> SynExpr.createLet [ SynBinding.basic [ Ident.create "v" ] [] node ]
| Measure (_measure, primType) ->
parseNumberType options propertyName node primType
|> SynExpr.pipeThroughFunction (Measure.getLanguagePrimitivesMeasure primType)