From 1cc1f059cb297fcb16e97f71605c93c719bbe26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Larch?= Date: Thu, 3 Oct 2024 18:20:09 +0200 Subject: [PATCH] chore: update README.md chore: tipo --- README.md | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 64926fe..b532be6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Features - Supports `System.ComponentModel.DescriptionAttribute` for descriptions. -- Handles nullable reference types. +- Handles `Nullable` like `int?` and `nullable reference` types like `string?`. - Supports a wide range of types, including primitives (e.g., `bool`, `int`, `double`, `DateTime`). - Ensures compatibility with OpenAI's JSON Schema format. @@ -23,10 +23,17 @@ Install-Package LarchSys.OpenAi.JsonSchema The following example demonstrates how to generate a JSON Schema using the **LarchSys.OpenAi.JsonSchema** library. ```csharp -var options = new JsonSchemaOptions(SchemaDefaults.OpenAi); +// use Json Options to control PropertyName and Enum serialization: +var jsonOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web) { + PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, + Converters = { new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseLower) } +}; + +// use SchemaDefaults.OpenAi to enforce OpenAi rule set: +var options = new JsonSchemaOptions(SchemaDefaults.OpenAi, jsonOptions); var resolver = new DefaultSchemaGenerator(); -var schema = resolver.Generate(options); +var schema = resolver.Generate(type, options); var json = schema.ToJsonNode().ToJsonString(new JsonSerializerOptions() { WriteIndented = true }); output.WriteLine(json); @@ -55,45 +62,45 @@ public record Line( "type": "object", "description": "A document", "properties": { - "Id": { + "id": { "type": "integer", "description": "Id of the document" }, - "Name": { + "name": { "type": "string", "description": "Document name" }, - "Lines": { + "lines": { "type": "array", "description": "Text lines of the document", "items": { "type": "object", "description": "A line of text in a document", "properties": { - "Number": { + "number": { "type": "integer", "description": "Line number" }, - "Text": { + "text": { "type": "string", "description": "Line text" } }, "required": [ - "Number", - "Text" + "number", + "text" ], "additionalProperties": false } }, - "Next": { + "next": { "description": "Next document in order", "anyOf": [ { "type": "null" }, { "$ref": "#" } ] }, - "Prev": { + "prev": { "description": "Prev document in order", "anyOf": [ { "type": "null" }, @@ -102,14 +109,15 @@ public record Line( } }, "required": [ - "Id", - "Name", - "Lines", - "Next", - "Prev" + "id", + "name", + "lines", + "next", + "prev" ], "additionalProperties": false } + ``` ## How It Works @@ -126,7 +134,7 @@ Contributions are welcome! Please fork this repository and submit a pull request ## License -This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information. +This project is licensed under the MIT License. See the [LICENSE](LICENSE.txt) file for more information. ## Contact