Skip to content

Commit f6e5f1d

Browse files
committed
Rename
1 parent 03337b9 commit f6e5f1d

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

src/Microsoft.OpenApi.Readers/ParseNodes/IOpenApiAnyExtensions.cs renamed to src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
using System;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
25
using System.Linq;
36
using Microsoft.OpenApi.Any;
47
using Microsoft.OpenApi.Exceptions;
58
using Microsoft.OpenApi.Models;
69

710
namespace Microsoft.OpenApi.Readers.ParseNodes
811
{
9-
internal static class OpenApiStringConverter
12+
internal static class OpenApiAnyConverter
1013
{
14+
/// <summary>
15+
/// Converts the <see cref="OpenApiString"/>s in the given <see cref="IOpenApiAny"/>
16+
/// into the most specific <see cref="IOpenApiPrimitive"/> type based on the value.
17+
/// </summary>
1118
public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny)
1219
{
1320
if (openApiAny is OpenApiArray openApiArray)
@@ -79,6 +86,12 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny)
7986
return new OpenApiString(value);
8087
}
8188

89+
/// <summary>
90+
/// Converts the <see cref="OpenApiString"/>s in the given <see cref="IOpenApiAny"/>
91+
/// into the appropriate <see cref="IOpenApiPrimitive"/> type based on the given <see cref="OpenApiSchema"/>.
92+
/// For those strings that the schema does not specify the type for, convert them into
93+
/// the most specific type based on the value.
94+
/// </summary>
8295
public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiSchema schema)
8396
{
8497
if (openApiAny is OpenApiArray openApiArray)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static void LoadExamples(OpenApiResponse response, ParseNode node)
8383

8484
private static void LoadExample(OpenApiResponse response, string mediaType, ParseNode node)
8585
{
86-
var exampleNode = OpenApiStringConverter.GetSpecificOpenApiAny(node.CreateAny());
86+
var exampleNode = OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
8787

8888
if (response.Content == null)
8989
{

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

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

4-
using System;
54
using System.Collections.Generic;
65
using System.Linq;
76
using Microsoft.OpenApi.Any;
@@ -48,7 +47,7 @@ private static void ProcessAnyFields<T>(
4847
{
4948
mapNode.Context.StartObject(anyFieldName);
5049

51-
var convertedOpenApiAny = OpenApiStringConverter.GetSpecificOpenApiAny(
50+
var convertedOpenApiAny = OpenApiAnyConverter.GetSpecificOpenApiAny(
5251
anyFieldMap[anyFieldName].PropertyGetter(domainObject),
5352
anyFieldMap[anyFieldName].SchemaGetter(domainObject));
5453

@@ -82,7 +81,7 @@ private static void ProcessAnyListFields<T>(
8281
foreach (var propertyElement in anyListFieldMap[anyListFieldName].PropertyGetter(domainObject))
8382
{
8483
newProperty.Add(
85-
OpenApiStringConverter.GetSpecificOpenApiAny(
84+
OpenApiAnyConverter.GetSpecificOpenApiAny(
8685
propertyElement,
8786
anyListFieldMap[anyListFieldName].SchemaGetter(domainObject)));
8887
}
@@ -103,20 +102,20 @@ private static void ProcessAnyListFields<T>(
103102

104103
public static IOpenApiAny LoadAny(ParseNode node)
105104
{
106-
return OpenApiStringConverter.GetSpecificOpenApiAny(node.CreateAny());
105+
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
107106
}
108107

109108
private static IOpenApiExtension LoadExtension(string name, ParseNode node)
110109
{
111110
if (node.Context.ExtensionParsers.TryGetValue(name, out var parser))
112111
{
113112
return parser(
114-
OpenApiStringConverter.GetSpecificOpenApiAny(node.CreateAny()),
113+
OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()),
115114
OpenApiSpecVersion.OpenApi2_0);
116115
}
117116
else
118117
{
119-
return OpenApiStringConverter.GetSpecificOpenApiAny(node.CreateAny());
118+
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
120119
}
121120
}
122121

src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static void ProcessAnyFields<T>(
4747
{
4848
mapNode.Context.StartObject(anyFieldName);
4949

50-
var convertedOpenApiAny = OpenApiStringConverter.GetSpecificOpenApiAny(
50+
var convertedOpenApiAny = OpenApiAnyConverter.GetSpecificOpenApiAny(
5151
anyFieldMap[anyFieldName].PropertyGetter(domainObject),
5252
anyFieldMap[anyFieldName].SchemaGetter(domainObject));
5353

@@ -81,7 +81,7 @@ private static void ProcessAnyListFields<T>(
8181
foreach (var propertyElement in anyListFieldMap[anyListFieldName].PropertyGetter(domainObject))
8282
{
8383
newProperty.Add(
84-
OpenApiStringConverter.GetSpecificOpenApiAny(
84+
OpenApiAnyConverter.GetSpecificOpenApiAny(
8585
propertyElement,
8686
anyListFieldMap[anyListFieldName].SchemaGetter(domainObject)));
8787
}
@@ -120,26 +120,26 @@ private static RuntimeExpressionAnyWrapper LoadRuntimeExpressionAnyWrapper(Parse
120120

121121
return new RuntimeExpressionAnyWrapper
122122
{
123-
Any = OpenApiStringConverter.GetSpecificOpenApiAny(node.CreateAny())
123+
Any = OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny())
124124
};
125125
}
126126

127127
public static IOpenApiAny LoadAny(ParseNode node)
128128
{
129-
return OpenApiStringConverter.GetSpecificOpenApiAny(node.CreateAny());
129+
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
130130
}
131131

132132
private static IOpenApiExtension LoadExtension(string name, ParseNode node)
133133
{
134134
if (node.Context.ExtensionParsers.TryGetValue(name, out var parser))
135135
{
136136
return parser(
137-
OpenApiStringConverter.GetSpecificOpenApiAny(node.CreateAny()),
137+
OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()),
138138
OpenApiSpecVersion.OpenApi3_0);
139139
}
140140
else
141141
{
142-
return OpenApiStringConverter.GetSpecificOpenApiAny(node.CreateAny());
142+
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
143143
}
144144
}
145145

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiAnyTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public void ParseMapAsAnyShouldSucceed()
4242
new OpenApiObject
4343
{
4444
["aString"] = new OpenApiString("fooBar"),
45-
["aInteger"] = new OpenApiInteger(10),
46-
["aDouble"] = new OpenApiDouble(2.34),
47-
["aDateTime"] = new OpenApiDateTime(DateTimeOffset.Parse("2017-01-01", CultureInfo.InvariantCulture))
45+
["aInteger"] = new OpenApiString("10"),
46+
["aDouble"] = new OpenApiString("2.34"),
47+
["aDateTime"] = new OpenApiString("2017-01-01")
4848
});
4949
}
5050

@@ -74,9 +74,9 @@ public void ParseListAsAnyShouldSucceed()
7474
new OpenApiArray
7575
{
7676
new OpenApiString("fooBar"),
77-
new OpenApiInteger(10),
78-
new OpenApiDouble(2.34),
79-
new OpenApiDateTime(DateTimeOffset.Parse("2017-01-01", CultureInfo.InvariantCulture))
77+
new OpenApiString("10"),
78+
new OpenApiString("2.34"),
79+
new OpenApiString("2017-01-01")
8080
});
8181
}
8282

@@ -100,7 +100,7 @@ public void ParseScalarIntegerAsAnyShouldSucceed()
100100
diagnostic.Errors.Should().BeEmpty();
101101

102102
any.ShouldBeEquivalentTo(
103-
new OpenApiInteger(10)
103+
new OpenApiString("10")
104104
);
105105
}
106106

@@ -124,7 +124,7 @@ public void ParseScalarDateTimeAsAnyShouldSucceed()
124124
diagnostic.Errors.Should().BeEmpty();
125125

126126
any.ShouldBeEquivalentTo(
127-
new OpenApiDateTime(DateTimeOffset.Parse("2012-07-23T12:33:00", CultureInfo.InvariantCulture))
127+
new OpenApiString("2012-07-23T12:33:00")
128128
);
129129
}
130130
}

0 commit comments

Comments
 (0)