Skip to content

Commit

Permalink
chore: update README.md
Browse files Browse the repository at this point in the history
chore: tipo
  • Loading branch information
r-Larch committed Oct 3, 2024
1 parent 64dd7b2 commit 1cc1f05
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Features
- Supports `System.ComponentModel.DescriptionAttribute` for descriptions.
- Handles nullable reference types.
- Handles `Nullable<T>` 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.

Expand All @@ -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<Document>(options);
var schema = resolver.Generate(type, options);

var json = schema.ToJsonNode().ToJsonString(new JsonSerializerOptions() { WriteIndented = true });
output.WriteLine(json);
Expand Down Expand Up @@ -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" },
Expand All @@ -102,14 +109,15 @@ public record Line(
}
},
"required": [
"Id",
"Name",
"Lines",
"Next",
"Prev"
"id",
"name",
"lines",
"next",
"prev"
],
"additionalProperties": false
}

```

## How It Works
Expand All @@ -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

Expand Down

0 comments on commit 1cc1f05

Please sign in to comment.