Skip to content

Commit 027d726

Browse files
committed
chore: update README.md
chore: tipo
1 parent 64dd7b2 commit 027d726

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

README.md

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
**OpenAi-JsonSchema** is a lightweight library for generating valid JSON Schema for OpenAI's Structured Outputs feature, ensuring compatibility with OpenAI's JSON Schema subset. It simplifies the creation of structured outputs for OpenAI models, following the schema generation guidelines provided by OpenAI.
66

77
## Features
8-
- Supports `System.ComponentModel.DescriptionAttribute` for descriptions.
9-
- Handles nullable reference types.
10-
- Supports a wide range of types, including primitives (e.g., `bool`, `int`, `double`, `DateTime`).
11-
- Ensures compatibility with OpenAI's JSON Schema format.
8+
- Supports `System.ComponentModel.DescriptionAttribute` for generating descriptions in the JSON Schema.
9+
- Handles `Nullable<T>` types (e.g., `int?`) and nullable reference types (e.g., `string?`).
10+
- Supports a wide range of types, including primitives such as `bool`, `int`, `double`, and `DateTime`.
11+
- Automatically manages `$defs` and `$ref` in the schema (e.g., `"$ref": "#/$defs/MyType"`).
12+
- Ensures compatibility with OpenAI's JSON Schema format for structured outputs.
1213

1314
## Installation
1415

@@ -23,10 +24,17 @@ Install-Package LarchSys.OpenAi.JsonSchema
2324
The following example demonstrates how to generate a JSON Schema using the **LarchSys.OpenAi.JsonSchema** library.
2425

2526
```csharp
26-
var options = new JsonSchemaOptions(SchemaDefaults.OpenAi);
27+
// use Json Options to control PropertyName and Enum serialization:
28+
var jsonOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web) {
29+
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
30+
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseLower) }
31+
};
32+
33+
// use SchemaDefaults.OpenAi to enforce OpenAi rule set:
34+
var options = new JsonSchemaOptions(SchemaDefaults.OpenAi, jsonOptions);
2735

2836
var resolver = new DefaultSchemaGenerator();
29-
var schema = resolver.Generate<Document>(options);
37+
var schema = resolver.Generate(type, options);
3038

3139
var json = schema.ToJsonNode().ToJsonString(new JsonSerializerOptions() { WriteIndented = true });
3240
output.WriteLine(json);
@@ -55,45 +63,45 @@ public record Line(
5563
"type": "object",
5664
"description": "A document",
5765
"properties": {
58-
"Id": {
66+
"id": {
5967
"type": "integer",
6068
"description": "Id of the document"
6169
},
62-
"Name": {
70+
"name": {
6371
"type": "string",
6472
"description": "Document name"
6573
},
66-
"Lines": {
74+
"lines": {
6775
"type": "array",
6876
"description": "Text lines of the document",
6977
"items": {
7078
"type": "object",
7179
"description": "A line of text in a document",
7280
"properties": {
73-
"Number": {
81+
"number": {
7482
"type": "integer",
7583
"description": "Line number"
7684
},
77-
"Text": {
85+
"text": {
7886
"type": "string",
7987
"description": "Line text"
8088
}
8189
},
8290
"required": [
83-
"Number",
84-
"Text"
91+
"number",
92+
"text"
8593
],
8694
"additionalProperties": false
8795
}
8896
},
89-
"Next": {
97+
"next": {
9098
"description": "Next document in order",
9199
"anyOf": [
92100
{ "type": "null" },
93101
{ "$ref": "#" }
94102
]
95103
},
96-
"Prev": {
104+
"prev": {
97105
"description": "Prev document in order",
98106
"anyOf": [
99107
{ "type": "null" },
@@ -102,14 +110,15 @@ public record Line(
102110
}
103111
},
104112
"required": [
105-
"Id",
106-
"Name",
107-
"Lines",
108-
"Next",
109-
"Prev"
113+
"id",
114+
"name",
115+
"lines",
116+
"next",
117+
"prev"
110118
],
111119
"additionalProperties": false
112120
}
121+
113122
```
114123

115124
## How It Works
@@ -126,7 +135,7 @@ Contributions are welcome! Please fork this repository and submit a pull request
126135

127136
## License
128137

129-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
138+
This project is licensed under the MIT License. See the [LICENSE](LICENSE.txt) file for more information.
130139

131140
## Contact
132141

0 commit comments

Comments
 (0)