Skip to content

Commit 609dc7f

Browse files
committed
chore: linting
Signed-off-by: Vincent Biret <[email protected]>
1 parent bd8124e commit 609dc7f

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

docs/upgrade-guide-2.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ author: rachit.malik
55
ms.author: malikrachit
66
ms.topic: conceptual
77
---
8+
89
# Introduction
910

1011
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
1415

1516
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 .
1617

17-
# Performance Improvements
18+
## Performance Improvements
1819

1920
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.
2021

@@ -34,12 +35,14 @@ The v1 library attempted to mimic the pattern of `XmlTextReader` and `JsonTextRe
3435
var reader = new OpenApiStringReader();
3536
var openApiDoc = reader.Read(stringOpenApiDoc, out var diagnostic);
3637
```
38+
3739
The same pattern can be used for `OpenApiStreamReader` and `OpenApiTextReader`. When we introduced the `ReadAsync` methods we eliminated the use of the `out` parameter.
3840

3941
```csharp
4042
var reader = new OpenApiStreamReader();
4143
var (document, diagnostics) = await reader.ReadAsync(streamOpenApiDoc);
4244
```
45+
4346
A `ReadResult` object acts as a tuple of `OpenApiDocument` and `OpenApiDiagnostic`.
4447

4548
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
6467
### Removing the OpenAPI Any classes
6568

6669
In the OpenAPI specification, there are a few properties that are defined as type `any`. This includes:
70+
6771
- the example property in the parameter, media type objects
6872
- the value property in the example object
6973
- 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
7478
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.
7579

7680
Due to `JsonNode` implicit operators, this makes initialization sometimes easier, instead of:
81+
7782
```csharp
7883
new OpenApiParameter
7984
{
@@ -83,7 +88,9 @@ Due to `JsonNode` implicit operators, this makes initialization sometimes easier
8388
Example = new OpenApiFloat(5),
8489
};
8590
```
91+
8692
the assignment becomes simply,
93+
8794
```csharp
8895
Example = 0.5f,
8996
```
@@ -128,12 +135,10 @@ In v2, the equivalent code would be,
128135

129136
```
130137

131-
132138
### Updates to OpenApiSchema
133139

134140
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.
135141

136-
137142
#### New keywords introduced in 2020-12
138143

139144
```csharp
@@ -155,6 +160,7 @@ The OpenAPI 3.1 specification changes significantly how it leverages JSON Schema
155160
public bool UnevaluatedProperties { get; set;}
156161

157162
```
163+
158164
#### Changes to existing keywords
159165

160166
```csharp
@@ -229,7 +235,6 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IOpenA
229235
}
230236
```
231237

232-
233238
### License SPDX identifiers
234239

235240
```csharp
@@ -270,9 +275,12 @@ Through the use of proxy objects in order to represent references, it is now pos
270275
Description = "Customer Id"
271276
};
272277
```
278+
273279
### Use HTTP Method Object Instead of Enum
280+
274281
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.
275282
Example:
283+
276284
```csharp
277285
// Before (1.6)
278286
OpenApiOperation operation = new OpenApiOperation
@@ -288,9 +296,11 @@ OpenApiOperation operation = new OpenApiOperation
288296
```
289297

290298
#### 2. Enable Null Reference Type Support
299+
291300
Version 2.0 preview 13 introduces support for null reference types, which improves type safety and reduces the likelihood of null reference exceptions.
292301

293302
**Example:**
303+
294304
```csharp
295305
// Before (1.6)
296306
OpenApiDocument document = new OpenApiDocument
@@ -310,9 +320,11 @@ OpenApiDocument document = new OpenApiDocument
310320
```
311321

312322
#### 3. References as Components
323+
313324
References can now be used as components, allowing for more modular and reusable OpenAPI documents.
314325

315326
**Example:**
327+
316328
```csharp
317329
// Before (1.6)
318330
OpenApiSchema schema = new OpenApiSchema
@@ -338,6 +350,7 @@ OpenApiComponents components = new OpenApiComponents
338350
```
339351

340352
### OpenApiDocument.SerializeAs()
353+
341354
The `SerializeAs()` method simplifies serialization scenarios, making it easier to convert OpenAPI documents to different formats.
342355
**Example:**
343356

@@ -349,9 +362,11 @@ string json = document.SerializeAs(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.
349362

350363
### Bug Fixes
351364

352-
## Serialization of References:
365+
## Serialization of References
366+
353367
Fixed a bug where references would not serialize summary or descriptions in OpenAPI 3.1.
354368
**Example:**
369+
355370
```csharp
356371
OpenApiSchemaReference schemaRef = new OpenApiSchemaReference("MySchema")
357372
{
@@ -360,6 +375,7 @@ OpenApiSchemaReference schemaRef = new OpenApiSchemaReference("MySchema")
360375
};
361376
```
362377

363-
## Feedback
364-
If you have any feedback please file a GitHub issue here: https://github.com/microsoft/OpenAPI.NET/issues
365-
The team is looking forward to hear your experience trying the new version and we hope you have fun busting out your OpenAPI 3.1 descriptions.
378+
## Feedback
379+
380+
If you have any feedback please file a GitHub issue [here](https://github.com/microsoft/OpenAPI.NET/issues)
381+
The team is looking forward to hear your experience trying the new version and we hope you have fun busting out your OpenAPI 3.1 descriptions.

0 commit comments

Comments
 (0)