From b98466ca06cfb003b4899af593b426770327bbd6 Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 1 Nov 2024 12:33:59 +1030 Subject: [PATCH] docs(dotnet): Add .NET JSON documentation (#26) --- sdk-dotnet/README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/sdk-dotnet/README.md b/sdk-dotnet/README.md index 68b39729..660f20c2 100644 --- a/sdk-dotnet/README.md +++ b/sdk-dotnet/README.md @@ -69,6 +69,38 @@ _ = client.Default.Start(); Unlike the [NodeJs SDK](https://github.com/inferablehq/inferable/sdk-node), the Dotnet SDK for Inferable reflects the types from the input struct of the function. It uses the [NJsonSchema](https://github.com/RicoSuter/NJsonSchema) under the hood to generate JSON schemas from C# types through reflection. +If the input class defines [System.Text.Json.Serialization](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization) attributes, the SDK will use those in the generated schema. This allows for fine-grained control over the schema generation. + +Here's an example to illustrate this: + +```cs +public struct UserInput +{ + [JsonPropertyName("id")] + public string Id { get; set; } + [JsonPropertyName("Name")] + public string Name { get; set; } + [ + JsonPropertyName("email"), + JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull) + ] + public string Email { get; set; } +} + +client.Default.RegisterFunction(new FunctionRegistration +{ + Name = "SayHello", + Description = "A simple greeting function", + Func = new Func>((input) => { + // Your code here + }), +}); +``` + +In this example, the UserInput class uses [System.Text.Json.Serialization](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization) attributes to define additional properties for the schema: + +- The email field is ignored when writing null. + ### Triggering a run