Skip to content

Commit 6cd8a82

Browse files
committed
Code cleanup and refactoring
1 parent 5d69eda commit 6cd8a82

6 files changed

+18
-10
lines changed

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

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

44
using System;
@@ -42,7 +42,7 @@ internal static partial class OpenApiV2Deserializer
4242
private static readonly PatternFieldMap<OpenApiResponse> _responsePatternFields =
4343
new()
4444
{
45-
{s => s.StartsWith("x-") && !s.Equals(OpenApiConstants.ExamplesExtension), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))}
45+
{s => s.StartsWith("x-") && !s.Equals(OpenApiConstants.ExamplesExtension, StringComparison.OrdinalIgnoreCase), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))}
4646
};
4747

4848
private static readonly AnyFieldMap<OpenApiMediaType> _mediaTypeAnyFields =
@@ -125,7 +125,7 @@ private static void LoadExamplesExtension(OpenApiResponse response, ParseNode no
125125
example.Description = valueNode.Value.GetScalarValue();
126126
break;
127127
case "value":
128-
example.Value = valueNode.Value.CreateAny();
128+
example.Value = OpenApiAnyConverter.GetSpecificOpenApiAny(valueNode.Value.CreateAny());
129129
break;
130130
case "externalValue":
131131
example.ExternalValue = valueNode.Value.GetScalarValue();

src/Microsoft.OpenApi/Models/OpenApiParameter.cs

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

44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using Microsoft.OpenApi.Any;
78
using Microsoft.OpenApi.Extensions;
89
using Microsoft.OpenApi.Interfaces;

src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs

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

44
using System;
@@ -145,7 +145,7 @@ internal OpenApiBodyParameter ConvertToBodyParameter()
145145
// V2 spec actually allows the body to have custom name.
146146
// To allow round-tripping we use an extension to hold the name
147147
Name = "body",
148-
Schema = Content.Values.FirstOrDefault()?.Schema ?? new JsonSchemaBuilder().Build(),
148+
Schema = Content.Values.FirstOrDefault()?.Schema ?? new OpenApiSchema(),
149149
Examples = Content.Values.FirstOrDefault()?.Examples,
150150
Required = Required,
151151
Extensions = Extensions.ToDictionary(static k => k.Key, static v => v.Value) // Clone extensions so we can remove the x-bodyName extensions from the output V2 model.
@@ -179,7 +179,7 @@ internal IEnumerable<OpenApiFormDataParameter> ConvertToFormDataParameters()
179179
Name = property.Key,
180180
Schema = property.Value,
181181
Examples = Content.Values.FirstOrDefault()?.Examples,
182-
Required = Content.First().Value.Schema.GetRequired()?.Contains(property.Key) ?? false
182+
Required = Content.First().Value.Schema.Required?.Contains(property.Key) ?? false
183183
};
184184
}
185185
}

src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs

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

44
using System;
55
using System.Collections.Generic;
66
using System.IO;
77
using Microsoft.OpenApi.Exceptions;
8+
using Microsoft.OpenApi.Models;
89
using Microsoft.OpenApi.Properties;
910

1011
namespace Microsoft.OpenApi.Writers

test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.SerializeParameterWithSchemaReferenceAsV2JsonWorksAsync_produceTerseOutput=False.verified.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
"name": "name1",
44
"description": "description1",
55
"required": true,
6-
"type": "string"
6+
"type": "string",
7+
"x-examples": {
8+
"test": {
9+
"summary": "summary3",
10+
"description": "description3"
11+
}
12+
}
713
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"in":"header","name":"name1","description":"description1","required":true,"type":"string"}
1+
{"in":"header","name":"name1","description":"description1","required":true,"type":"string","x-examples":{"test":{"summary":"summary3","description":"description3"}}}

0 commit comments

Comments
 (0)