You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/upgrade-guide-2.md
+17-24Lines changed: 17 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -220,6 +220,23 @@ In v2, the equivalent code would be,
220
220
> - OpenApiString
221
221
> - PrimitiveType
222
222
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
+
vardocument=newOpenApiDocument
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
+
varcomponentA=document.Components["A"];
238
+
```
239
+
223
240
### Updates to OpenApiSchema
224
241
225
242
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
380
397
};
381
398
```
382
399
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
-
OpenApiDocumentdocument=newOpenApiDocument
392
-
{
393
-
Components=newOpenApiComponents()
394
-
};
395
-
396
-
// After (2.0)
397
-
OpenApiDocumentdocument=newOpenApiDocument
398
-
{
399
-
Components=newOpenApiComponents()
400
-
{
401
-
Schemas=newDictionary<string, IOpenApiSchema?>()
402
-
}
403
-
};
404
-
405
-
```
406
-
407
400
#### 3. References as Components
408
401
409
402
References can now be used as components, allowing for more modular and reusable OpenAPI documents.
0 commit comments