diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index a613ecba4..0663b27eb 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -4,6 +4,7 @@ * Move common runtime utilities out of `FSharp.Data.Http` and into a new `FSharp.Data.Runtime.Utilities` assembly. * Add `aria-label` to the list of html attributes used to infer names of types provided by the HtmlProvider. * Enable TLS 1.2 when requesting http(s) samples from the type providers. +* Fix generated code of the json provider with `PreferDictionaries` when values are arrays. ### 6.0.1-beta001 - Aug 18 2022 diff --git a/src/FSharp.Data.DesignTime/Json/JsonGenerator.fs b/src/FSharp.Data.DesignTime/Json/JsonGenerator.fs index d4739e8e0..3f769ef8a 100644 --- a/src/FSharp.Data.DesignTime/Json/JsonGenerator.fs +++ b/src/FSharp.Data.DesignTime/Json/JsonGenerator.fs @@ -399,15 +399,42 @@ module JsonTypeBuilder = let inferedKeyValueType = let aggr = List.fold (StructuralInference.subtypeInfered false) InferedType.Top - let dropRecordName infType = + let dropRecordsNames infType = + + let dropRecordName infType = + match infType with + | InferedType.Record (_, fields, opt) -> InferedType.Record(None, fields, opt) + | _ -> infType + + let dropTagName tag = + match tag with + | InferedTypeTag.Record (Some _) -> InferedTypeTag.Record None + | _ -> tag + + let infType = dropRecordName infType + match infType with - | InferedType.Record (_, fields, opt) -> InferedType.Record(None, fields, opt) + | InferedType.Collection (order, types) -> + // Records in collections have the parent property as name. + // We drop it too so they can be merged into a unified type. + let order = order |> List.map dropTagName + + let types = + types + |> Map.toSeq + |> Seq.map (fun (tag, (multiplicity, typ)) -> + let tag = dropTagName tag + let typ = dropRecordName typ + tag, (multiplicity, typ)) + |> Map.ofSeq + + InferedType.Collection(order, types) | _ -> infType if not ctx.PreferDictionaries then None else - let infType = + let infKeyType = [ for prop in props -> StructuralInference.getInferedTypeFromString ctx.UnitsOfMeasureProvider @@ -417,14 +444,16 @@ module JsonTypeBuilder = None ] |> aggr - match infType with + match infKeyType with | InferedType.Primitive (typ = typ) when typ <> typeof -> let inferValueType = - ([ for prop in props -> prop.Type |> dropRecordName ] + ([ for prop in props -> prop.Type |> dropRecordsNames ] |> aggr) + // Optional properties in the initial record should translate + // to simply missing values in the dictionary, not an optional type. .DropOptionality() - (infType, inferValueType) |> Some + Some(infKeyType, inferValueType) | _ -> None match inferedKeyValueType with diff --git a/tests/FSharp.Data.DesignTime.Tests/SignatureTestCases.config b/tests/FSharp.Data.DesignTime.Tests/SignatureTestCases.config index 6f6688a33..e5d66bf59 100644 --- a/tests/FSharp.Data.DesignTime.Tests/SignatureTestCases.config +++ b/tests/FSharp.Data.DesignTime.Tests/SignatureTestCases.config @@ -190,6 +190,14 @@ Json,DictionaryInference.json,false,,,true,true,BackwardCompatible Json,DictionaryInference.json,false,,,true,true,ValuesOnly Json,DictionaryInference.json,false,,,true,true,ValuesAndInlineSchemasHints Json,DictionaryInference.json,false,,,true,true,ValuesAndInlineSchemasOverrides +Json,DictionaryInference-arrays.json,false,,,true,false,BackwardCompatible +Json,DictionaryInference-arrays.json,false,,,true,false,ValuesOnly +Json,DictionaryInference-arrays.json,false,,,true,false,ValuesAndInlineSchemasHints +Json,DictionaryInference-arrays.json,false,,,true,false,ValuesAndInlineSchemasOverrides +Json,DictionaryInference-arrays.json,false,,,true,true,BackwardCompatible +Json,DictionaryInference-arrays.json,false,,,true,true,ValuesOnly +Json,DictionaryInference-arrays.json,false,,,true,true,ValuesAndInlineSchemasHints +Json,DictionaryInference-arrays.json,false,,,true,true,ValuesAndInlineSchemasOverrides Html,MarketDepth.htm,false,false, Html,MarketDepth.htm,true,false, Html,SimpleHtmlTablesWithTr.html,false,false, @@ -207,4 +215,4 @@ Html,doctor_who3.html,false,false, Html,SimpleHtmlLists.html,false,false, Html,EmptyDefinitionLists.html,false,false, Html,zoopla.html,false,false, -Html,zoopla2.html,false,false, \ No newline at end of file +Html,zoopla2.html,false,false, diff --git a/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,BackwardCompatible.expected b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,BackwardCompatible.expected new file mode 100644 index 000000000..4f68c6a1f --- /dev/null +++ b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,BackwardCompatible.expected @@ -0,0 +1,108 @@ +class JsonProvider : obj + static member AsyncGetSample: () -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"), f) + + static member AsyncLoad: uri:string -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri), f) + + static member GetSample: () -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"))) + + static member Load: stream:System.IO.Stream -> JsonProvider+Root + JsonDocument.Create(((new StreamReader(stream)) :> TextReader)) + + static member Load: reader:System.IO.TextReader -> JsonProvider+Root + JsonDocument.Create(reader) + + static member Load: uri:string -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri))) + + static member Load: value:JsonValue -> JsonProvider+Root + JsonDocument.Create(value, "") + + static member Parse: text:string -> JsonProvider+Root + JsonDocument.Create(((new StringReader(text)) :> TextReader)) + + static member ParseList: text:string -> JsonProvider+JsonProvider+Root[] + JsonDocument.CreateList(((new StringReader(text)) :> TextReader)) + + +class JsonProvider+Root : FDR.BaseTypes.IJsonDocument + new : mappings:JsonProvider+Mappings -> JsonProvider+Root + JsonRuntime.CreateRecord([| ("Mappings", + (mappings :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Root + JsonDocument.Create(jsonValue, "") + + member Mappings: JsonProvider+Mappings with get + JsonRuntime.GetPropertyPacked(this, "Mappings") + + +class JsonProvider+Mappings : FDR.BaseTypes.IJsonDocument + new : 123:JsonProvider+JsonProvider+123[] -> 456:JsonProvider+JsonProvider+123[] -> 789:JsonProvider+JsonProvider+789[] -> JsonProvider+Mappings + JsonRuntime.CreateRecord([| ("123", + (123 :> obj)) + ("456", + (456 :> obj)) + ("789", + (789 :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Mappings + JsonDocument.Create(jsonValue, "") + + member 123: JsonProvider+JsonProvider+123[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "123"), new Func<_,_>(id))) + + member 456: JsonProvider+JsonProvider+123[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "456"), new Func<_,_>(id))) + + member 789: JsonProvider+JsonProvider+789[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "789"), new Func<_,_>(id))) + + +class JsonProvider+123 : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> JsonProvider+123 + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+123 + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + +class JsonProvider+789 : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> errorMessage:string option -> JsonProvider+789 + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) + ("ErrorMessage", + (errorMessage :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+789 + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member ErrorMessage: string option with get + JsonRuntime.ConvertString("", JsonRuntime.TryGetPropertyUnpacked(this, "ErrorMessage")) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + diff --git a/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,ValuesAndInlineSchemasHints.expected b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,ValuesAndInlineSchemasHints.expected new file mode 100644 index 000000000..4f68c6a1f --- /dev/null +++ b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,ValuesAndInlineSchemasHints.expected @@ -0,0 +1,108 @@ +class JsonProvider : obj + static member AsyncGetSample: () -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"), f) + + static member AsyncLoad: uri:string -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri), f) + + static member GetSample: () -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"))) + + static member Load: stream:System.IO.Stream -> JsonProvider+Root + JsonDocument.Create(((new StreamReader(stream)) :> TextReader)) + + static member Load: reader:System.IO.TextReader -> JsonProvider+Root + JsonDocument.Create(reader) + + static member Load: uri:string -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri))) + + static member Load: value:JsonValue -> JsonProvider+Root + JsonDocument.Create(value, "") + + static member Parse: text:string -> JsonProvider+Root + JsonDocument.Create(((new StringReader(text)) :> TextReader)) + + static member ParseList: text:string -> JsonProvider+JsonProvider+Root[] + JsonDocument.CreateList(((new StringReader(text)) :> TextReader)) + + +class JsonProvider+Root : FDR.BaseTypes.IJsonDocument + new : mappings:JsonProvider+Mappings -> JsonProvider+Root + JsonRuntime.CreateRecord([| ("Mappings", + (mappings :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Root + JsonDocument.Create(jsonValue, "") + + member Mappings: JsonProvider+Mappings with get + JsonRuntime.GetPropertyPacked(this, "Mappings") + + +class JsonProvider+Mappings : FDR.BaseTypes.IJsonDocument + new : 123:JsonProvider+JsonProvider+123[] -> 456:JsonProvider+JsonProvider+123[] -> 789:JsonProvider+JsonProvider+789[] -> JsonProvider+Mappings + JsonRuntime.CreateRecord([| ("123", + (123 :> obj)) + ("456", + (456 :> obj)) + ("789", + (789 :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Mappings + JsonDocument.Create(jsonValue, "") + + member 123: JsonProvider+JsonProvider+123[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "123"), new Func<_,_>(id))) + + member 456: JsonProvider+JsonProvider+123[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "456"), new Func<_,_>(id))) + + member 789: JsonProvider+JsonProvider+789[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "789"), new Func<_,_>(id))) + + +class JsonProvider+123 : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> JsonProvider+123 + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+123 + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + +class JsonProvider+789 : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> errorMessage:string option -> JsonProvider+789 + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) + ("ErrorMessage", + (errorMessage :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+789 + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member ErrorMessage: string option with get + JsonRuntime.ConvertString("", JsonRuntime.TryGetPropertyUnpacked(this, "ErrorMessage")) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + diff --git a/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,ValuesAndInlineSchemasOverrides.expected b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,ValuesAndInlineSchemasOverrides.expected new file mode 100644 index 000000000..4f68c6a1f --- /dev/null +++ b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,ValuesAndInlineSchemasOverrides.expected @@ -0,0 +1,108 @@ +class JsonProvider : obj + static member AsyncGetSample: () -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"), f) + + static member AsyncLoad: uri:string -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri), f) + + static member GetSample: () -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"))) + + static member Load: stream:System.IO.Stream -> JsonProvider+Root + JsonDocument.Create(((new StreamReader(stream)) :> TextReader)) + + static member Load: reader:System.IO.TextReader -> JsonProvider+Root + JsonDocument.Create(reader) + + static member Load: uri:string -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri))) + + static member Load: value:JsonValue -> JsonProvider+Root + JsonDocument.Create(value, "") + + static member Parse: text:string -> JsonProvider+Root + JsonDocument.Create(((new StringReader(text)) :> TextReader)) + + static member ParseList: text:string -> JsonProvider+JsonProvider+Root[] + JsonDocument.CreateList(((new StringReader(text)) :> TextReader)) + + +class JsonProvider+Root : FDR.BaseTypes.IJsonDocument + new : mappings:JsonProvider+Mappings -> JsonProvider+Root + JsonRuntime.CreateRecord([| ("Mappings", + (mappings :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Root + JsonDocument.Create(jsonValue, "") + + member Mappings: JsonProvider+Mappings with get + JsonRuntime.GetPropertyPacked(this, "Mappings") + + +class JsonProvider+Mappings : FDR.BaseTypes.IJsonDocument + new : 123:JsonProvider+JsonProvider+123[] -> 456:JsonProvider+JsonProvider+123[] -> 789:JsonProvider+JsonProvider+789[] -> JsonProvider+Mappings + JsonRuntime.CreateRecord([| ("123", + (123 :> obj)) + ("456", + (456 :> obj)) + ("789", + (789 :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Mappings + JsonDocument.Create(jsonValue, "") + + member 123: JsonProvider+JsonProvider+123[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "123"), new Func<_,_>(id))) + + member 456: JsonProvider+JsonProvider+123[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "456"), new Func<_,_>(id))) + + member 789: JsonProvider+JsonProvider+789[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "789"), new Func<_,_>(id))) + + +class JsonProvider+123 : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> JsonProvider+123 + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+123 + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + +class JsonProvider+789 : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> errorMessage:string option -> JsonProvider+789 + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) + ("ErrorMessage", + (errorMessage :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+789 + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member ErrorMessage: string option with get + JsonRuntime.ConvertString("", JsonRuntime.TryGetPropertyUnpacked(this, "ErrorMessage")) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + diff --git a/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,ValuesOnly.expected b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,ValuesOnly.expected new file mode 100644 index 000000000..4f68c6a1f --- /dev/null +++ b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,False,ValuesOnly.expected @@ -0,0 +1,108 @@ +class JsonProvider : obj + static member AsyncGetSample: () -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"), f) + + static member AsyncLoad: uri:string -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri), f) + + static member GetSample: () -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"))) + + static member Load: stream:System.IO.Stream -> JsonProvider+Root + JsonDocument.Create(((new StreamReader(stream)) :> TextReader)) + + static member Load: reader:System.IO.TextReader -> JsonProvider+Root + JsonDocument.Create(reader) + + static member Load: uri:string -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri))) + + static member Load: value:JsonValue -> JsonProvider+Root + JsonDocument.Create(value, "") + + static member Parse: text:string -> JsonProvider+Root + JsonDocument.Create(((new StringReader(text)) :> TextReader)) + + static member ParseList: text:string -> JsonProvider+JsonProvider+Root[] + JsonDocument.CreateList(((new StringReader(text)) :> TextReader)) + + +class JsonProvider+Root : FDR.BaseTypes.IJsonDocument + new : mappings:JsonProvider+Mappings -> JsonProvider+Root + JsonRuntime.CreateRecord([| ("Mappings", + (mappings :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Root + JsonDocument.Create(jsonValue, "") + + member Mappings: JsonProvider+Mappings with get + JsonRuntime.GetPropertyPacked(this, "Mappings") + + +class JsonProvider+Mappings : FDR.BaseTypes.IJsonDocument + new : 123:JsonProvider+JsonProvider+123[] -> 456:JsonProvider+JsonProvider+123[] -> 789:JsonProvider+JsonProvider+789[] -> JsonProvider+Mappings + JsonRuntime.CreateRecord([| ("123", + (123 :> obj)) + ("456", + (456 :> obj)) + ("789", + (789 :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Mappings + JsonDocument.Create(jsonValue, "") + + member 123: JsonProvider+JsonProvider+123[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "123"), new Func<_,_>(id))) + + member 456: JsonProvider+JsonProvider+123[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "456"), new Func<_,_>(id))) + + member 789: JsonProvider+JsonProvider+789[] with get + JsonRuntime.ConvertArray(JsonRuntime.GetPropertyPackedOrNull(this, "789"), new Func<_,_>(id))) + + +class JsonProvider+123 : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> JsonProvider+123 + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+123 + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + +class JsonProvider+789 : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> errorMessage:string option -> JsonProvider+789 + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) + ("ErrorMessage", + (errorMessage :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+789 + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member ErrorMessage: string option with get + JsonRuntime.ConvertString("", JsonRuntime.TryGetPropertyUnpacked(this, "ErrorMessage")) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + diff --git a/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,BackwardCompatible.expected b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,BackwardCompatible.expected new file mode 100644 index 000000000..bf92ebd58 --- /dev/null +++ b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,BackwardCompatible.expected @@ -0,0 +1,99 @@ +class JsonProvider : obj + static member AsyncGetSample: () -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"), f) + + static member AsyncLoad: uri:string -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri), f) + + static member GetSample: () -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"))) + + static member Load: stream:System.IO.Stream -> JsonProvider+Root + JsonDocument.Create(((new StreamReader(stream)) :> TextReader)) + + static member Load: reader:System.IO.TextReader -> JsonProvider+Root + JsonDocument.Create(reader) + + static member Load: uri:string -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri))) + + static member Load: value:JsonValue -> JsonProvider+Root + JsonDocument.Create(value, "") + + static member Parse: text:string -> JsonProvider+Root + JsonDocument.Create(((new StringReader(text)) :> TextReader)) + + static member ParseList: text:string -> JsonProvider+JsonProvider+Root[] + JsonDocument.CreateList(((new StringReader(text)) :> TextReader)) + + +class JsonProvider+Root : FDR.BaseTypes.IJsonDocument + new : mappings:JsonProvider+Mappings -> JsonProvider+Root + JsonRuntime.CreateRecord([| ("Mappings", + (mappings :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Root + JsonDocument.Create(jsonValue, "") + + member Mappings: JsonProvider+Mappings with get + JsonRuntime.GetPropertyPacked(this, "Mappings") + + +class JsonProvider+Mappings : FDR.BaseTypes.IJsonDocument + new : items:int * JsonProvider+JsonProvider+MappingsValue[] seq -> JsonProvider+Mappings + JsonRuntime.CreateRecordFromDictionary(items, "", new Func<_,_>(fun (t:int) -> TextRuntime.ConvertIntegerBack("", Some t))) + + new : jsonValue:JsonValue -> JsonProvider+Mappings + JsonDocument.Create(jsonValue, "") + + member ContainsKey: key:int -> bool + JsonRuntime.InferedDictionaryContainsKey(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), key) + + member Count: int with get + JsonRuntime.GetRecordProperties(this).Length + + member IsEmpty: bool with get + (Operators.op_Equality JsonRuntime.GetRecordProperties(this).Length 0) + + member Item: JsonProvider+JsonProvider+MappingsValue[] with get + JsonRuntime.GetValueByKeyFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id)))), key) + + member Items: int * JsonProvider+JsonProvider+MappingsValue[] seq with get + JsonRuntime.ConvertRecordToDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id))))) + + member Keys: int[] with get + JsonRuntime.GetKeysFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue))) + + member TryFind: key:int -> JsonProvider+JsonProvider+MappingsValue[] option + JsonRuntime.TryGetValueByKeyFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id)))), key) + + member Values: JsonProvider+JsonProvider+JsonProvider+MappingsValue[][] with get + JsonRuntime.GetValuesFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id))))) + + +class JsonProvider+MappingsValue : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> errorMessage:string option -> JsonProvider+MappingsValue + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) + ("ErrorMessage", + (errorMessage :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+MappingsValue + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member ErrorMessage: string option with get + JsonRuntime.ConvertString("", JsonRuntime.TryGetPropertyUnpacked(this, "ErrorMessage")) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + diff --git a/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,ValuesAndInlineSchemasHints.expected b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,ValuesAndInlineSchemasHints.expected new file mode 100644 index 000000000..bf92ebd58 --- /dev/null +++ b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,ValuesAndInlineSchemasHints.expected @@ -0,0 +1,99 @@ +class JsonProvider : obj + static member AsyncGetSample: () -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"), f) + + static member AsyncLoad: uri:string -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri), f) + + static member GetSample: () -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"))) + + static member Load: stream:System.IO.Stream -> JsonProvider+Root + JsonDocument.Create(((new StreamReader(stream)) :> TextReader)) + + static member Load: reader:System.IO.TextReader -> JsonProvider+Root + JsonDocument.Create(reader) + + static member Load: uri:string -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri))) + + static member Load: value:JsonValue -> JsonProvider+Root + JsonDocument.Create(value, "") + + static member Parse: text:string -> JsonProvider+Root + JsonDocument.Create(((new StringReader(text)) :> TextReader)) + + static member ParseList: text:string -> JsonProvider+JsonProvider+Root[] + JsonDocument.CreateList(((new StringReader(text)) :> TextReader)) + + +class JsonProvider+Root : FDR.BaseTypes.IJsonDocument + new : mappings:JsonProvider+Mappings -> JsonProvider+Root + JsonRuntime.CreateRecord([| ("Mappings", + (mappings :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Root + JsonDocument.Create(jsonValue, "") + + member Mappings: JsonProvider+Mappings with get + JsonRuntime.GetPropertyPacked(this, "Mappings") + + +class JsonProvider+Mappings : FDR.BaseTypes.IJsonDocument + new : items:int * JsonProvider+JsonProvider+MappingsValue[] seq -> JsonProvider+Mappings + JsonRuntime.CreateRecordFromDictionary(items, "", new Func<_,_>(fun (t:int) -> TextRuntime.ConvertIntegerBack("", Some t))) + + new : jsonValue:JsonValue -> JsonProvider+Mappings + JsonDocument.Create(jsonValue, "") + + member ContainsKey: key:int -> bool + JsonRuntime.InferedDictionaryContainsKey(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), key) + + member Count: int with get + JsonRuntime.GetRecordProperties(this).Length + + member IsEmpty: bool with get + (Operators.op_Equality JsonRuntime.GetRecordProperties(this).Length 0) + + member Item: JsonProvider+JsonProvider+MappingsValue[] with get + JsonRuntime.GetValueByKeyFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id)))), key) + + member Items: int * JsonProvider+JsonProvider+MappingsValue[] seq with get + JsonRuntime.ConvertRecordToDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id))))) + + member Keys: int[] with get + JsonRuntime.GetKeysFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue))) + + member TryFind: key:int -> JsonProvider+JsonProvider+MappingsValue[] option + JsonRuntime.TryGetValueByKeyFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id)))), key) + + member Values: JsonProvider+JsonProvider+JsonProvider+MappingsValue[][] with get + JsonRuntime.GetValuesFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id))))) + + +class JsonProvider+MappingsValue : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> errorMessage:string option -> JsonProvider+MappingsValue + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) + ("ErrorMessage", + (errorMessage :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+MappingsValue + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member ErrorMessage: string option with get + JsonRuntime.ConvertString("", JsonRuntime.TryGetPropertyUnpacked(this, "ErrorMessage")) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + diff --git a/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,ValuesAndInlineSchemasOverrides.expected b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,ValuesAndInlineSchemasOverrides.expected new file mode 100644 index 000000000..bf92ebd58 --- /dev/null +++ b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,ValuesAndInlineSchemasOverrides.expected @@ -0,0 +1,99 @@ +class JsonProvider : obj + static member AsyncGetSample: () -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"), f) + + static member AsyncLoad: uri:string -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri), f) + + static member GetSample: () -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"))) + + static member Load: stream:System.IO.Stream -> JsonProvider+Root + JsonDocument.Create(((new StreamReader(stream)) :> TextReader)) + + static member Load: reader:System.IO.TextReader -> JsonProvider+Root + JsonDocument.Create(reader) + + static member Load: uri:string -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri))) + + static member Load: value:JsonValue -> JsonProvider+Root + JsonDocument.Create(value, "") + + static member Parse: text:string -> JsonProvider+Root + JsonDocument.Create(((new StringReader(text)) :> TextReader)) + + static member ParseList: text:string -> JsonProvider+JsonProvider+Root[] + JsonDocument.CreateList(((new StringReader(text)) :> TextReader)) + + +class JsonProvider+Root : FDR.BaseTypes.IJsonDocument + new : mappings:JsonProvider+Mappings -> JsonProvider+Root + JsonRuntime.CreateRecord([| ("Mappings", + (mappings :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Root + JsonDocument.Create(jsonValue, "") + + member Mappings: JsonProvider+Mappings with get + JsonRuntime.GetPropertyPacked(this, "Mappings") + + +class JsonProvider+Mappings : FDR.BaseTypes.IJsonDocument + new : items:int * JsonProvider+JsonProvider+MappingsValue[] seq -> JsonProvider+Mappings + JsonRuntime.CreateRecordFromDictionary(items, "", new Func<_,_>(fun (t:int) -> TextRuntime.ConvertIntegerBack("", Some t))) + + new : jsonValue:JsonValue -> JsonProvider+Mappings + JsonDocument.Create(jsonValue, "") + + member ContainsKey: key:int -> bool + JsonRuntime.InferedDictionaryContainsKey(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), key) + + member Count: int with get + JsonRuntime.GetRecordProperties(this).Length + + member IsEmpty: bool with get + (Operators.op_Equality JsonRuntime.GetRecordProperties(this).Length 0) + + member Item: JsonProvider+JsonProvider+MappingsValue[] with get + JsonRuntime.GetValueByKeyFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id)))), key) + + member Items: int * JsonProvider+JsonProvider+MappingsValue[] seq with get + JsonRuntime.ConvertRecordToDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id))))) + + member Keys: int[] with get + JsonRuntime.GetKeysFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue))) + + member TryFind: key:int -> JsonProvider+JsonProvider+MappingsValue[] option + JsonRuntime.TryGetValueByKeyFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id)))), key) + + member Values: JsonProvider+JsonProvider+JsonProvider+MappingsValue[][] with get + JsonRuntime.GetValuesFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id))))) + + +class JsonProvider+MappingsValue : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> errorMessage:string option -> JsonProvider+MappingsValue + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) + ("ErrorMessage", + (errorMessage :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+MappingsValue + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member ErrorMessage: string option with get + JsonRuntime.ConvertString("", JsonRuntime.TryGetPropertyUnpacked(this, "ErrorMessage")) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + diff --git a/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,ValuesOnly.expected b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,ValuesOnly.expected new file mode 100644 index 000000000..bf92ebd58 --- /dev/null +++ b/tests/FSharp.Data.DesignTime.Tests/expected/Json,DictionaryInference-arrays.json,False,,,True,True,ValuesOnly.expected @@ -0,0 +1,99 @@ +class JsonProvider : obj + static member AsyncGetSample: () -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"), f) + + static member AsyncLoad: uri:string -> JsonProvider+Root async + let f = new Func<_,_>(fun (t:TextReader) -> JsonDocument.Create(t)) + TextRuntime.AsyncMap((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri), f) + + static member GetSample: () -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntimeWithDesignTimeRules "" "" "JSON" "" "DictionaryInference-arrays.json"))) + + static member Load: stream:System.IO.Stream -> JsonProvider+Root + JsonDocument.Create(((new StreamReader(stream)) :> TextReader)) + + static member Load: reader:System.IO.TextReader -> JsonProvider+Root + JsonDocument.Create(reader) + + static member Load: uri:string -> JsonProvider+Root + JsonDocument.Create(FSharpAsync.RunSynchronously((IO.asyncReadTextAtRuntime false "" "" "JSON" "" uri))) + + static member Load: value:JsonValue -> JsonProvider+Root + JsonDocument.Create(value, "") + + static member Parse: text:string -> JsonProvider+Root + JsonDocument.Create(((new StringReader(text)) :> TextReader)) + + static member ParseList: text:string -> JsonProvider+JsonProvider+Root[] + JsonDocument.CreateList(((new StringReader(text)) :> TextReader)) + + +class JsonProvider+Root : FDR.BaseTypes.IJsonDocument + new : mappings:JsonProvider+Mappings -> JsonProvider+Root + JsonRuntime.CreateRecord([| ("Mappings", + (mappings :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+Root + JsonDocument.Create(jsonValue, "") + + member Mappings: JsonProvider+Mappings with get + JsonRuntime.GetPropertyPacked(this, "Mappings") + + +class JsonProvider+Mappings : FDR.BaseTypes.IJsonDocument + new : items:int * JsonProvider+JsonProvider+MappingsValue[] seq -> JsonProvider+Mappings + JsonRuntime.CreateRecordFromDictionary(items, "", new Func<_,_>(fun (t:int) -> TextRuntime.ConvertIntegerBack("", Some t))) + + new : jsonValue:JsonValue -> JsonProvider+Mappings + JsonDocument.Create(jsonValue, "") + + member ContainsKey: key:int -> bool + JsonRuntime.InferedDictionaryContainsKey(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), key) + + member Count: int with get + JsonRuntime.GetRecordProperties(this).Length + + member IsEmpty: bool with get + (Operators.op_Equality JsonRuntime.GetRecordProperties(this).Length 0) + + member Item: JsonProvider+JsonProvider+MappingsValue[] with get + JsonRuntime.GetValueByKeyFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id)))), key) + + member Items: int * JsonProvider+JsonProvider+MappingsValue[] seq with get + JsonRuntime.ConvertRecordToDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id))))) + + member Keys: int[] with get + JsonRuntime.GetKeysFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue))) + + member TryFind: key:int -> JsonProvider+JsonProvider+MappingsValue[] option + JsonRuntime.TryGetValueByKeyFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.GetNonOptionalValue(t.Path(), JsonRuntime.ConvertInteger("", Some t.JsonValue), Some t.JsonValue)), new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id)))), key) + + member Values: JsonProvider+JsonProvider+JsonProvider+MappingsValue[][] with get + JsonRuntime.GetValuesFromInferedDictionary(this, new Func<_,_>(fun (t:IJsonDocument) -> JsonRuntime.ConvertArray(t, new Func<_,_>(id))))) + + +class JsonProvider+MappingsValue : FDR.BaseTypes.IJsonDocument + new : groupId:int -> canDelete:bool -> errorMessage:string option -> JsonProvider+MappingsValue + JsonRuntime.CreateRecord([| ("GroupId", + (groupId :> obj)) + ("CanDelete", + (canDelete :> obj)) + ("ErrorMessage", + (errorMessage :> obj)) |], "") + + new : jsonValue:JsonValue -> JsonProvider+MappingsValue + JsonDocument.Create(jsonValue, "") + + member CanDelete: bool with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "CanDelete") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertBoolean(value.JsonOpt), value.JsonOpt) + + member ErrorMessage: string option with get + JsonRuntime.ConvertString("", JsonRuntime.TryGetPropertyUnpacked(this, "ErrorMessage")) + + member GroupId: int with get + let value = JsonRuntime.TryGetPropertyUnpackedWithPath(this, "GroupId") + JsonRuntime.GetNonOptionalValue(value.Path, JsonRuntime.ConvertInteger("", value.JsonOpt), value.JsonOpt) + + diff --git a/tests/FSharp.Data.Tests/Data/DictionaryInference-arrays.json b/tests/FSharp.Data.Tests/Data/DictionaryInference-arrays.json new file mode 100644 index 000000000..0a70795e8 --- /dev/null +++ b/tests/FSharp.Data.Tests/Data/DictionaryInference-arrays.json @@ -0,0 +1,31 @@ +{ + "Mappings": { + "123": [ + { + "GroupId": 1001, + "CanDelete": true + }, + { + "GroupId": 6562, + "CanDelete": false + } + ], + "456": [ + { + "GroupId": 1003, + "CanDelete": false + } + ], + "789": [ + { + "GroupId": 1002, + "CanDelete": false, + "ErrorMessage": "Error." + }, + { + "GroupId": 6562, + "CanDelete": true + } + ] + } +}