Skip to content

Commit 404ba4f

Browse files
committed
chore: refactor to update Extensions type to OpenApiExtensionDictionary
1 parent 7f9d840 commit 404ba4f

Some content is hidden

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

46 files changed

+147
-105
lines changed

src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs

Lines changed: 2 additions & 3 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 System.Collections.Generic;
5+
using Microsoft.OpenApi.Any;
66
using Microsoft.OpenApi.Exceptions;
77
using Microsoft.OpenApi.Interfaces;
88
using Microsoft.OpenApi.Models;
@@ -32,9 +32,8 @@ public static void AddExtension<T>(this T element, string name, IOpenApiExtensio
3232
{
3333
throw new OpenApiException(string.Format(SRResource.ExtensionFieldNameMustBeginWithXDash, name));
3434
}
35-
3635
element.Extensions ??= [];
37-
element.Extensions[name] = Utils.CheckArgumentNull(any);
36+
element.Extensions[name] = (OpenApiAny)Utils.CheckArgumentNull(any);
3837
}
3938
}
4039
}

src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System.Collections.Generic;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using Microsoft.OpenApi.Any;
25

36
namespace Microsoft.OpenApi.Interfaces;
47

@@ -10,6 +13,5 @@ public interface IOpenApiReadOnlyExtensible
1013
/// <summary>
1114
/// Specification extensions.
1215
/// </summary>
13-
Dictionary<string, IOpenApiExtension>? Extensions { get; }
14-
16+
OpenApiExtensionDictionary? Extensions { get; }
1517
}

src/Microsoft.OpenApi/Models/OpenApiCallback.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal OpenApiCallback(IOpenApiCallback callback)
3838
{
3939
Utils.CheckArgumentNull(callback);
4040
PathItems = callback?.PathItems != null ? new(callback.PathItems) : null;
41-
Extensions = callback?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(callback.Extensions) : null;
41+
Extensions = callback?.Extensions != null ? new OpenApiExtensionDictionary(callback.Extensions) : null;
4242
}
4343

4444
/// <summary>
@@ -92,7 +92,6 @@ internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion versio
9292

9393
// extensions
9494
writer.WriteExtensions(Extensions, version);
95-
Extensions!["x-extensions"] = new JsonObject(); //this works
9695

9796
writer.WriteEndObject();
9897
}

src/Microsoft.OpenApi/Models/OpenApiComponents.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using Microsoft.OpenApi.Any;
78
using Microsoft.OpenApi.Interfaces;
89
using Microsoft.OpenApi.Models.Interfaces;
910
using Microsoft.OpenApi.Models.References;
@@ -69,7 +70,7 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible
6970
/// <summary>
7071
/// This object MAY be extended with Specification Extensions.
7172
/// </summary>
72-
public Dictionary<string, IOpenApiExtension>? Extensions { get; set; }
73+
public OpenApiExtensionDictionary? Extensions { get; set; }
7374

7475
/// <summary>
7576
/// Parameter-less constructor
@@ -91,7 +92,7 @@ public OpenApiComponents(OpenApiComponents? components)
9192
Links = components?.Links != null ? new Dictionary<string, IOpenApiLink>(components.Links) : null;
9293
Callbacks = components?.Callbacks != null ? new Dictionary<string, IOpenApiCallback>(components.Callbacks) : null;
9394
PathItems = components?.PathItems != null ? new Dictionary<string, IOpenApiPathItem>(components.PathItems) : null;
94-
Extensions = components?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(components.Extensions) : null;
95+
Extensions = components?.Extensions != null ? new OpenApiExtensionDictionary(components.Extensions) : null;
9596
}
9697

9798
/// <summary>

src/Microsoft.OpenApi/Models/OpenApiContact.cs

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

44
using System;
55
using System.Collections.Generic;
6+
using Microsoft.OpenApi.Any;
67
using Microsoft.OpenApi.Interfaces;
78
using Microsoft.OpenApi.Writers;
89

@@ -32,7 +33,7 @@ public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible
3233
/// <summary>
3334
/// This object MAY be extended with Specification Extensions.
3435
/// </summary>
35-
public Dictionary<string, IOpenApiExtension>? Extensions { get; set; }
36+
public OpenApiExtensionDictionary? Extensions { get; set; }
3637

3738
/// <summary>
3839
/// Parameter-less constructor
@@ -47,7 +48,7 @@ public OpenApiContact(OpenApiContact contact)
4748
Name = contact?.Name ?? Name;
4849
Url = contact?.Url != null ? new Uri(contact.Url.OriginalString, UriKind.RelativeOrAbsolute) : null;
4950
Email = contact?.Email ?? Email;
50-
Extensions = contact?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(contact.Extensions) : null;
51+
Extensions = contact?.Extensions != null ? new OpenApiExtensionDictionary(contact.Extensions) : null;
5152
}
5253

5354
/// <summary>

src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs

Lines changed: 3 additions & 2 deletions
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 Microsoft.OpenApi.Any;
56
using Microsoft.OpenApi.Interfaces;
67
using Microsoft.OpenApi.Models.References;
78
using Microsoft.OpenApi.Writers;
@@ -26,7 +27,7 @@ public class OpenApiDiscriminator : IOpenApiSerializable, IOpenApiExtensible
2627
/// <summary>
2728
/// This object MAY be extended with Specification Extensions.
2829
/// </summary>
29-
public Dictionary<string, IOpenApiExtension>? Extensions { get; set; }
30+
public OpenApiExtensionDictionary? Extensions { get; set; }
3031

3132
/// <summary>
3233
/// Parameter-less constructor
@@ -40,7 +41,7 @@ public OpenApiDiscriminator(OpenApiDiscriminator discriminator)
4041
{
4142
PropertyName = discriminator?.PropertyName ?? PropertyName;
4243
Mapping = discriminator?.Mapping != null ? new Dictionary<string, OpenApiSchemaReference>(discriminator.Mapping) : null;
43-
Extensions = discriminator?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(discriminator.Extensions) : null;
44+
Extensions = discriminator?.Extensions != null ? new OpenApiExtensionDictionary(discriminator.Extensions) : null;
4445
}
4546

4647
/// <summary>

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Text;
1010
using System.Threading;
1111
using System.Threading.Tasks;
12+
using Microsoft.OpenApi.Any;
1213
using Microsoft.OpenApi.Extensions;
1314
using Microsoft.OpenApi.Interfaces;
1415
using Microsoft.OpenApi.Models.Interfaces;
@@ -103,7 +104,7 @@ public HashSet<OpenApiTag>? Tags
103104
/// <summary>
104105
/// This object MAY be extended with Specification Extensions.
105106
/// </summary>
106-
public Dictionary<string, IOpenApiExtension>? Extensions { get; set; }
107+
public OpenApiExtensionDictionary? Extensions { get; set; }
107108

108109
/// <inheritdoc />
109110
public Dictionary<string, object>? Metadata { get; set; }
@@ -139,7 +140,7 @@ public OpenApiDocument(OpenApiDocument? document)
139140
Security = document?.Security != null ? [.. document.Security] : null;
140141
Tags = document?.Tags != null ? new HashSet<OpenApiTag>(document.Tags, OpenApiTagComparer.Instance) : null;
141142
ExternalDocs = document?.ExternalDocs != null ? new(document.ExternalDocs) : null;
142-
Extensions = document?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(document.Extensions) : null;
143+
Extensions = document?.Extensions != null ? new OpenApiExtensionDictionary(document.Extensions) : null;
143144
Metadata = document?.Metadata != null ? new Dictionary<string, object>(document.Metadata) : null;
144145
BaseUri = document?.BaseUri != null ? document.BaseUri : new(OpenApiConstants.BaseRegistryUri + Guid.NewGuid());
145146
}

src/Microsoft.OpenApi/Models/OpenApiEncoding.cs

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

44
using System;
55
using System.Collections.Generic;
6+
using Microsoft.OpenApi.Any;
67
using Microsoft.OpenApi.Extensions;
78
using Microsoft.OpenApi.Interfaces;
89
using Microsoft.OpenApi.Models.Interfaces;
@@ -52,7 +53,7 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible
5253
/// <summary>
5354
/// This object MAY be extended with Specification Extensions.
5455
/// </summary>
55-
public Dictionary<string, IOpenApiExtension>? Extensions { get; set; }
56+
public OpenApiExtensionDictionary? Extensions { get; set; }
5657

5758
/// <summary>
5859
/// Parameter-less constructor
@@ -69,7 +70,7 @@ public OpenApiEncoding(OpenApiEncoding encoding)
6970
Style = encoding?.Style ?? Style;
7071
Explode = encoding?.Explode ?? Explode;
7172
AllowReserved = encoding?.AllowReserved ?? AllowReserved;
72-
Extensions = encoding?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(encoding.Extensions) : null;
73+
Extensions = encoding?.Extensions != null ? new OpenApiExtensionDictionary(encoding.Extensions) : null;
7374
}
7475

7576
/// <summary>

src/Microsoft.OpenApi/Models/OpenApiExample.cs

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

44
using System.Collections.Generic;
55
using System.Text.Json.Nodes;
6+
using Microsoft.OpenApi.Any;
67
using Microsoft.OpenApi.Helpers;
78
using Microsoft.OpenApi.Interfaces;
89
using Microsoft.OpenApi.Models.Interfaces;
@@ -28,7 +29,7 @@ public class OpenApiExample : IOpenApiExtensible, IOpenApiExample
2829
public JsonNode? Value { get; set; }
2930

3031
/// <inheritdoc/>
31-
public Dictionary<string, IOpenApiExtension>? Extensions { get; set; }
32+
public OpenApiExtensionDictionary? Extensions { get; set; }
3233

3334
/// <summary>
3435
/// Parameter-less constructor
@@ -46,7 +47,7 @@ internal OpenApiExample(IOpenApiExample example)
4647
Description = example.Description ?? Description;
4748
Value = example.Value != null ? JsonNodeCloneHelper.Clone(example.Value) : null;
4849
ExternalValue = example.ExternalValue ?? ExternalValue;
49-
Extensions = example.Extensions != null ? new Dictionary<string, IOpenApiExtension>(example.Extensions) : null;
50+
Extensions = example.Extensions != null ? new OpenApiExtensionDictionary(example.Extensions) : null;
5051
}
5152

5253
/// <inheritdoc/>

src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs

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

44
using System;
55
using System.Collections.Generic;
6+
using Microsoft.OpenApi.Any;
67
using Microsoft.OpenApi.Interfaces;
78
using Microsoft.OpenApi.Writers;
89

@@ -28,15 +29,15 @@ protected OpenApiExtensibleDictionary():this([]) { }
2829
/// <param name="extensions">The dictionary of <see cref="IOpenApiExtension"/>.</param>
2930
protected OpenApiExtensibleDictionary(
3031
Dictionary<string, T> dictionary,
31-
Dictionary<string, IOpenApiExtension>? extensions = null) : base(dictionary is null ? [] : dictionary)
32+
OpenApiExtensionDictionary? extensions = null) : base(dictionary is null ? [] : dictionary)
3233
{
33-
Extensions = extensions != null ? new Dictionary<string, IOpenApiExtension>(extensions) : [];
34+
Extensions = extensions != null ? new OpenApiExtensionDictionary(extensions) : [];
3435
}
3536

3637
/// <summary>
3738
/// This object MAY be extended with Specification Extensions.
3839
/// </summary>
39-
public Dictionary<string, IOpenApiExtension>? Extensions { get; set; }
40+
public OpenApiExtensionDictionary? Extensions { get; set; }
4041

4142

4243
/// <summary>

0 commit comments

Comments
 (0)