Skip to content

Commit d6a5fe4

Browse files
committed
docs: revamps the null reference exception information
Signed-off-by: Vincent Biret <[email protected]>
1 parent 4906d21 commit d6a5fe4

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

docs/upgrade-guide-2.md

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,23 @@ In v2, the equivalent code would be,
220220
> - OpenApiString
221221
> - PrimitiveType
222222
223+
### Enable Null Reference Type Support
224+
225+
Version 2.0 preview 13 introduces support for null reference types, which improves type safety and reduces the likelihood of null reference exceptions.
226+
227+
**Example:**
228+
229+
```csharp
230+
var document = new OpenApiDocument
231+
{
232+
Components = null
233+
};
234+
235+
// 1.X: no compilation error or warning, but fails with a null reference exception at runtime
236+
// 2.X: compilation error or warning depending on the project configuration
237+
var componentA = document.Components["A"];
238+
```
239+
223240
### Updates to OpenApiSchema
224241

225242
The OpenAPI 3.1 specification changes significantly how it leverages JSON Schema. In 3.0 and earlier, OpenAPI used a "subset, superset" of JSON Schema draft-4. This caused many problems for developers trying to use JSON Schema validation libraries with the JSON Schema in their OpenAPI descriptions. In OpenAPI 3.1, the 2020-12 draft version of JSON Schema was adopted and a new JSON Schema vocabulary was adopted to support OpenAPI specific keywords. All attempts to constrain what JSON Schema keywords could be used in OpenAPI were removed.
@@ -380,30 +397,6 @@ OpenApiOperation operation = new OpenApiOperation
380397
};
381398
```
382399

383-
#### 2. Enable Null Reference Type Support
384-
385-
Version 2.0 preview 13 introduces support for null reference types, which improves type safety and reduces the likelihood of null reference exceptions.
386-
387-
**Example:**
388-
389-
```csharp
390-
// Before (1.6)
391-
OpenApiDocument document = new OpenApiDocument
392-
{
393-
Components = new OpenApiComponents()
394-
};
395-
396-
// After (2.0)
397-
OpenApiDocument document = new OpenApiDocument
398-
{
399-
Components = new OpenApiComponents()
400-
{
401-
Schemas = new Dictionary<string, IOpenApiSchema?>()
402-
}
403-
};
404-
405-
```
406-
407400
#### 3. References as Components
408401

409402
References can now be used as components, allowing for more modular and reusable OpenAPI documents.

0 commit comments

Comments
 (0)