Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8b91278

Browse files
committed
fix: use settings for terse output in serialization extension methods
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent9b11f2e commit8b91278

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,17 @@ private static async Task WriteOpenApiAsync(HidiOptions options, string openApiF
192192
usingvaroutputStream=options.Output.Create();
193193
usingvartextWriter=newStreamWriter(outputStream);
194194

195-
varsettings=newOpenApiWriterSettings
195+
varsettings=newOpenApiJsonWriterSettings
196196
{
197197
InlineLocalReferences=options.InlineLocal,
198-
InlineExternalReferences=options.InlineExternal
198+
InlineExternalReferences=options.InlineExternal,
199+
Terse=options.TerseOutput
199200
};
200201
#pragma warning disableCA1308
201202
IOpenApiWriterwriter=openApiFormat.ToLowerInvariant()switch
202203
#pragma warning restoreCA1308
203204
{
204-
OpenApiConstants.Json=>options.TerseOutput?new(textWriter,settings,options.TerseOutput):newOpenApiJsonWriter(textWriter,settings,false),
205+
OpenApiConstants.Json=>newOpenApiJsonWriter(textWriter,settings),
205206
OpenApiConstants.Yaml=>newOpenApiYamlWriter(textWriter,settings),
206207
_=>thrownewArgumentException("Unknown format"),
207208
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public static Task SerializeAsync<T>(
8888

8989
IOpenApiWriterwriter=format.ToLowerInvariant()switch
9090
{
91-
OpenApiConstants.Json=>newOpenApiJsonWriter(streamWriter,settings,false),
91+
OpenApiConstants.JsonwhensettingsisOpenApiJsonWriterSettingsjsonSettings=>newOpenApiJsonWriter(streamWriter,jsonSettings),
92+
OpenApiConstants.Json=>newOpenApiJsonWriter(streamWriter,settings),
9293
OpenApiConstants.Yaml=>newOpenApiYamlWriter(streamWriter,settings),
9394
_=>thrownewOpenApiException(string.Format(SRResource.OpenApiFormatNotSupported,format)),
9495
};

‎src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
usingSystem;
5+
usingSystem.ComponentModel;
46
usingSystem.IO;
57

68
namespaceMicrosoft.OpenApi
@@ -14,7 +16,17 @@ public class OpenApiJsonWriter : OpenApiWriterBase
1416
/// Initializes a new instance of the <see cref="OpenApiJsonWriter"/> class.
1517
/// </summary>
1618
/// <param name="textWriter">The text writer.</param>
17-
publicOpenApiJsonWriter(TextWritertextWriter):base(textWriter,null)
19+
publicOpenApiJsonWriter(TextWritertextWriter):this(textWriter,(OpenApiWriterSettings?)null)
20+
{
21+
// this constructor is kept for binary compatibility
22+
// TODO remove in next major version and make the settings an optional parameter in the other constructor
23+
}
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="OpenApiJsonWriter"/> class.
26+
/// </summary>
27+
/// <param name="settings">Settings for controlling how the OpenAPI document will be written out.</param>
28+
/// <param name="textWriter">The text writer.</param>
29+
publicOpenApiJsonWriter(TextWritertextWriter,OpenApiWriterSettings?settings):base(textWriter,settings??newOpenApiJsonWriterSettings())
1830
{
1931
}
2032

@@ -34,9 +46,13 @@ public OpenApiJsonWriter(TextWriter textWriter, OpenApiJsonWriterSettings settin
3446
/// <param name="textWriter">The text writer.</param>
3547
/// <param name="settings">Settings for controlling how the OpenAPI document will be written out.</param>
3648
/// <param name="terseOutput"> Setting for allowing the JSON emitted to be in terse format.</param>
37-
publicOpenApiJsonWriter(TextWritertextWriter,OpenApiWriterSettings?settings,boolterseOutput=false):base(textWriter,settings)
49+
[Obsolete("Use OpenApiJsonWriter(TextWriter textWriter, OpenApiJsonWriterSettings settings) instead.")]
50+
[EditorBrowsable(EditorBrowsableState.Never)]
51+
publicOpenApiJsonWriter(TextWritertextWriter,OpenApiWriterSettings?settings,boolterseOutput):base(textWriter,settings)
3852
{
3953
_produceTerseOutput=terseOutput;
54+
// this constructor is kept for binary compatibility, terse information should be read from the settings to avoid fork APIs.
55+
// TODO remove in next major version
4056
}
4157

4258
/// <summary>

‎src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ protected OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings? settin
5555
Writer.NewLine="\n";
5656

5757
Scopes=new();
58-
if(settings==null)
59-
{
60-
settings=new();
61-
}
58+
settings??=new();
6259
Settings=settings;
6360
}
6461

‎test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,10 @@ namespace Microsoft.OpenApi
795795
{
796796
public OpenApiJsonWriter(System.IO.TextWriter textWriter) { }
797797
public OpenApiJsonWriter(System.IO.TextWriter textWriter, Microsoft.OpenApi.OpenApiJsonWriterSettings settings) { }
798-
public OpenApiJsonWriter(System.IO.TextWriter textWriter, Microsoft.OpenApi.OpenApiWriterSettings? settings, bool terseOutput = false) { }
798+
public OpenApiJsonWriter(System.IO.TextWriter textWriter, Microsoft.OpenApi.OpenApiWriterSettings? settings) { }
799+
[System.Obsolete("Use OpenApiJsonWriter(TextWriter textWriter, OpenApiJsonWriterSettings settings) " +
800+
"instead.")]
801+
public OpenApiJsonWriter(System.IO.TextWriter textWriter, Microsoft.OpenApi.OpenApiWriterSettings? settings, bool terseOutput) { }
799802
protected override int BaseIndentation { get; }
800803
public override void WriteEndArray() { }
801804
public override void WriteEndObject() { }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp