Skip to content

Commit 77e3ee1

Browse files
[Repo Assist] Add XML doc comments to JsonValue.fs (batch 2 of #1678) (#1686)
* Add XML doc comments to JsonValue.fs (batch 2 of #1678) Add comprehensive doc comments to JsonValue: - Document DU cases: String, Number, Float, Record, Array, Boolean, Null - Add param/return XML docs to WriteTo, ToString overloads - Add param/return XML docs to Parse, TryParse, Load, AsyncLoad, ParseMultiple - Add param/return XML docs to Request and RequestAsync Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger CI checks --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f893f0c commit 77e3ee1

1 file changed

Lines changed: 51 additions & 10 deletions

File tree

src/FSharp.Data.Json.Core/JsonValue.fs

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ type JsonSaveOptions =
3737
[<RequireQualifiedAccess>]
3838
[<StructuredFormatDisplay("{_Print}")>]
3939
type JsonValue =
40+
/// A JSON string value
4041
| String of string
42+
/// A JSON number stored as a decimal (used for numbers that fit in the decimal range)
4143
| Number of decimal
44+
/// A JSON number stored as a float (used for large numbers that do not fit in decimal)
4245
| Float of float
46+
/// A JSON object, represented as an array of name-value pairs
4347
| Record of properties: (string * JsonValue)[]
48+
/// A JSON array of values
4449
| Array of elements: JsonValue[]
50+
/// A JSON boolean value
4551
| Boolean of bool
52+
/// A JSON null value
4653
| Null
4754

4855
/// <exclude />
@@ -59,7 +66,10 @@ type JsonValue =
5966
else
6067
str
6168

62-
/// Serializes the JsonValue to the specified System.IO.TextWriter.
69+
/// <summary>Serializes the JsonValue to the specified System.IO.TextWriter.</summary>
70+
/// <param name="w">The writer to serialize to.</param>
71+
/// <param name="saveOptions">Controls formatting: indented, compact, or compact with spaces.</param>
72+
/// <param name="indentationSpaces">Number of spaces per indentation level (default 2). Only used when saveOptions is <see cref="JsonSaveOptions.None"/>.</param>
6373
member x.WriteTo(w: TextWriter, saveOptions, ?indentationSpaces: int) =
6474
let indentationSpaces = defaultArg indentationSpaces 2
6575

@@ -179,11 +189,18 @@ type JsonValue =
179189
if lastWritePos < value.Length then
180190
w.Write(value.Substring(lastWritePos))
181191

192+
/// <summary>Serializes this JsonValue to a string with the specified formatting options.</summary>
193+
/// <param name="saveOptions">Controls formatting: indented, compact, or compact with spaces.</param>
194+
/// <param name="indentationSpaces">Number of spaces per indentation level (default 2). Only used when saveOptions is <see cref="JsonSaveOptions.None"/>.</param>
195+
/// <returns>The JSON string representation.</returns>
182196
member x.ToString(saveOptions, ?indentationSpaces: int) =
183197
let w = new StringWriter(CultureInfo.InvariantCulture)
184198
x.WriteTo(w, saveOptions, ?indentationSpaces = indentationSpaces)
185199
w.GetStringBuilder().ToString()
186200

201+
/// <summary>Serializes this JsonValue to a formatted (indented) string.</summary>
202+
/// <param name="indentationSpaces">Number of spaces per indentation level (default 2).</param>
203+
/// <returns>The formatted JSON string representation.</returns>
187204
member x.ToString(?indentationSpaces: int) =
188205
x.ToString(JsonSaveOptions.None, ?indentationSpaces = indentationSpaces)
189206

@@ -482,28 +499,39 @@ type private JsonParser(jsonText: string) =
482499

483500
type JsonValue with
484501

485-
/// Parses the specified JSON string
502+
/// <summary>Parses the specified JSON string.</summary>
503+
/// <param name="text">The JSON string to parse.</param>
504+
/// <returns>A <see cref="JsonValue"/> representing the parsed JSON.</returns>
486505
static member Parse(text) = JsonParser(text).Parse()
487506

488-
/// Attempts to parse the specified JSON string
507+
/// <summary>Attempts to parse the specified JSON string.</summary>
508+
/// <param name="text">The JSON string to parse.</param>
509+
/// <returns>Some <see cref="JsonValue"/> if parsing succeeds, or None if parsing fails.</returns>
489510
static member TryParse(text) =
490511
try
491512
Some <| JsonParser(text).Parse()
492513
with _ ->
493514
None
494515

495-
/// Loads JSON from the specified stream
516+
/// <summary>Loads JSON from the specified stream.</summary>
517+
/// <param name="stream">The stream to read JSON from.</param>
518+
/// <returns>A <see cref="JsonValue"/> representing the parsed JSON.</returns>
496519
static member Load(stream: Stream) =
497520
use reader = new StreamReader(stream)
498521
let text = reader.ReadToEnd()
499522
JsonParser(text).Parse()
500523

501-
/// Loads JSON from the specified reader
524+
/// <summary>Loads JSON from the specified reader.</summary>
525+
/// <param name="reader">The text reader to read JSON from.</param>
526+
/// <returns>A <see cref="JsonValue"/> representing the parsed JSON.</returns>
502527
static member Load(reader: TextReader) =
503528
let text = reader.ReadToEnd()
504529
JsonParser(text).Parse()
505530

506-
/// Loads JSON from the specified uri asynchronously
531+
/// <summary>Loads JSON from the specified URI asynchronously.</summary>
532+
/// <param name="uri">The URI to load JSON from (file path or URL).</param>
533+
/// <param name="encoding">The text encoding to use (default: UTF-8).</param>
534+
/// <returns>An async computation yielding a <see cref="JsonValue"/> representing the parsed JSON.</returns>
507535
static member AsyncLoad(uri: string, [<Optional>] ?encoding) =
508536
async {
509537
let encoding = defaultArg encoding Encoding.UTF8
@@ -512,11 +540,16 @@ type JsonValue with
512540
return JsonParser(text).Parse()
513541
}
514542

515-
/// Loads JSON from the specified uri
543+
/// <summary>Loads JSON from the specified URI.</summary>
544+
/// <param name="uri">The URI to load JSON from (file path or URL).</param>
545+
/// <param name="encoding">The text encoding to use (default: UTF-8).</param>
546+
/// <returns>A <see cref="JsonValue"/> representing the parsed JSON.</returns>
516547
static member Load(uri: string, [<Optional>] ?encoding) =
517548
JsonValue.AsyncLoad(uri, ?encoding = encoding) |> Async.RunSynchronously
518549

519-
/// Parses the specified string into multiple JSON values
550+
/// <summary>Parses the specified string into multiple JSON values (e.g. newline-delimited JSON).</summary>
551+
/// <param name="text">The string containing multiple JSON values.</param>
552+
/// <returns>A sequence of <see cref="JsonValue"/> instances.</returns>
520553
static member ParseMultiple(text) = JsonParser(text).ParseMultiple()
521554

522555
member private x.PrepareRequest(httpMethod, headers) =
@@ -535,12 +568,20 @@ type JsonValue with
535568

536569
TextRequest(x.ToString(JsonSaveOptions.DisableFormatting)), headers, httpMethod
537570

538-
/// Sends the JSON to the specified URL synchronously. Defaults to a POST request.
571+
/// <summary>Sends the JSON to the specified URL synchronously. Defaults to a POST request.</summary>
572+
/// <param name="url">The URL to send the JSON to.</param>
573+
/// <param name="httpMethod">The HTTP method to use (default: POST).</param>
574+
/// <param name="headers">Additional HTTP headers to include.</param>
575+
/// <returns>An <see cref="HttpResponse"/> containing the server's response.</returns>
539576
member x.Request(url: string, [<Optional>] ?httpMethod, [<Optional>] ?headers: seq<_>) =
540577
let body, headers, httpMethod = x.PrepareRequest(httpMethod, headers)
541578
Http.Request(url, body = body, headers = headers, httpMethod = httpMethod)
542579

543-
/// Sends the JSON to the specified URL asynchronously. Defaults to a POST request.
580+
/// <summary>Sends the JSON to the specified URL asynchronously. Defaults to a POST request.</summary>
581+
/// <param name="url">The URL to send the JSON to.</param>
582+
/// <param name="httpMethod">The HTTP method to use (default: POST).</param>
583+
/// <param name="headers">Additional HTTP headers to include.</param>
584+
/// <returns>An async computation yielding an <see cref="HttpResponse"/> containing the server's response.</returns>
544585
member x.RequestAsync(url: string, [<Optional>] ?httpMethod, [<Optional>] ?headers: seq<_>) =
545586
let body, headers, httpMethod = x.PrepareRequest(httpMethod, headers)
546587
Http.AsyncRequest(url, body = body, headers = headers, httpMethod = httpMethod)

0 commit comments

Comments
 (0)