Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/upgrade-guide-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ var openApiObject = new OpenApiObject
}
};
var parameter = new OpenApiParameter();
parameter.Extensions.Add("x-foo", new OpenApiAny(openApiObject));
parameter.Extensions.Add("x-foo", new JsonNodeExtension(openApiObject));

```

Expand All @@ -223,7 +223,7 @@ var openApiObject = new JsonObject
}
};
var parameter = new OpenApiParameter();
parameter.Extensions.Add("x-foo", new OpenApiAny(openApiObject));
parameter.Extensions.Add("x-foo", new JsonNodeExtension(openApiObject));

```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using System.Collections.Generic;
using System.Text.Json.Nodes;
Expand All @@ -15,7 +15,7 @@ internal static class OpenApiExtensibleExtensions
/// <returns>A <see cref="string"/> value matching the provided extensionKey. Return null when extensionKey is not found. </returns>
internal static string GetExtension(this Dictionary<string, IOpenApiExtension> extensions, string extensionKey)
{
if (extensions.TryGetValue(extensionKey, out var value) && value is OpenApiAny { Node: JsonValue castValue } && castValue.TryGetValue<string>(out var stringValue))
if (extensions.TryGetValue(extensionKey, out var value) && value is JsonNodeExtension { Node: JsonValue castValue } && castValue.TryGetValue<string>(out var stringValue))
{
return stringValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;

namespace Microsoft.OpenApi.Any
namespace Microsoft.OpenApi.Extensions
{
/// <summary>
/// A wrapper class for JsonNode
/// </summary>
public class OpenApiAny : IOpenApiElement, IOpenApiExtension
public class JsonNodeExtension : IOpenApiElement, IOpenApiExtension
{
private readonly JsonNode jsonNode;

/// <summary>
/// Initializes the <see cref="OpenApiAny"/> class.
/// Initializes the <see cref="JsonNodeExtension"/> class.
/// </summary>
/// <param name="jsonNode"></param>
public OpenApiAny(JsonNode jsonNode)
public JsonNodeExtension(JsonNode jsonNode)
{
this.jsonNode = jsonNode;
}
Expand All @@ -29,7 +29,7 @@ public OpenApiAny(JsonNode jsonNode)
public JsonNode Node { get { return jsonNode; } }

/// <summary>
/// Writes out the OpenApiAny type.
/// Writes out the JsonNodeExtension type.
/// </summary>
/// <param name="writer"></param>
/// <param name="specVersion"></param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using System;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;
using System.Text.Json.Nodes;
Expand Down Expand Up @@ -103,7 +102,7 @@ jsonNode is not JsonValue jsonValue ||
return null;
}
/// <summary>
/// Parses the <see cref="OpenApiAny"/> to <see cref="OpenApiDeprecationExtension"/>.
/// Parses the <see cref="JsonNodeExtension"/> to <see cref="OpenApiDeprecationExtension"/>.
/// </summary>
/// <param name="source">The source object.</param>
/// <returns>The <see cref="OpenApiDeprecationExtension"/>.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using System;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;

Expand Down Expand Up @@ -34,7 +34,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
public bool IsPrimaryErrorMessage { get; set; }

/// <summary>
/// Parses the <see cref="OpenApiAny"/> to <see cref="OpenApiPrimaryErrorMessageExtension"/>.
/// Parses the <see cref="JsonNodeExtension"/> to <see cref="OpenApiPrimaryErrorMessageExtension"/>.
/// </summary>
/// <param name="source">The source object.</param>
/// <returns>The <see cref="OpenApiPrimaryErrorMessageExtension"/>.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using System;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;

Expand Down Expand Up @@ -35,7 +35,7 @@ public bool? IsReserved
get; set;
}
/// <summary>
/// Parses the <see cref="OpenApiAny"/> to <see cref="OpenApiReservedParameterExtension"/>.
/// Parses the <see cref="JsonNodeExtension"/> to <see cref="OpenApiReservedParameterExtension"/>.
/// </summary>
/// <param name="source">The source object.</param>
/// <returns>The <see cref="OpenApiReservedParameterExtension"/>.</returns>
Expand Down
3 changes: 1 addition & 2 deletions src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models.Interfaces;
Expand Down Expand Up @@ -110,7 +109,7 @@
// Clone extensions so we can remove the x-bodyName extensions from the output V2 model.
if (bodyParameter.Extensions is not null &&
bodyParameter.Extensions.TryGetValue(OpenApiConstants.BodyName, out var bodyNameExtension) &&
bodyNameExtension is OpenApiAny bodyName)
bodyNameExtension is JsonNodeExtension bodyName)
{
bodyParameter.Name = string.IsNullOrEmpty(bodyName.Node.ToString()) ? "body" : bodyName.Node.ToString();
bodyParameter.Extensions.Remove(OpenApiConstants.BodyName);
Expand All @@ -137,7 +136,7 @@
{
OpenApiSchema s => s, // we already have a copy
// we have a copy of a reference but don't want to mutate the source schema
// TODO might need recursive resolution of references here

Check warning on line 139 in src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
OpenApiSchemaReference r when r.Target is not null => (OpenApiSchema)r.Target.CreateShallowCopy(),
OpenApiSchemaReference => throw new InvalidOperationException("Unresolved reference target"),
_ => throw new InvalidOperationException("Unexpected schema type")
Expand Down
3 changes: 1 addition & 2 deletions src/Microsoft.OpenApi/Models/OpenApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Helpers;
using Microsoft.OpenApi.Interfaces;
Expand Down Expand Up @@ -755,7 +754,7 @@ private void SerializeTypeProperty(JsonSchemaType? type, IOpenApiWriter writer,
var isNullable = (Type.HasValue && Type.Value.HasFlag(JsonSchemaType.Null)) ||
Extensions is not null &&
Extensions.TryGetValue(OpenApiConstants.NullableExtension, out var nullExtRawValue) &&
nullExtRawValue is OpenApiAny { Node: JsonNode jsonNode } &&
nullExtRawValue is JsonNodeExtension { Node: JsonNode jsonNode } &&
jsonNode.GetValueKind() is JsonValueKind.True;
if (type is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AnyMapFieldMapParameter(
}

/// <summary>
/// Function to retrieve the property that is a map from string to an inner element containing IOpenApiAny.
/// Function to retrieve the property that is a map from string to an inner element.
/// </summary>
public Func<T, Dictionary<string, U>?> PropertyMapGetter { get; }

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;

namespace Microsoft.OpenApi.Reader.ParseNodes
Expand Down Expand Up @@ -191,7 +191,7 @@ public override string GetRaw()
}

/// <summary>
/// Create an <see cref="OpenApiAny"/>
/// Create an <see cref="JsonNodeExtension"/>
/// </summary>
/// <returns>The created Json object.</returns>
public override JsonNode CreateAny()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader.ParseNodes;
using Microsoft.OpenApi.Models.References;
using Microsoft.OpenApi.Models.Interfaces;
using System;
using Microsoft.OpenApi.Interfaces;

namespace Microsoft.OpenApi.Reader.V2
{
Expand Down Expand Up @@ -242,7 +240,7 @@ internal static IOpenApiRequestBody CreateRequestBody(
if (bodyParameter.Name is not null)
{
requestBody.Extensions ??= [];
requestBody.Extensions[OpenApiConstants.BodyName] = new OpenApiAny(bodyParameter.Name);
requestBody.Extensions[OpenApiConstants.BodyName] = new JsonNodeExtension(bodyParameter.Name);
}
return requestBody;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Reader/V2/OpenApiV2Deserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader.ParseNodes;
Expand Down Expand Up @@ -86,7 +86,7 @@ private static IOpenApiExtension LoadExtension(string name, ParseNode node)
}
else
{
return new OpenApiAny(node.CreateAny());
return new JsonNodeExtension(node.CreateAny());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Reader/V2/OpenApiV2VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

using System;
using System.Collections.Generic;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Properties;
Expand All @@ -31,7 +31,7 @@ public OpenApiV2VersionService(OpenApiDiagnostic diagnostic)

private readonly Dictionary<Type, Func<ParseNode, OpenApiDocument, object?>> _loaders = new()
{
[typeof(OpenApiAny)] = OpenApiV2Deserializer.LoadAny,
[typeof(JsonNodeExtension)] = OpenApiV2Deserializer.LoadAny,
[typeof(OpenApiContact)] = OpenApiV2Deserializer.LoadContact,
[typeof(OpenApiExternalDocs)] = OpenApiV2Deserializer.LoadExternalDocs,
[typeof(OpenApiHeader)] = OpenApiV2Deserializer.LoadHeader,
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Expressions;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader.ParseNodes;
Expand Down Expand Up @@ -131,9 +131,9 @@ private static RuntimeExpressionAnyWrapper LoadRuntimeExpressionAnyWrapper(Parse
};
}

public static OpenApiAny LoadAny(ParseNode node, OpenApiDocument hostDocument)
public static JsonNodeExtension LoadAny(ParseNode node, OpenApiDocument hostDocument)
{
return new OpenApiAny(node.CreateAny());
return new JsonNodeExtension(node.CreateAny());
}

private static IOpenApiExtension LoadExtension(string name, ParseNode node)
Expand All @@ -145,7 +145,7 @@ private static IOpenApiExtension LoadExtension(string name, ParseNode node)
}
else
{
return new OpenApiAny(node.CreateAny());
return new JsonNodeExtension(node.CreateAny());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Reader/V3/OpenApiV3VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.References;
Expand All @@ -19,7 +19,7 @@
{
public OpenApiDiagnostic Diagnostic { get; }

private static readonly char[] _pathSeparator = new char[] { '/' };

Check warning on line 22 in src/Microsoft.OpenApi/Reader/V3/OpenApiV3VersionService.cs

View workflow job for this annotation

GitHub Actions / Build

Remove the unused private field '_pathSeparator'. (https://rules.sonarsource.com/csharp/RSPEC-1144)

/// <summary>
/// Create Parsing Context
Expand All @@ -32,7 +32,7 @@

private readonly Dictionary<Type, Func<ParseNode, OpenApiDocument, object>> _loaders = new()
{
[typeof(OpenApiAny)] = OpenApiV3Deserializer.LoadAny,
[typeof(JsonNodeExtension)] = OpenApiV3Deserializer.LoadAny,
[typeof(OpenApiCallback)] = OpenApiV3Deserializer.LoadCallback,
[typeof(OpenApiComponents)] = OpenApiV3Deserializer.LoadComponents,
[typeof(OpenApiContact)] = OpenApiV3Deserializer.LoadContact,
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Reader/V31/OpenApiV31Deserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System;
using System.Linq;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Expressions;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader.ParseNodes;
Expand Down Expand Up @@ -139,7 +139,7 @@ private static IOpenApiExtension LoadExtension(string name, ParseNode node)
{
return node.Context.ExtensionParsers is not null && node.Context.ExtensionParsers.TryGetValue(name, out var parser)
? parser(node.CreateAny(), OpenApiSpecVersion.OpenApi3_1)
: new OpenApiAny(node.CreateAny());
: new JsonNodeExtension(node.CreateAny());
}

private static string? LoadString(ParseNode node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.References;
Expand All @@ -31,7 +31,7 @@ public OpenApiV31VersionService(OpenApiDiagnostic diagnostic)

private readonly Dictionary<Type, Func<ParseNode, OpenApiDocument, object>> _loaders = new Dictionary<Type, Func<ParseNode, OpenApiDocument, object>>
{
[typeof(OpenApiAny)] = OpenApiV31Deserializer.LoadAny,
[typeof(JsonNodeExtension)] = OpenApiV31Deserializer.LoadAny,
[typeof(OpenApiCallback)] = OpenApiV31Deserializer.LoadCallback,
[typeof(OpenApiComponents)] = OpenApiV31Deserializer.LoadComponents,
[typeof(OpenApiContact)] = OpenApiV31Deserializer.LoadContact,
Expand Down
3 changes: 1 addition & 2 deletions src/Microsoft.OpenApi/Services/OpenApiWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using System.Net.Http;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
Expand Down Expand Up @@ -72,7 +71,7 @@
_visitor.Visit(tags);

// Visit tags
if (tags != null)

Check warning on line 74 in src/Microsoft.OpenApi/Services/OpenApiWalker.cs

View workflow job for this annotation

GitHub Actions / Build

Change this condition so that it does not always evaluate to 'True'. (https://rules.sonarsource.com/csharp/RSPEC-2589)
{
var tagsAsArray = tags.ToArray();
for (var i = 0; i < tagsAsArray.Length; i++)
Expand All @@ -95,7 +94,7 @@
_visitor.Visit(tags);

// Visit tags
if (tags != null)

Check warning on line 97 in src/Microsoft.OpenApi/Services/OpenApiWalker.cs

View workflow job for this annotation

GitHub Actions / Build

Change this condition so that it does not always evaluate to 'True'. (https://rules.sonarsource.com/csharp/RSPEC-2589)
{
var referencesAsArray = tags.ToArray();
for (var i = 0; i < referencesAsArray.Length; i++)
Expand Down Expand Up @@ -133,7 +132,7 @@
/// <summary>
/// Visits <see cref="OpenApiComponents"/> and child objects
/// </summary>
internal void Walk(OpenApiComponents? components)

Check warning on line 135 in src/Microsoft.OpenApi/Services/OpenApiWalker.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 52 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (components == null)
{
Expand Down Expand Up @@ -268,7 +267,7 @@
_visitor.Visit(paths);

// Visit Paths
if (paths != null)

Check warning on line 270 in src/Microsoft.OpenApi/Services/OpenApiWalker.cs

View workflow job for this annotation

GitHub Actions / Build

Change this condition so that it does not always evaluate to 'True'. (https://rules.sonarsource.com/csharp/RSPEC-2589)
{
foreach (var pathItem in paths)
{
Expand All @@ -293,7 +292,7 @@
_visitor.Visit(webhooks);

// Visit Webhooks
if (webhooks != null)

Check warning on line 295 in src/Microsoft.OpenApi/Services/OpenApiWalker.cs

View workflow job for this annotation

GitHub Actions / Build

Change this condition so that it does not always evaluate to 'True'. (https://rules.sonarsource.com/csharp/RSPEC-2589)
{
foreach (var pathItem in webhooks)
{
Expand Down Expand Up @@ -465,7 +464,7 @@
return;
}

if (tag is IOpenApiReferenceHolder openApiReferenceHolder)

Check warning on line 467 in src/Microsoft.OpenApi/Services/OpenApiWalker.cs

View workflow job for this annotation

GitHub Actions / Build

Change this condition so that it does not always evaluate to 'True'. (https://rules.sonarsource.com/csharp/RSPEC-2589)
{
Walk(openApiReferenceHolder);
}
Expand Down Expand Up @@ -498,7 +497,7 @@

_visitor.Visit(serverVariables);

if (serverVariables != null)

Check warning on line 500 in src/Microsoft.OpenApi/Services/OpenApiWalker.cs

View workflow job for this annotation

GitHub Actions / Build

Change this condition so that it does not always evaluate to 'True'. (https://rules.sonarsource.com/csharp/RSPEC-2589)
{
foreach (var variable in serverVariables)
{
Expand Down Expand Up @@ -965,7 +964,7 @@
}

/// <summary>
/// Visits <see cref="OpenApiAny"/> and child objects
/// Visits <see cref="JsonNodeExtension"/> and child objects
/// </summary>
internal void Walk(JsonNode? example)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Nodes;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;

namespace Microsoft.OpenApi.Writers
{
/// <summary>
/// Extensions methods for writing the <see cref="OpenApiAny"/>
/// Extensions methods for writing the <see cref="JsonNodeExtension"/>
/// </summary>
public static class OpenApiWriterAnyExtensions
{
Expand Down Expand Up @@ -114,7 +114,7 @@

private static void WritePrimitive(this IOpenApiWriter writer, JsonValue jsonValue)
{
if (jsonValue.TryGetValue(out string? stringValue) && stringValue is not null)

Check warning on line 117 in src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Change this condition so that it does not always evaluate to 'True'. (https://rules.sonarsource.com/csharp/RSPEC-2589)
writer.WriteValue(stringValue);
else if (jsonValue.TryGetValue(out DateTime dateTimeValue))
writer.WriteValue(dateTimeValue.ToString("o", CultureInfo.InvariantCulture)); // ISO 8601 format
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Hidi.Formatters;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.Interfaces;
using Microsoft.OpenApi.Services;
using Xunit;

Expand Down Expand Up @@ -147,7 +145,7 @@ private static OpenApiDocument GetSampleOpenApiDocument()
Extensions = new()
{
{
"x-ms-docs-operation-type", new OpenApiAny("function")
"x-ms-docs-operation-type", new JsonNodeExtension("function")
}
}
}
Expand Down
Loading