Skip to content

Commit f3772ee

Browse files
committed
Code clean up
1 parent 49435c0 commit f3772ee

23 files changed

+113
-83
lines changed

src/Microsoft.OpenApi.Readers/OpenApiReaderSettings.cs

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

4-
using Microsoft.OpenApi.Any;
54
using Microsoft.OpenApi.Interfaces;
65
using Microsoft.OpenApi.Readers.Interface;
76
using Microsoft.OpenApi.Validations;
87
using System;
98
using System.Collections.Generic;
109
using System.IO;
10+
using System.Text.Json.Nodes;
1111

1212
namespace Microsoft.OpenApi.Readers
1313
{
@@ -49,7 +49,7 @@ public class OpenApiReaderSettings
4949
/// <summary>
5050
/// Dictionary of parsers for converting extensions into strongly typed classes
5151
/// </summary>
52-
public Dictionary<string, Func<IOpenApiAny, OpenApiSpecVersion, IOpenApiExtension>> ExtensionParsers { get; set; } = new Dictionary<string, Func<IOpenApiAny, OpenApiSpecVersion, IOpenApiExtension>>();
52+
public Dictionary<string, Func<JsonNode, OpenApiSpecVersion, IOpenApiExtension>> ExtensionParsers { get; set; } = new Dictionary<string, Func<JsonNode, OpenApiSpecVersion, IOpenApiExtension>>();
5353

5454
/// <summary>
5555
/// Rules to use for validating OpenAPI specification. If none are provided a default set of rules are applied.

src/Microsoft.OpenApi.Readers/ParseNodes/AnyFieldMapParameter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license.
33

44
using System;
5-
using Microsoft.OpenApi.Any;
5+
using System.Text.Json.Nodes;
66
using Microsoft.OpenApi.Models;
77

88
namespace Microsoft.OpenApi.Readers.ParseNodes
@@ -13,8 +13,8 @@ internal class AnyFieldMapParameter<T>
1313
/// Constructor.
1414
/// </summary>
1515
public AnyFieldMapParameter(
16-
Func<T, IOpenApiAny> propertyGetter,
17-
Action<T, IOpenApiAny> propertySetter,
16+
Func<T, JsonNode> propertyGetter,
17+
Action<T, JsonNode> propertySetter,
1818
Func<T, OpenApiSchema> schemaGetter)
1919
{
2020
this.PropertyGetter = propertyGetter;
@@ -25,12 +25,12 @@ public AnyFieldMapParameter(
2525
/// <summary>
2626
/// Function to retrieve the value of the property.
2727
/// </summary>
28-
public Func<T, IOpenApiAny> PropertyGetter { get; }
28+
public Func<T, JsonNode> PropertyGetter { get; }
2929

3030
/// <summary>
3131
/// Function to set the value of the property.
3232
/// </summary>
33-
public Action<T, IOpenApiAny> PropertySetter { get; }
33+
public Action<T, JsonNode> PropertySetter { get; }
3434

3535
/// <summary>
3636
/// Function to get the schema to apply to the property.

src/Microsoft.OpenApi.Readers/ParseNodes/AnyListFieldMapParameter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using Microsoft.OpenApi.Any;
6+
using System.Text.Json.Nodes;
77
using Microsoft.OpenApi.Models;
88

99
namespace Microsoft.OpenApi.Readers.ParseNodes
@@ -14,8 +14,8 @@ internal class AnyListFieldMapParameter<T>
1414
/// Constructor
1515
/// </summary>
1616
public AnyListFieldMapParameter(
17-
Func<T, IList<IOpenApiAny>> propertyGetter,
18-
Action<T, IList<IOpenApiAny>> propertySetter,
17+
Func<T, IList<JsonNode>> propertyGetter,
18+
Action<T, IList<JsonNode>> propertySetter,
1919
Func<T, OpenApiSchema> schemaGetter)
2020
{
2121
this.PropertyGetter = propertyGetter;
@@ -26,12 +26,12 @@ public AnyListFieldMapParameter(
2626
/// <summary>
2727
/// Function to retrieve the value of the property.
2828
/// </summary>
29-
public Func<T, IList<IOpenApiAny>> PropertyGetter { get; }
29+
public Func<T, IList<JsonNode>> PropertyGetter { get; }
3030

3131
/// <summary>
3232
/// Function to set the value of the property.
3333
/// </summary>
34-
public Action<T, IList<IOpenApiAny>> PropertySetter { get; }
34+
public Action<T, IList<JsonNode>> PropertySetter { get; }
3535

3636
/// <summary>
3737
/// Function to get the schema to apply to the property.

src/Microsoft.OpenApi.Readers/ParseNodes/AnyMapFieldMapParameter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using Microsoft.OpenApi.Any;
6+
using System.Text.Json.Nodes;
77
using Microsoft.OpenApi.Interfaces;
88
using Microsoft.OpenApi.Models;
99

@@ -16,8 +16,8 @@ internal class AnyMapFieldMapParameter<T, U>
1616
/// </summary>
1717
public AnyMapFieldMapParameter(
1818
Func<T, IDictionary<string, U>> propertyMapGetter,
19-
Func<U, IOpenApiAny> propertyGetter,
20-
Action<U, IOpenApiAny> propertySetter,
19+
Func<U, JsonNode> propertyGetter,
20+
Action<U, JsonNode> propertySetter,
2121
Func<T, OpenApiSchema> schemaGetter)
2222
{
2323
this.PropertyMapGetter = propertyMapGetter;
@@ -34,12 +34,12 @@ public AnyMapFieldMapParameter(
3434
/// <summary>
3535
/// Function to retrieve the value of the property from an inner element.
3636
/// </summary>
37-
public Func<U, IOpenApiAny> PropertyGetter { get; }
37+
public Func<U, JsonNode> PropertyGetter { get; }
3838

3939
/// <summary>
4040
/// Function to set the value of the property.
4141
/// </summary>
42-
public Action<U, IOpenApiAny> PropertySetter { get; }
42+
public Action<U, JsonNode> PropertySetter { get; }
4343

4444
/// <summary>
4545
/// Function to get the schema to apply to the property.

src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static JsonNode GetSpecificOpenApiAny(JsonNode jsonNode, OpenApiSchema sc
4848
return newObject;
4949
}
5050

51-
if (!(jsonNode is JsonValue jsonValue))
51+
if (jsonNode is not JsonValue jsonValue)
5252
{
5353
return jsonNode;
5454
}

src/Microsoft.OpenApi.Readers/ParseNodes/ParseNode.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Text.Json;
76
using System.Text.Json.Nodes;
8-
using Microsoft.OpenApi.Any;
97
using Microsoft.OpenApi.Interfaces;
108
using Microsoft.OpenApi.Models;
119
using Microsoft.OpenApi.Readers.Exceptions;

src/Microsoft.OpenApi.Readers/ParseNodes/PropertyNode.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.Text.Json.Nodes;
8-
using Microsoft.OpenApi.Any;
98
using Microsoft.OpenApi.Exceptions;
109
using Microsoft.OpenApi.Models;
1110
using Microsoft.OpenApi.Readers.Exceptions;
12-
using SharpYaml.Serialization;
1311

1412
namespace Microsoft.OpenApi.Readers.ParseNodes
1513
{
@@ -87,7 +85,7 @@ public void ParseField<T>(
8785
}
8886
}
8987

90-
public override IOpenApiAny CreateAny()
88+
public override JsonNode CreateAny()
9189
{
9290
throw new NotImplementedException();
9391
}

src/Microsoft.OpenApi.Readers/ParsingContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public class ParsingContext
2424
private readonly Dictionary<string, object> _tempStorage = new Dictionary<string, object>();
2525
private readonly Dictionary<object, Dictionary<string, object>> _scopedTempStorage = new Dictionary<object, Dictionary<string, object>>();
2626
private readonly Dictionary<string, Stack<string>> _loopStacks = new Dictionary<string, Stack<string>>();
27-
internal Dictionary<string, Func<JsonNode, OpenApiSpecVersion, IOpenApiExtension>> ExtensionParsers { get; set; } = new Dictionary<string, Func<IOpenApiAny, OpenApiSpecVersion, IOpenApiExtension>>();
27+
internal Dictionary<string, Func<JsonNode, OpenApiSpecVersion, IOpenApiExtension>> ExtensionParsers { get; set; } =
28+
new Dictionary<string, Func<JsonNode, OpenApiSpecVersion, IOpenApiExtension>>();
2829
internal RootNode RootNode { get; set; }
2930
internal List<OpenApiTag> Tags { get; private set; } = new List<OpenApiTag>();
3031
internal Uri BaseUrl { get; set; }

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System.Collections.Generic;
55
using System.Linq;
6-
using Microsoft.OpenApi.Any;
6+
using System.Text.Json.Nodes;
77
using Microsoft.OpenApi.Extensions;
88
using Microsoft.OpenApi.Models;
99
using Microsoft.OpenApi.Readers.ParseNodes;
@@ -213,10 +213,10 @@ internal static OpenApiRequestBody CreateRequestBody(
213213
Extensions = bodyParameter.Extensions
214214
};
215215

216-
requestBody.Extensions[OpenApiConstants.BodyName] = new OpenApiString(bodyParameter.Name);
216+
requestBody.Extensions[OpenApiConstants.BodyName] = new ExtensionTypeCaster<string>(bodyParameter.Name);
217217
return requestBody;
218218
}
219-
219+
220220
private static OpenApiTag LoadTagByReference(
221221
ParsingContext context,
222222
string tagName)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System.Collections.Generic;
55
using System.Linq;
6-
using Microsoft.OpenApi.Any;
6+
using System.Text.Json.Nodes;
77
using Microsoft.OpenApi.Exceptions;
88
using Microsoft.OpenApi.Interfaces;
99
using Microsoft.OpenApi.Models;
@@ -74,7 +74,7 @@ private static void ProcessAnyListFields<T>(
7474
{
7575
try
7676
{
77-
var newProperty = new List<IOpenApiAny>();
77+
var newProperty = new List<JsonNode>();
7878

7979
mapNode.Context.StartObject(anyListFieldName);
8080

@@ -143,7 +143,7 @@ private static void ProcessAnyMapFields<T, U>(
143143
}
144144
}
145145

146-
public static IOpenApiAny LoadAny(ParseNode node)
146+
public static JsonNode LoadAny(ParseNode node)
147147
{
148148
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
149149
}
@@ -158,7 +158,7 @@ private static IOpenApiExtension LoadExtension(string name, ParseNode node)
158158
}
159159
else
160160
{
161-
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
161+
return (IOpenApiExtension)OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
162162
}
163163
}
164164

0 commit comments

Comments
 (0)