Skip to content

Commit 9bc3044

Browse files
committed
fix: shallow copy for example
Signed-off-by: Vincent Biret <[email protected]>
1 parent 4ea87ef commit 9bc3044

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.OpenApi.Models.Interfaces;
77
/// Defines the base properties for the example object.
88
/// This interface is provided for type assertions but should not be implemented by package consumers beyond automatic mocking.
99
/// </summary>
10-
public interface IOpenApiExample : IOpenApiDescribedElement, IOpenApiSummarizedElement, IOpenApiSerializable, IOpenApiReadOnlyExtensible
10+
public interface IOpenApiExample : IOpenApiDescribedElement, IOpenApiSummarizedElement, IOpenApiSerializable, IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiExample>
1111
{
1212
/// <summary>
1313
/// Embedded literal example. The value field and externalValue field are mutually

src/Microsoft.OpenApi/Models/OpenApiExample.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public OpenApiExample() { }
3939
/// Initializes a copy of <see cref="OpenApiExample"/> object
4040
/// </summary>
4141
/// <param name="example">The <see cref="IOpenApiExample"/> object</param>
42-
public OpenApiExample(IOpenApiExample example)
42+
internal OpenApiExample(IOpenApiExample example)
4343
{
4444
Utils.CheckArgumentNull(example);
4545
Summary = example.Summary ?? Summary;
@@ -90,5 +90,11 @@ public void SerializeAsV2(IOpenApiWriter writer)
9090
{
9191
SerializeInternal(writer, OpenApiSpecVersion.OpenApi2_0);
9292
}
93+
94+
/// <inheritdoc/>
95+
public IOpenApiExample CreateShallowCopy()
96+
{
97+
return new OpenApiExample(this);
98+
}
9399
}
94100
}

src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ public OpenApiExampleReference(string referenceId, OpenApiDocument hostDocument,
2929
{
3030
}
3131

32-
/// <summary>
33-
/// Copy constructor
34-
/// </summary>
35-
/// <param name="example">The reference to copy.</param>
36-
public OpenApiExampleReference(OpenApiExampleReference example):base(example)
37-
{
38-
}
39-
4032
internal OpenApiExampleReference(OpenApiExample target, string referenceId):base(target, referenceId, ReferenceType.Example)
4133
{
4234
}
@@ -88,5 +80,13 @@ public override void SerializeAsV2(IOpenApiWriter writer)
8880
// examples components are not supported in OAS 2.0
8981
Reference.SerializeAsV2(writer);
9082
}
83+
84+
/// <inheritdoc/>
85+
public IOpenApiExample CreateShallowCopy()
86+
{
87+
return _target is null ?
88+
new OpenApiExampleReference(Reference.Id, Reference.HostDocument, Reference.ExternalResource) :
89+
new OpenApiExampleReference(_target, Reference.Id);
90+
}
9191
}
9292
}

0 commit comments

Comments
 (0)