Skip to content

Commit be998b0

Browse files
committed
Use DictionaryCloneHelper cloning method for all dictionary copies
1 parent 608d908 commit be998b0

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

src/Microsoft.OpenApi/Models/OpenApiEncoding.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using Microsoft.OpenApi.Any;
66
using Microsoft.OpenApi.Extensions;
7+
using Microsoft.OpenApi.Helpers;
78
using Microsoft.OpenApi.Interfaces;
89
using Microsoft.OpenApi.Writers;
910

@@ -64,11 +65,11 @@ public OpenApiEncoding() {}
6465
public OpenApiEncoding(OpenApiEncoding encoding)
6566
{
6667
ContentType = encoding?.ContentType ?? ContentType;
67-
Headers = encoding?.Headers != null ? new Dictionary<string, OpenApiHeader>(encoding.Headers) : null;
68+
Headers = encoding?.Headers != null ? DictionaryCloneHelper.Clone(encoding.Headers) : null;
6869
Style = encoding?.Style ?? Style;
6970
Explode = encoding?.Explode ?? Explode;
7071
AllowReserved = encoding?.AllowReserved ?? AllowReserved;
71-
Extensions = encoding?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(encoding.Extensions) : null;
72+
Extensions = encoding?.Extensions != null ? DictionaryCloneHelper.Clone(encoding.Extensions) : null;
7273
}
7374

7475
/// <summary>

src/Microsoft.OpenApi/Models/OpenApiExample.cs

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

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

@@ -68,7 +69,7 @@ public OpenApiExample(OpenApiExample example)
6869
Description = example?.Description ?? Description;
6970
Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example?.Value);
7071
ExternalValue = example?.ExternalValue ?? ExternalValue;
71-
Extensions = example?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(example.Extensions) : null;
72+
Extensions = example?.Extensions != null ? DictionaryCloneHelper.Clone(example.Extensions) : null;
7273
Reference = example?.Reference != null ? new(example?.Reference) : null;
7374
UnresolvedReference = example?.UnresolvedReference ?? UnresolvedReference;
7475
}

src/Microsoft.OpenApi/Models/OpenApiHeader.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using Microsoft.OpenApi.Any;
66
using Microsoft.OpenApi.Extensions;
7+
using Microsoft.OpenApi.Helpers;
78
using Microsoft.OpenApi.Interfaces;
89
using Microsoft.OpenApi.Writers;
910

@@ -107,9 +108,9 @@ public OpenApiHeader(OpenApiHeader header)
107108
AllowReserved = header?.AllowReserved ?? AllowReserved;
108109
Schema = header?.Schema != null ? new(header?.Schema) : null;
109110
Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(header?.Example);
110-
Examples = header?.Examples != null ? new Dictionary<string, OpenApiExample>(header.Examples) : null;
111-
Content = header?.Content != null ? new Dictionary<string, OpenApiMediaType>(header.Content) : null;
112-
Extensions = header?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(header.Extensions) : null;
111+
Examples = header?.Examples != null ? DictionaryCloneHelper.Clone(header.Examples) : null;
112+
Content = header?.Content != null ? DictionaryCloneHelper.Clone(header.Content) : null;
113+
Extensions = header?.Extensions != null ? DictionaryCloneHelper.Clone(header.Extensions) : null;
113114
}
114115

115116
/// <summary>

src/Microsoft.OpenApi/Models/OpenApiMediaType.cs

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

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

@@ -55,9 +56,9 @@ public OpenApiMediaType(OpenApiMediaType mediaType)
5556
{
5657
Schema = mediaType?.Schema != null ? new(mediaType?.Schema) : null;
5758
Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(mediaType?.Example);
58-
Examples = mediaType?.Examples != null ? new Dictionary<string, OpenApiExample>(mediaType.Examples) : null;
59-
Encoding = mediaType?.Encoding != null ? new Dictionary<string, OpenApiEncoding>(mediaType.Encoding) : null;
60-
Extensions = mediaType?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(mediaType.Extensions) : null;
59+
Examples = mediaType?.Examples != null ? DictionaryCloneHelper.Clone(mediaType.Examples) : null;
60+
Encoding = mediaType?.Encoding != null ? DictionaryCloneHelper.Clone(mediaType.Encoding) : null;
61+
Extensions = mediaType?.Extensions != null ? DictionaryCloneHelper.Clone(mediaType.Extensions) : null;
6162
}
6263

6364
/// <summary>

src/Microsoft.OpenApi/Models/OpenApiResponse.cs

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

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

@@ -62,10 +63,10 @@ public OpenApiResponse() {}
6263
public OpenApiResponse(OpenApiResponse response)
6364
{
6465
Description = response?.Description ?? Description;
65-
Headers = response?.Headers != null ? new Dictionary<string, OpenApiHeader>(response.Headers) : null;
66-
Content = response?.Content != null ? new Dictionary<string, OpenApiMediaType>(response.Content) : null;
67-
Links = response?.Links != null ? new Dictionary<string, OpenApiLink>(response.Links) : null;
68-
Extensions = response?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(response.Extensions) : null;
66+
Headers = response?.Headers != null ? DictionaryCloneHelper.Clone(response.Headers) : null;
67+
Content = response?.Content != null ? DictionaryCloneHelper.Clone(response.Content) : null;
68+
Links = response?.Links != null ? DictionaryCloneHelper.Clone(response.Links) : null;
69+
Extensions = response?.Extensions != null ? DictionaryCloneHelper.Clone(response.Extensions) : null;
6970
UnresolvedReference = response?.UnresolvedReference ?? UnresolvedReference;
7071
Reference = response?.Reference != null ? new(response?.Reference) : null;
7172
}

0 commit comments

Comments
 (0)