You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Repo Assist] Add ExceptionIfMissing static parameter to JsonProvider and XmlProvider (#1680)
* Add ExceptionIfMissing static parameter to JsonProvider and XmlProvider
Implements opt-in strict mode for missing field handling. When ExceptionIfMissing=true,
accessing a non-optional field that is absent in the data raises an exception instead of
silently returning a default value (empty string for string, NaN for float).
The default behavior (ExceptionIfMissing=false) is unchanged for backward compatibility.
- Added GetNonOptionalValueStrict<'T> to JsonRuntime and TextRuntime
- Added ExceptionIfMissing static parameter to JsonProvider and XmlProvider
- Updated code generation pipeline (JsonConversionsGenerator, ConversionsGenerator)
- CsvProvider and HtmlProvider always use non-strict mode (false)
- Updated TypeProviderInstantiation.fs test helper
- Added tests for ExceptionIfMissing behavior
Also fixes a pre-existing XmlProvider bug where args.[14] was used for both
UseSchemaTypeNames and PreferDateTimeOffset (should be args.[14] and args.[15]).
Closes#1241
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* ci: trigger CI checks
---------
Co-authored-by: Repo Assist <repo-assist@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Don Syme <dsyme@users.noreply.github.com>
Copy file name to clipboardExpand all lines: RELEASE_NOTES.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
3
3
## 8.1.0-beta
4
4
5
+
- Add `ExceptionIfMissing` static parameter to `JsonProvider` and `XmlProvider`: when true, accessing a non-optional field that is missing in the data raises an exception instead of silently returning a default value (empty string for string, NaN for float). Defaults to false for backward compatibility.
5
6
- Add `Http.ParseLinkHeader` utility for parsing RFC 5988 `Link` response headers (used by GitHub, GitLab, and other paginated APIs) into a `Map<string, string>` from relation name to URL (closes #805)
6
7
- Add `PreferDateTimeOffset` parameter to `CsvProvider`, `JsonProvider`, and `XmlProvider`: when true, date-time values without an explicit timezone offset are inferred as `DateTimeOffset` (using local offset) instead of `DateTime` (closes #1100, #1072)
7
8
- Make `Http.AppendQueryToUrl` public (closes #1325)
"""<summary>Typed representation of a JSON document.</summary>
@@ -215,7 +218,8 @@ type public JsonProvider(cfg: TypeProviderConfig) as this =
215
218
<param name='UseOriginalNames'>When true, JSON property names are used as-is for generated property names instead of being normalized to PascalCase. Defaults to false.</param>
216
219
<param name='OmitNullFields'>When true, optional fields with value None are omitted from the generated JSON rather than serialized as null. Defaults to false.</param>
217
220
<param name='PreferOptionals'>When set to true (default), inference will use the option type for missing or null values. When false, inference will prefer to use empty string or double.NaN for missing values where possible, matching the default CsvProvider behavior.</param>
218
-
<param name='PreferDateTimeOffset'>When true, date-time strings without an explicit timezone offset are inferred as DateTimeOffset (using the local offset) instead of DateTime. Defaults to false.</param>"""
221
+
<param name='PreferDateTimeOffset'>When true, date-time strings without an explicit timezone offset are inferred as DateTimeOffset (using the local offset) instead of DateTime. Defaults to false.</param>
222
+
<param name='ExceptionIfMissing'>When true, accessing a non-optional field that is missing in the JSON data raises an exception instead of returning a default value (empty string for string, NaN for float). Defaults to false for backward compatibility.</param>"""
219
223
220
224
do jsonProvTy.AddXmlDoc helpText
221
225
do jsonProvTy.DefineStaticParameters(parameters, buildTypes)
"""<summary>Typed representation of a XML file.</summary>
@@ -255,7 +259,8 @@ type public XmlProvider(cfg: TypeProviderConfig) as this =
255
259
<param name='UseOriginalNames'>When true, XML element and attribute names are used as-is for generated property names instead of being normalized to PascalCase. Defaults to false.</param>
256
260
<param name='PreferOptionals'>When set to true (default), inference will use the option type for missing or absent values. When false, inference will prefer to use empty string or double.NaN for missing values where possible, matching the default CsvProvider behavior.</param>
257
261
<param name='UseSchemaTypeNames'>When true and a Schema is provided, the XSD complex type name is used for the generated F# type instead of the element name. This causes multiple elements that share the same XSD type to map to a single F# type. Defaults to false for backward compatibility.</param>
258
-
<param name='PreferDateTimeOffset'>When true, date-time strings without an explicit timezone offset are inferred as DateTimeOffset (using the local offset) instead of DateTime. Defaults to false.</param>"""
262
+
<param name='PreferDateTimeOffset'>When true, date-time strings without an explicit timezone offset are inferred as DateTimeOffset (using the local offset) instead of DateTime. Defaults to false.</param>
263
+
<param name='ExceptionIfMissing'>When true, accessing a non-optional field that is missing in the XML data raises an exception instead of returning a default value (empty string for string, NaN for float). Defaults to false for backward compatibility.</param>"""
0 commit comments