Skip to content

Commit 1994320

Browse files
authored
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
1 parent 15ece47 commit 1994320

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

docs/upgrade-guide-2.md

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
---
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
44
author: rachit.malik
55
ms.author: malikrachit
66
ms.topic: conceptual
77
---
88

99
# Introduction
1010

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!
1212
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.
1313

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+
1417
## The biggest update ever
1518

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.
1720

1821
## Performance Improvements
1922

2023
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.
2124

2225
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.
2326

24-
[How does this change the behaviour of external references?]
27+
[How does this change the behavior of external references?]
2528

2629
### Results
2730

@@ -95,15 +98,15 @@ mySchema.AnyOf = new List<IOpenApiSchema> { otherSchema };
9598

9699
## Reduced Dependencies
97100

98-
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.
99102

100103
Once the dependency is added, the reader needs to be added to the reader settings as demonstrated below
101104

102105
```csharp
103-
var settings = new OpenApiReaderSettings();
104-
settings.AddYamlReader();
106+
var settings = new OpenApiReaderSettings();
107+
settings.AddYamlReader();
105108

106-
var result = OpenApiDocument.LoadAsync(openApiString, settings: settings);
109+
var result = OpenApiDocument.LoadAsync(openApiString, settings: settings);
107110
```
108111

109112
## API Enhancements
@@ -117,7 +120,7 @@ var reader = new OpenApiStringReader();
117120
var openApiDoc = reader.Read(stringOpenApiDoc, out var diagnostic);
118121
```
119122

120-
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.
121124

122125
```csharp
123126
var reader = new OpenApiStreamReader();
@@ -130,7 +133,7 @@ var diagnostics = result.Diagnostics;
130133

131134
A `ReadResult` object acts as a tuple of `OpenApiDocument` and `OpenApiDiagnostic`.
132135

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.
134137

135138
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.
136139

@@ -143,11 +146,11 @@ public class OpenApiDocument {
143146
}
144147
```
145148

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.
147150

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.
149152

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.
151154

152155
### Additional exceptions
153156

@@ -281,7 +284,7 @@ var info = schema.Metadata["foo"];
281284

282285
### Updates to OpenApiSchema
283286

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.
285288

286289
#### New keywords introduced in 2020-12
287290

@@ -308,24 +311,24 @@ public bool UnevaluatedProperties { get; set;}
308311
#### Changes to existing keywords
309312

310313
```csharp
311-
public string? ExclusiveMaximum { get; set; } // type changed to reflect the new version of JSON schema
314+
public string? ExclusiveMaximum { get; set; } // type changed to reflect the new version of JSON schema
312315
public string? ExclusiveMinimum { get; set; } // type changed to reflect the new version of JSON schema
313-
public JsonSchemaType? Type { get; set; } // Was string, now flagged enum
316+
public JsonSchemaType? Type { get; set; } // Was string, now flagged enum
314317
public string? Maximum { get; set; } // type changed to overcome double vs decimal issues
315318
public string? Minimum { get; set; } // type changed to overcome double vs decimal issues
316319
317-
public JsonNode Default { get; set; } // Type matching no longer enforced. Was IOpenApiAny
318-
public bool ReadOnly { get; set; } // No longer has defined semantics in OpenAPI 3.1
319-
public bool WriteOnly { get; set; } // No longer has defined semantics in OpenAPI 3.1
320+
public JsonNode Default { get; set; } // Type matching no longer enforced. Was IOpenApiAny
321+
public bool ReadOnly { get; set; } // No longer has defined semantics in OpenAPI 3.1
322+
public bool WriteOnly { get; set; } // No longer has defined semantics in OpenAPI 3.1
320323
321-
public JsonNode Example { get; set; } // No longer IOpenApiAny
324+
public JsonNode Example { get; set; } // No longer IOpenApiAny
322325
public IList<JsonNode> Examples { get; set; }
323326
public IList<JsonNode> Enum { get; set; }
324-
public OpenApiExternalDocs ExternalDocs { get; set; } // OpenApi Vocab
325-
public bool Deprecated { get; set; } // OpenApi Vocab
326-
public OpenApiXml Xml { get; set; } // OpenApi Vocab
327+
public OpenApiExternalDocs ExternalDocs { get; set; } // OpenApi Vocab
328+
public bool Deprecated { get; set; } // OpenApi Vocab
329+
public OpenApiXml Xml { get; set; } // OpenApi Vocab
327330
328-
public IDictionary<string, object> Metadata { get; set; } // Custom property bag to be used by the application, used to be named annotations
331+
public IDictionary<string, object> Metadata { get; set; } // Custom property bag to be used by the application, used to be named annotations
329332
```
330333

331334
#### OpenApiSchema methods
@@ -349,7 +352,8 @@ public class OpenApiSchema : IMetadataContainer, IOpenApiExtensible, IOpenApiRef
349352
There are a number of new features in OpenAPI v3.1 that are now supported in OpenAPI.NET.
350353

351354
### 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.
353357

354358
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.
355359

@@ -375,7 +379,7 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IMetada
375379

376380
```csharp
377381

378-
public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IOpenApiMetadataContainer
382+
public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IOpenApiMetadataContainer
379383
{
380384
public IDictionary<string, OpenApiPathItem>? Webhooks { get; set; } = new Dictionary<string, OpenApiPathItem>();
381385
}
@@ -510,7 +514,7 @@ string json = await document.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, OpenA
510514

511515
```csharp
512516
// Before (1.6)
513-
var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json);
517+
var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json);
514518

515519
// After (2.0)
516520
var outputString = await openApiDocument.SerializeAsync(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json);
@@ -521,6 +525,7 @@ var outputString = await openApiDocument.SerializeAsync(OpenApiSpecVersion.OpenA
521525
In v2.0, the Type property in `OpenApiSchema` is now defined as a flaggable enum, allowing consumers to swap nullable for type arrays.
522526

523527
**Example:**
528+
524529
```csharp
525530
// v1.6.x
526531
var schema = new OpenApiSchema
@@ -533,7 +538,7 @@ var schema = new OpenApiSchema
533538
// bitwise OR(|) - combines flags to allow multiple types
534539
var schema = new OpenApiSchema
535540
{
536-
Type = JsonSchemaType.String | JsonSchemaType.Null
541+
Type = JsonSchemaType.String | JsonSchemaType.Null
537542
}
538543

539544
// bitwise NOT(~) - inverts bits; filters out null flag
@@ -545,7 +550,7 @@ var schema = new OpenApiSchema
545550
// bitwise AND(&) - intersects flags to check for a specific type
546551
var schema = new OpenApiSchema
547552
{
548-
Type = (JsonSchemaType.String & JsonSchemaType.Null) == JsonSchemaType.Null
553+
Type = (JsonSchemaType.String & JsonSchemaType.Null) == JsonSchemaType.Null
549554
}
550555

551556
```
@@ -588,6 +593,7 @@ This resolver class has been removed in favor of a more streamlined resolution m
588593
### Visitor and Validator now pass an interface model
589594

590595
**Example:**
596+
591597
```csharp
592598
//v1.6.x
593599
public override void Visit(OpenApiParameter parameter){}
@@ -605,6 +611,7 @@ All the `IEffective` and `GetEffective` infrastructure in the models have been r
605611
Copy constructors for referenceable components have been made internal, a new `CreateShallowCopy()` method has been exposed on these models to facilitate cloning.
606612

607613
**Example:**
614+
608615
```csharp
609616
var schema = new OpenApiSchema();
610617
var schemaCopy = schema.CreateShallowCopy();
@@ -619,6 +626,7 @@ The redundant _style property on the Parameter model has been removed to simplif
619626
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.
620627

621628
**Example:**
629+
622630
```csharp
623631
// v1.6.x
624632
Discriminator = new()
@@ -660,5 +668,5 @@ OpenApiSchemaReference schemaRef = new OpenApiSchemaReference("MySchema")
660668

661669
## Feedback
662670

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)
664672
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)