Skip to content

Commit 532765a

Browse files
committed
feat: adds deep copy infrastructure
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent 3632439 commit 532765a

48 files changed

Lines changed: 1551 additions & 84 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
namespace Microsoft.OpenApi;
5+
/// <summary>
6+
/// Interface for deep copyable objects.
7+
/// </summary>
8+
/// <typeparam name="T">The type of the resulting object.</typeparam>
9+
public interface IDeepCopyable<out T>
10+
{
11+
/// <summary>
12+
/// Create a deep copy of the current instance.
13+
/// </summary>
14+
T CreateDeepCopy();
15+
}
16+

src/Microsoft.OpenApi/Models/BaseOpenApiReference.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ internal void EnsureHostDocumentIsSet(OpenApiDocument currentDocument)
295295
Utils.CheckArgumentNull(currentDocument);
296296
hostDocument ??= currentDocument;
297297
}
298+
299+
internal void SetHostDocument(OpenApiDocument currentDocument)
300+
{
301+
Utils.CheckArgumentNull(currentDocument);
302+
hostDocument = currentDocument;
303+
}
298304
/// <summary>
299305
/// Gets the property value from a JsonObject node.
300306
/// </summary>

src/Microsoft.OpenApi/Models/OpenApiCallback.cs

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

44
using System;
@@ -9,7 +9,7 @@ namespace Microsoft.OpenApi
99
/// <summary>
1010
/// Callback Object: A map of possible out-of band callbacks related to the parent operation.
1111
/// </summary>
12-
public class OpenApiCallback : IOpenApiExtensible, IOpenApiCallback
12+
public class OpenApiCallback : IOpenApiExtensible, IOpenApiCallback, IDeepCopyable<IOpenApiCallback>
1313
{
1414
/// <inheritdoc/>
1515
public Dictionary<RuntimeExpression, IOpenApiPathItem>? PathItems { get; set; }
@@ -113,5 +113,10 @@ public IOpenApiCallback CreateShallowCopy()
113113
{
114114
return new OpenApiCallback(this);
115115
}
116+
/// <inheritdoc/>
117+
public IOpenApiCallback CreateDeepCopy()
118+
{
119+
return new OpenApiDeepCopyContext().Copy(this);
120+
}
116121
}
117122
}

src/Microsoft.OpenApi/Models/OpenApiComponents.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.OpenApi
1010
/// <summary>
1111
/// Components Object.
1212
/// </summary>
13-
public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible
13+
public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible, IDeepCopyable<OpenApiComponents>
1414
{
1515
/// <summary>
1616
/// An object to hold reusable <see cref="IOpenApiSchema"/> Objects.
@@ -96,6 +96,12 @@ public OpenApiComponents(OpenApiComponents? components)
9696
Extensions = components?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(components.Extensions) : null;
9797
}
9898

99+
/// <inheritdoc/>
100+
public OpenApiComponents CreateDeepCopy()
101+
{
102+
return new OpenApiDeepCopyContext().Copy(this);
103+
}
104+
99105
/// <summary>
100106
/// Serialize <see cref="OpenApiComponents"/> to Open API v3.2.
101107
/// </summary>

src/Microsoft.OpenApi/Models/OpenApiContact.cs

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

44
using System;
@@ -9,7 +9,7 @@ namespace Microsoft.OpenApi
99
/// <summary>
1010
/// Contact Object.
1111
/// </summary>
12-
public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible
12+
public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible, IDeepCopyable<OpenApiContact>
1313
{
1414
/// <summary>
1515
/// The identifying name of the contact person/organization.
@@ -47,6 +47,11 @@ public OpenApiContact(OpenApiContact contact)
4747
Email = contact?.Email ?? Email;
4848
Extensions = contact?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(contact.Extensions) : null;
4949
}
50+
/// <inheritdoc/>
51+
public OpenApiContact CreateDeepCopy()
52+
{
53+
return new OpenApiDeepCopyContext().Copy(this);
54+
}
5055
/// <summary>
5156
/// Serialize <see cref="OpenApiContact"/> to Open Api v3.2
5257
/// </summary>

0 commit comments

Comments
 (0)