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
Add warning for ASP.NET Core version < 10.0 (#2451)
* Add warning for ASP.NET Core version `< 10.0`
docs: Remove trailing and unnecessary white space
docs: Typo correction of British English `behaviour` to American English `behavior`
docs: Fix basic markdown lint issues
docs: Fix some more white space
Copy file name to clipboardExpand all lines: docs/upgrade-guide-2.md
+39-31Lines changed: 39 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -1,27 +1,30 @@
1
1
---
2
-
title: Upgrade guide to OpenAPI.NET 2.1
3
-
description: Learn how to upgrade your OpenAPI.NET version from 1.6 to 2.0
2
+
title: Upgrade guide to OpenAPI.NET 2.0
3
+
description: Learn how to upgrade your OpenAPI.NET version from 1.6 to 2.0
4
4
author: rachit.malik
5
5
ms.author: malikrachit
6
6
ms.topic: conceptual
7
7
---
8
8
9
9
# Introduction
10
10
11
-
We are excited to announce the new version of the OpenAPI.NET library!
11
+
We are excited to announce the new version of the OpenAPI.NET library!
12
12
OpenAPI.NET v2 is a major update to the OpenAPI.NET library. This release includes a number of performance improvements, API enhancements, and support for OpenAPI v3.1.
13
13
14
+
> [!WARNING]
15
+
> If you are using this library with ASP.NET Core version `< 10.0` then you must remain on version `1.x` as it's not compatible.
16
+
14
17
## The biggest update ever
15
18
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.
19
+
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.
17
20
18
21
## Performance Improvements
19
22
20
23
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.
21
24
22
25
In v1, instances of `$ref` were resolved in a second pass of the document to ensure the target of the reference has been parsed before attempting to resolve it. In v2, reference targets are lazily resolved when reference objects are accessed. This improves load time performance for documents that make heavy use of references.
23
26
24
-
[How does this change the behaviour of external references?]
27
+
[How does this change the behavior of external references?]
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.
101
+
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.
99
102
100
103
Once the dependency is added, the reader needs to be added to the reader settings as demonstrated below
The same pattern can be used for `OpenApiStreamReader` and `OpenApiTextReader`. When we introduced the `ReadAsync` methods we eliminated the use of the `out` parameter. To improve code readability, we've added deconstruction support to `ReadResult`. The properties also have been renamed to avoid confusion with their types.
123
+
The same pattern can be used for `OpenApiStreamReader` and `OpenApiTextReader`. When we introduced the `ReadAsync` methods we eliminated the use of the `out` parameter. To improve code readability, we've added deconstruction support to `ReadResult`. The properties also have been renamed to avoid confusion with their types.
121
124
122
125
```csharp
123
126
varreader=newOpenApiStreamReader();
@@ -130,7 +133,7 @@ var diagnostics = result.Diagnostics;
130
133
131
134
A `ReadResult` object acts as a tuple of `OpenApiDocument` and `OpenApiDiagnostic`.
132
135
133
-
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.
136
+
The challenge with this approach is that the reader classes are not very discoverable and the behavior 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.
134
137
135
138
In the v2 library we are moving to the pattern used by classes like `XDocument` where a set of static `Load` and `Parse` methods are used as factory methods.
136
139
@@ -143,11 +146,11 @@ public class OpenApiDocument {
143
146
}
144
147
```
145
148
146
-
This API design allows a developer to use IDE autocomplete to present all the loading options by simply knowing the name of the `OpenApiDocument` class. Each of these methods are layered on top of the more primitive methods to ensure consistent behaviour.
149
+
This API design allows a developer to use IDE autocomplete to present all the loading options by simply knowing the name of the `OpenApiDocument` class. Each of these methods are layered on top of the more primitive methods to ensure consistent behavior.
147
150
148
-
As the YAML format is only supported when including the `Microsoft.OpenApi.YamlReader` library it was decided not to use an enum for the `format` parameter. We are considering implementing a more [strongly typed solution](https://github.com/microsoft/OpenAPI.NET/issues/1952) similar to the way that `HttpMethod` is implemented so that we have a strongly typed experience that is also extensible.
151
+
As the YAML format is only supported when including the `Microsoft.OpenApi.YamlReader` library it was decided not to use an enum for the `format` parameter. We are considering implementing a more [strongly typed solution](https://github.com/microsoft/OpenAPI.NET/issues/1952) similar to the way that `HttpMethod` is implemented so that we have a strongly typed experience that is also extensible.
149
152
150
-
When the loading methods are used without a format parameter, we will attempt to parse the document using the default JSON reader. If that fails and the YAML reader is registered, then we will attempt to read as YAML. The goal is always to provide the fastest path with JSON but still maintain the convenience of not having to care whether a URL points to YAML or JSON if you need that flexibility.
153
+
When the loading methods are used without a format parameter, we will attempt to parse the document using the default JSON reader. If that fails and the YAML reader is registered, then we will attempt to read as YAML. The goal is always to provide the fastest path with JSON but still maintain the convenience of not having to care whether a URL points to YAML or JSON if you need that flexibility.
151
154
152
155
### Additional exceptions
153
156
@@ -281,7 +284,7 @@ var info = schema.Metadata["foo"];
281
284
282
285
### Updates to OpenApiSchema
283
286
284
-
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.
287
+
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.
285
288
286
289
#### New keywords introduced in 2020-12
287
290
@@ -308,24 +311,24 @@ public bool UnevaluatedProperties { get; set;}
308
311
#### Changes to existing keywords
309
312
310
313
```csharp
311
-
publicstring?ExclusiveMaximum { get; set; } // type changed to reflect the new version of JSON schema
314
+
publicstring?ExclusiveMaximum { get; set; } // type changed to reflect the new version of JSON schema
312
315
publicstring?ExclusiveMinimum { get; set; } // type changed to reflect the new version of JSON schema
313
-
publicJsonSchemaType?Type { get; set; } // Was string, now flagged enum
316
+
publicJsonSchemaType?Type { get; set; } // Was string, now flagged enum
314
317
publicstring?Maximum { get; set; } // type changed to overcome double vs decimal issues
315
318
publicstring?Minimum { get; set; } // type changed to overcome double vs decimal issues
316
319
317
-
publicJsonNodeDefault { get; set; } // Type matching no longer enforced. Was IOpenApiAny
318
-
publicboolReadOnly { get; set; } // No longer has defined semantics in OpenAPI 3.1
319
-
publicboolWriteOnly { get; set; } // No longer has defined semantics in OpenAPI 3.1
320
+
publicJsonNodeDefault { get; set; } // Type matching no longer enforced. Was IOpenApiAny
321
+
publicboolReadOnly { get; set; } // No longer has defined semantics in OpenAPI 3.1
322
+
publicboolWriteOnly { get; set; } // No longer has defined semantics in OpenAPI 3.1
320
323
321
-
publicJsonNodeExample { get; set; } // No longer IOpenApiAny
324
+
publicJsonNodeExample { get; set; } // No longer IOpenApiAny
publicIDictionary<string, object>Metadata { get; set; } // Custom property bag to be used by the application, used to be named annotations
331
+
publicIDictionary<string, object>Metadata { get; set; } // Custom property bag to be used by the application, used to be named annotations
329
332
```
330
333
331
334
#### OpenApiSchema methods
@@ -349,7 +352,8 @@ public class OpenApiSchema : IMetadataContainer, IOpenApiExtensible, IOpenApiRef
349
352
There are a number of new features in OpenAPI v3.1 that are now supported in OpenAPI.NET.
350
353
351
354
### JsonSchema Dialect and BaseUri in OpenApiDocument
352
-
To enable full compatibility with JSON Schema, the `OpenApiDocument` class now supports a `JsonSchemaDialect` property. This property specifies the JSON Schema dialect used throughout the document, using a URI. By explicitly declaring the dialect, tooling can be directed to use a JSON Schema version other than the default [2020-12 draft](https://json-schema.org/draft/2020-12/json-schema-core.html). However, OpenAPI.NET does not guarantee compatibility with versions other than 2020-12.
355
+
356
+
To enable full compatibility with JSON Schema, the `OpenApiDocument` class now supports a `JsonSchemaDialect` property. This property specifies the JSON Schema dialect used throughout the document, using a URI. By explicitly declaring the dialect, tooling can be directed to use a JSON Schema version other than the default [2020-12 draft](https://json-schema.org/draft/2020-12/json-schema-core.html). However, OpenAPI.NET does not guarantee compatibility with versions other than 2020-12.
353
357
354
358
In addition, a `BaseUri` property has been added to represent the identity of the OpenAPI document. If the document’s identity is not provided or cannot be determined at based on its ___location, this property will be set to a generated placeholder URI.
355
359
@@ -375,7 +379,7 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IMetada
@@ -605,6 +611,7 @@ All the `IEffective` and `GetEffective` infrastructure in the models have been r
605
611
Copy constructors for referenceable components have been made internal, a new `CreateShallowCopy()` method has been exposed on these models to facilitate cloning.
606
612
607
613
**Example:**
614
+
608
615
```csharp
609
616
varschema=newOpenApiSchema();
610
617
varschemaCopy=schema.CreateShallowCopy();
@@ -619,6 +626,7 @@ The redundant _style property on the Parameter model has been removed to simplif
619
626
Discriminator mappings have been updated from using a `Dictionary<string, string>` to a `Dictionary<string, OpenApiSchemaReference>`. This change improves the handling of discriminator mappings by referencing OpenAPI schema components more explicitly, which enhances schema resolution.
620
627
621
628
**Example:**
629
+
622
630
```csharp
623
631
// v1.6.x
624
632
Discriminator=new()
@@ -660,5 +668,5 @@ OpenApiSchemaReference schemaRef = new OpenApiSchemaReference("MySchema")
660
668
661
669
## Feedback
662
670
663
-
If you have any feedback please file a GitHub issue[here](https://github.com/microsoft/OpenAPI.NET/issues)
671
+
If you have any feedback please file [a new GitHub issue](https://github.com/microsoft/OpenAPI.NET/issues)
664
672
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