Skip to content

Commit 8a48a77

Browse files
committed
Use ternary operator and compound assignment.
1 parent f9aea51 commit 8a48a77

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,9 @@ internal static partial class OpenApiV2Deserializer
5959
"definitions",
6060
(o, n) =>
6161
{
62-
if (o.Components == null)
63-
{
64-
o.Components = new();
65-
}
66-
67-
o.Components.Schemas = n.CreateJsonSchemaMapWithReference(ReferenceType.Schema, LoadSchema, OpenApiSpecVersion.OpenApi2_0); }
62+
o.Components ??= new();
63+
o.Components.Schemas = n.CreateJsonSchemaMapWithReference(ReferenceType.Schema, LoadSchema, OpenApiSpecVersion.OpenApi2_0);
64+
}
6865
},
6966
{
7067
"parameters",

src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -594,15 +594,9 @@ public void WriteJsonSchemaWithoutReference(IOpenApiWriter writer, JsonSchema sc
594594
/// <inheritdoc />
595595
public void WriteJsonSchemaReference(IOpenApiWriter writer, Uri referenceUri, OpenApiSpecVersion version)
596596
{
597-
var reference = String.Empty;
598-
if (version.Equals(OpenApiSpecVersion.OpenApi2_0))
599-
{
600-
reference = referenceUri.OriginalString.Replace("components/schemas", "definitions");
601-
}
602-
else
603-
{
604-
reference = referenceUri.OriginalString;
605-
}
597+
var reference = version.Equals(OpenApiSpecVersion.OpenApi2_0)
598+
? referenceUri.OriginalString.Replace("components/schemas", "definitions")
599+
: referenceUri.OriginalString;
606600

607601
WriteStartObject();
608602
this.WriteProperty(OpenApiConstants.DollarRef, reference);

0 commit comments

Comments
 (0)