Skip to content

Commit e538742

Browse files
committed
Fixes more failing tests
1 parent a33a315 commit e538742

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+180
-155
lines changed

src/Microsoft.OpenApi.Readers/OpenApiReaderSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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<JsonNode, OpenApiSpecVersion, IOpenApiExtension>> ExtensionParsers { get; set; } = new Dictionary<string, Func<JsonNode, OpenApiSpecVersion, IOpenApiExtension>>();
52+
public Dictionary<string, Func<JsonNode, OpenApiSpecVersion, JsonNode>> ExtensionParsers { get; set; } = new Dictionary<string, Func<JsonNode, OpenApiSpecVersion, JsonNode>>();
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/OpenApiAnyConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static JsonNode GetSpecificOpenApiAny(JsonNode jsonNode, OpenApiSchema sc
8585
var type = schema?.Type;
8686
var format = schema?.Format;
8787

88-
if (value.StartsWith("\"") && value.EndsWith("\""))
88+
if (value.Contains("\""))
8989
{
9090
// More narrow type detection for explicit strings, only check types that are passed as strings
9191
if (schema == null)
@@ -275,9 +275,9 @@ public static JsonNode GetSpecificOpenApiAny(JsonNode jsonNode, OpenApiSchema sc
275275

276276
if (type == "string")
277277
{
278-
return jsonNode;
278+
return value;
279279
}
280-
280+
281281
if (type == "boolean")
282282
{
283283
if (bool.TryParse(value, out var booleanValue))
@@ -290,7 +290,7 @@ public static JsonNode GetSpecificOpenApiAny(JsonNode jsonNode, OpenApiSchema sc
290290
// If data conflicts with the given type, return a string.
291291
// This converter is used in the parser, so it does not perform any validations,
292292
// but the validator can be used to validate whether the data and given type conflicts.
293-
return jsonNode;
293+
return value;
294294
}
295295
}
296296
}

src/Microsoft.OpenApi.Readers/ParsingContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +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; } =
28-
new Dictionary<string, Func<JsonNode, OpenApiSpecVersion, IOpenApiExtension>>();
27+
internal Dictionary<string, Func<JsonNode, OpenApiSpecVersion, JsonNode>> ExtensionParsers { get; set; } =
28+
new Dictionary<string, Func<JsonNode, OpenApiSpecVersion, JsonNode>>();
2929
internal RootNode RootNode { get; set; }
3030
internal List<OpenApiTag> Tags { get; private set; } = new List<OpenApiTag>();
3131
internal Uri BaseUrl { get; set; }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ internal static OpenApiRequestBody CreateRequestBody(
213213
Extensions = bodyParameter.Extensions
214214
};
215215

216-
requestBody.Extensions[OpenApiConstants.BodyName] = new ExtensionTypeCaster<string>(bodyParameter.Name);
216+
requestBody.Extensions[OpenApiConstants.BodyName] = bodyParameter.Name;
217217
return requestBody;
218218
}
219219

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static JsonNode LoadAny(ParseNode node)
148148
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
149149
}
150150

151-
private static IOpenApiExtension LoadExtension(string name, ParseNode node)
151+
private static JsonNode LoadExtension(string name, ParseNode node)
152152
{
153153
if (node.Context.ExtensionParsers.TryGetValue(name, out var parser))
154154
{
@@ -158,7 +158,7 @@ private static IOpenApiExtension LoadExtension(string name, ParseNode node)
158158
}
159159
else
160160
{
161-
return (IOpenApiExtension)OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
161+
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
162162
}
163163
}
164164

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ public static JsonNode LoadAny(ParseNode node)
168168
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
169169
}
170170

171-
private static IOpenApiExtension LoadExtension(string name, ParseNode node)
171+
private static JsonNode LoadExtension(string name, ParseNode node)
172172
{
173173
if (node.Context.ExtensionParsers.TryGetValue(name, out var parser))
174174
{
175175
return parser(OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny()), OpenApiSpecVersion.OpenApi3_0);
176176
}
177177
else
178178
{
179-
return (IOpenApiExtension)OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
179+
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
180180
}
181181
}
182182

src/Microsoft.OpenApi/Extensions/ExtensionTypeCaster.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Text.Json.Nodes;
5+
using Microsoft.OpenApi.Writers;
6+
7+
namespace Microsoft.OpenApi.Extensions
8+
{
9+
internal static class JsonNodeExtension
10+
{
11+
//private static void Write(this JsonNode, IOpenApiWriter writer) => writer.WriteValue(this);
12+
//public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
13+
//{
14+
// writer.WriteValue(_value);
15+
//}
16+
}
17+
}

src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs

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

4+
using System.Text.Json.Nodes;
45
using Microsoft.OpenApi.Exceptions;
56
using Microsoft.OpenApi.Interfaces;
67
using Microsoft.OpenApi.Models;
@@ -20,7 +21,7 @@ public static class OpenApiExtensibleExtensions
2021
/// <param name="element">The extensible Open API element. </param>
2122
/// <param name="name">The extension name.</param>
2223
/// <param name="any">The extension value.</param>
23-
public static void AddExtension<T>(this T element, string name, IOpenApiExtension any)
24+
public static void AddExtension<T>(this T element, string name, JsonNode any)
2425
where T : IOpenApiExtensible
2526
{
2627
if (element == null)

src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs

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

44
using System.Collections.Generic;
5+
using System.Text.Json.Nodes;
56

67
namespace Microsoft.OpenApi.Interfaces
78
{
@@ -13,6 +14,6 @@ public interface IOpenApiExtensible : IOpenApiElement
1314
/// <summary>
1415
/// Specification extensions.
1516
/// </summary>
16-
IDictionary<string, IOpenApiExtension> Extensions { get; set; }
17+
IDictionary<string, JsonNode> Extensions { get; set; }
1718
}
1819
}

0 commit comments

Comments
 (0)