Skip to content

Commit 4906d21

Browse files
committed
docs: adds information about the null collections
Signed-off-by: Vincent Biret <[email protected]>
1 parent 305f026 commit 4906d21

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/upgrade-guide-2.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,29 @@ To better support applications deployed in high performance environments or on d
4747
>
4848
> - StringExtensions
4949
50+
### Collections are not initialized
51+
52+
To lower the memory footprint of the library, collections are now NOT initialized anymore when instantiating any of the models.
53+
54+
Example
55+
56+
```csharp
57+
var mySchema = new OpenApiSchema();
58+
59+
// 1.6: works
60+
// 2.X: if null reference types is enabled in the target application,
61+
// this will lead to a warning or error at compile time.
62+
// And fail at runtime with a null reference exception.
63+
mySchema.AnyOf.Add(otherSchema);
64+
65+
// one solution
66+
mySchema.AnyOf ??= [];
67+
mySchema.AnyOf.Add(otherSchema);
68+
69+
// alternative
70+
mySchema.AnyOf = [otherSchema];
71+
```
72+
5073
## Reduced Dependencies
5174

5275
In OpenAPI v1, it was necessary to include the Microsoft.OpenApi.Readers library to be able to read OpenAPI descriptions in either YAML or JSON. In OpenAPI.NET v2, the core Microsoft.OpenAPI library can both read and write JSON. It is only necessary to use the newly renamed [Microsoft.OpenApi.YamlReader](https://www.nuget.org/packages/Microsoft.OpenApi.YamlReader/) library if you need YAML support. This allows teams who are only working in JSON to avoid the additional dependency and therefore eliminate all non-.NET library references.

0 commit comments

Comments
 (0)