Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1b86cec

Browse files
committedApr 16, 2025·
resolve PR comments
1 parent 8ad002d commit 1b86cec

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed
 

‎docs/upgrade-guide-2.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,24 @@ The `SerializeAs()` method simplifies serialization scenarios, making it easier
487487

488488
```csharp
489489
OpenApiDocument document = new OpenApiDocument();
490-
string json = document.SerializeAs(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Json);
490+
string json = document.SerializeAs(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Json);
491491

492492
```
493493

494+
### Use OpenApiConstants string Instead of OpenApiFormat Enum
495+
496+
OpenApiConstants are now used instead of OpenApiFormat enums.
497+
498+
**Example:**
499+
500+
```csharp
501+
// Before (1.6)
502+
var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json);
503+
504+
// After (2.0)
505+
var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json);
506+
```
507+
494508
### Bug Fixes
495509

496510
## Serialization of References

‎src/Microsoft.OpenApi.Hidi/OpenApiService.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ private static async Task WriteOpenApiAsync(HidiOptions options, string openApiF
202202
InlineLocalReferences = options.InlineLocal,
203203
InlineExternalReferences = options.InlineExternal
204204
};
205-
206-
IOpenApiWriter writer = openApiFormat switch
205+
#pragma warning disable CA1308
206+
IOpenApiWriter writer = openApiFormat.ToLowerInvariant() switch
207+
#pragma warning restore CA1308
207208
{
208209
OpenApiConstants.Json => options.TerseOutput ? new(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false),
209210
OpenApiConstants.Yaml => new OpenApiYamlWriter(textWriter, settings),

‎src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static Task SerializeAsync<T>(
9191

9292
var streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture);
9393

94-
IOpenApiWriter writer = format switch
94+
IOpenApiWriter writer = format.ToLowerInvariant() switch
9595
{
9696
OpenApiConstants.Json => new OpenApiJsonWriter(streamWriter, settings, false),
9797
OpenApiConstants.Yaml => new OpenApiYamlWriter(streamWriter, settings),

0 commit comments

Comments
 (0)
Please sign in to comment.