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
+24-8Lines changed: 24 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@ author: rachit.malik
5
5
ms.author: malikrachit
6
6
ms.topic: conceptual
7
7
---
8
+
8
9
# Introduction
9
10
10
11
We are excited to announce the preview of a new version of the OpenAPI.NET library!
@@ -14,7 +15,7 @@ OpenAPI.NET v2 is a major update to the OpenAPI.NET library. This release includ
14
15
15
16
Since the release of the first version of the OpenAPI.NET library in 2018, there has not been a major version update to the library. With the addition of support for OpenAPI v3.1 it was necessary to make some breaking changes. With this opportunity, we have taken the time to make some other improvements to the library, based on the experience we have gained supporting a large community of users for the last six years .
16
17
17
-
# Performance Improvements
18
+
##Performance Improvements
18
19
19
20
One of the key features of OpenAPI.NET is its performance. This version makes it possible to parse JSON based OpenAPI descriptions even faster. OpenAPI.NET v1 relied on the excellent YamlSharp library for parsing both JSON and YAML files. With OpenAPI.NET v2 we are relying on System.Text.Json for parsing JSON files. For YAML files, we continue to use YamlSharp to parse YAML but then convert to JsonNodes for processing. This allows us to take advantage of the performance improvements in System.Text.Json while still supporting YAML files.
20
21
@@ -34,12 +35,14 @@ The v1 library attempted to mimic the pattern of `XmlTextReader` and `JsonTextRe
The same pattern can be used for `OpenApiStreamReader` and `OpenApiTextReader`. When we introduced the `ReadAsync` methods we eliminated the use of the `out` parameter.
38
40
39
41
```csharp
40
42
varreader=newOpenApiStreamReader();
41
43
var (document, diagnostics) =awaitreader.ReadAsync(streamOpenApiDoc);
42
44
```
45
+
43
46
A `ReadResult` object acts as a tuple of `OpenApiDocument` and `OpenApiDiagnostic`.
44
47
45
48
The challenge with this approach is that the reader classes are not very discoverable and the behaviour is not actually consistent with the `*TextReader` pattern that allows incrementally reading the document. This library does not support incrementally reading the OpenAPI Document. It only reads a complete document and returns an `OpenApiDocument` instance.
@@ -64,6 +67,7 @@ When the loading methods are used without a format parameter, we will attempt to
64
67
### Removing the OpenAPI Any classes
65
68
66
69
In the OpenAPI specification, there are a few properties that are defined as type `any`. This includes:
70
+
67
71
- the example property in the parameter, media type objects
68
72
- the value property in the example object
69
73
- the values in the link object's parameters dictionary and `requestBody` property
@@ -74,6 +78,7 @@ In the v1 library, there are a set of classes that are derived from the `OpenApi
74
78
In v2 we are removing this abstraction and relying on the `JsonNode` model to represent these inner types. In v1 we were not able to reliably identify the additional primitive types and it caused a significant amount of false negatives in error reporting as well as incorrectly parsed data values.
75
79
76
80
Due to `JsonNode` implicit operators, this makes initialization sometimes easier, instead of:
81
+
77
82
```csharp
78
83
newOpenApiParameter
79
84
{
@@ -83,7 +88,9 @@ Due to `JsonNode` implicit operators, this makes initialization sometimes easier
83
88
Example=newOpenApiFloat(5),
84
89
};
85
90
```
91
+
86
92
the assignment becomes simply,
93
+
87
94
```csharp
88
95
Example=0.5f,
89
96
```
@@ -128,12 +135,10 @@ In v2, the equivalent code would be,
128
135
129
136
```
130
137
131
-
132
138
### Updates to OpenApiSchema
133
139
134
140
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.
135
141
136
-
137
142
#### New keywords introduced in 2020-12
138
143
139
144
```csharp
@@ -155,6 +160,7 @@ The OpenAPI 3.1 specification changes significantly how it leverages JSON Schema
155
160
publicboolUnevaluatedProperties { get; set;}
156
161
157
162
```
163
+
158
164
#### Changes to existing keywords
159
165
160
166
```csharp
@@ -229,7 +235,6 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IOpenA
229
235
}
230
236
```
231
237
232
-
233
238
### License SPDX identifiers
234
239
235
240
```csharp
@@ -270,9 +275,12 @@ Through the use of proxy objects in order to represent references, it is now pos
270
275
Description="Customer Id"
271
276
};
272
277
```
278
+
273
279
### Use HTTP Method Object Instead of Enum
280
+
274
281
HTTP methods are now represented as objects instead of enums. This change enhances flexibility but requires updates to how HTTP methods are handled in your code.
275
282
Example:
283
+
276
284
```csharp
277
285
// Before (1.6)
278
286
OpenApiOperationoperation=newOpenApiOperation
@@ -288,9 +296,11 @@ OpenApiOperation operation = new OpenApiOperation
288
296
```
289
297
290
298
#### 2. Enable Null Reference Type Support
299
+
291
300
Version 2.0 preview 13 introduces support for null reference types, which improves type safety and reduces the likelihood of null reference exceptions.
292
301
293
302
**Example:**
303
+
294
304
```csharp
295
305
// Before (1.6)
296
306
OpenApiDocumentdocument=newOpenApiDocument
@@ -310,9 +320,11 @@ OpenApiDocument document = new OpenApiDocument
310
320
```
311
321
312
322
#### 3. References as Components
323
+
313
324
References can now be used as components, allowing for more modular and reusable OpenAPI documents.
314
325
315
326
**Example:**
327
+
316
328
```csharp
317
329
// Before (1.6)
318
330
OpenApiSchemaschema=newOpenApiSchema
@@ -338,6 +350,7 @@ OpenApiComponents components = new OpenApiComponents
338
350
```
339
351
340
352
### OpenApiDocument.SerializeAs()
353
+
341
354
The `SerializeAs()` method simplifies serialization scenarios, making it easier to convert OpenAPI documents to different formats.
0 commit comments