Skip to content

chore: rename OpenApiAny to JsonNodeExtension #2338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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", 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 @@ public IOpenApiParameter ConvertToBodyParameter(IOpenApiWriter writer)
// 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 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 Down Expand Up @@ -32,7 +32,7 @@ public OpenApiV3VersionService(OpenApiDiagnostic diagnostic)

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 @@ -965,7 +964,7 @@ internal void Walk(Dictionary<string, IOpenApiExample>? examples)
}

/// <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
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
Loading