Skip to content

Commit 2f7cd05

Browse files
committed
docs: add information about read result deconstruction
Signed-off-by: Vincent Biret <[email protected]>
1 parent e0e0448 commit 2f7cd05

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

docs/upgrade-guide-2.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,24 @@ var result = OpenApiDocument.LoadAsync(openApiString, settings: settings);
8585

8686
## API Enhancements
8787

88+
### Loading the document
89+
8890
The v1 library attempted to mimic the pattern of `XmlTextReader` and `JsonTextReader` for the purpose of loading OpenAPI documents from strings, streams and text readers.
8991

9092
```csharp
91-
var reader = new OpenApiStringReader();
92-
var openApiDoc = reader.Read(stringOpenApiDoc, out var diagnostic);
93+
var reader = new OpenApiStringReader();
94+
var openApiDoc = reader.Read(stringOpenApiDoc, out var diagnostic);
9395
```
9496

95-
The same pattern can be used for `OpenApiStreamReader` and `OpenApiTextReader`. When we introduced the `ReadAsync` methods we eliminated the use of the `out` parameter.
97+
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.
9698

9799
```csharp
98-
var reader = new OpenApiStreamReader();
99-
var (document, diagnostics) = await reader.ReadAsync(streamOpenApiDoc);
100+
var reader = new OpenApiStreamReader();
101+
var (document, diagnostics) = await reader.ReadAsync(streamOpenApiDoc);
102+
// or
103+
var result = await reader.ReadAsync(streamOpenApiDoc);
104+
var document = result.Document;
105+
var diagnostics = result.Diagnostics;
100106
```
101107

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

0 commit comments

Comments
 (0)