< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.OpenApi.OpenApiComponentShallowCopy
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/OpenApi/OpenApiComponentShallowCopy.cs
Tag: Kestrun/Kestrun@09cad9a8fdafda7aca15f5f5e888b4bbcc8f0674
Line coverage
55%
Covered lines: 43
Uncovered lines: 35
Coverable lines: 78
Total lines: 249
Line coverage: 55.1%
Branch coverage
40%
Covered branches: 20
Total branches: 50
Branch coverage: 40%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 03/26/2026 - 03:54:59 Line coverage: 55.1% (43/78) Branch coverage: 40% (20/50) Total lines: 249 Tag: Kestrun/Kestrun@844b5179fb0492dc6b1182bae3ff65fa7365521d 03/26/2026 - 03:54:59 Line coverage: 55.1% (43/78) Branch coverage: 40% (20/50) Total lines: 249 Tag: Kestrun/Kestrun@844b5179fb0492dc6b1182bae3ff65fa7365521d

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ConvertToSchema(...)50%66100%
CreateShallowCopy(...)100%44100%
CreateShallowCopy(...)75%44100%
CreateShallowCopy(...)0%2040%
CreateShallowCopy(...)0%2040%
CreateShallowCopy(...)0%2040%
CreateShallowCopy(...)0%2040%
CreateShallowCopy(...)75%4483.33%
CreateShallowCopy(...)0%2040%
CreateShallowCopy(...)100%44100%
CreateShallowCopy(...)50%22100%
CreateShallowCopy(...)25%9433.33%
DeepClone(...)50%22100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/OpenApi/OpenApiComponentShallowCopy.cs

#LineLine coverage
 1using Microsoft.OpenApi;
 2using System.Text.Json.Nodes;
 3
 4namespace Kestrun.OpenApi;
 5
 6/// <summary>
 7/// Helper methods for creating shallow copies of OpenAPI components.
 8/// </summary>
 9internal static class OpenApiComponentShallowCopy
 10{
 11    /// <summary>
 12    /// Converts an OpenApiRequestBody to an OpenApiSchema.
 13    /// </summary>
 14    /// <param name="requestBody">The OpenApiRequestBody to convert.</param>
 15    /// <returns>An OpenApiSchema representing the request body.</returns>
 16    internal static OpenApiSchema ConvertToSchema(this OpenApiRequestBody requestBody)
 17    {
 118        var clone = new OpenApiSchema
 119        {
 120            Description = requestBody.Description,
 121            Properties = requestBody.Content?.Values.FirstOrDefault()?.Schema?.Properties.CreateShallowCopy(),
 122            Extensions = requestBody.Extensions.CreateShallowCopy()
 123        };
 124        return clone;
 25    }
 26
 27    /// <summary>
 28    /// Creates a shallow copy of a dictionary of OpenApiExtension instances.
 29    /// </summary>
 30    /// <param name="extensions">The dictionary to copy.</param>
 31    /// <returns>A new dictionary with shallow copies of the OpenApiExtension instances.</returns>
 32    internal static IDictionary<string, IOpenApiExtension>? CreateShallowCopy(this IDictionary<string, IOpenApiExtension
 33    {
 234        if (extensions == null)
 35        {
 136            return null;
 37        }
 38
 139        var clone = new Dictionary<string, IOpenApiExtension>();
 440        foreach (var kvp in extensions)
 41        {
 142            clone[kvp.Key] = kvp.Value.CreateShallowCopy();
 43        }
 144        return clone;
 45    }
 46
 47    /// <summary>
 48    /// Creates a shallow copy of an OpenApiExtension instance.
 49    /// </summary>
 50    /// <param name="extension">The OpenApiExtension to copy.</param>
 51    /// <returns>A new OpenApiExtension instance with the same properties as the input extension.</returns>
 52    /// <exception cref="InvalidOperationException">Thrown when the extension is of an unsupported type.</exception>
 53    internal static IOpenApiExtension CreateShallowCopy(this IOpenApiExtension extension)
 54    {
 355        ArgumentNullException.ThrowIfNull(extension);
 56
 357        if (extension is JsonNodeExtension jsonNodeExtension)
 58        {
 259            var nodeClone = DeepClone(jsonNodeExtension.Node)
 260                ?? throw new InvalidOperationException("Unsupported IOpenApiExtension implementation.");
 261            return new JsonNodeExtension(nodeClone);
 62        }
 63
 164        throw new InvalidOperationException("Unsupported IOpenApiExtension implementation.");
 65    }
 66
 67    /// <summary>
 68    /// Creates a shallow copy of a dictionary of IOpenApiHeader instances.
 69    /// </summary>
 70    /// <param name="headers">The dictionary of headers to copy.</param>
 71    /// <returns>A new dictionary with shallow copies of the IOpenApiHeader instances.</returns>
 72    internal static IDictionary<string, IOpenApiHeader>? CreateShallowCopy(this IDictionary<string, IOpenApiHeader>? hea
 73    {
 074        if (headers == null)
 75        {
 076            return null;
 77        }
 78
 079        var clone = new Dictionary<string, IOpenApiHeader>();
 080        foreach (var kvp in headers)
 81        {
 082            clone[kvp.Key] = kvp.Value.CreateShallowCopy();
 83        }
 084        return clone;
 85    }
 86
 87    /// <summary>
 88    /// Creates a shallow copy of a dictionary of OpenApiMediaType instances.
 89    /// </summary>
 90    /// <param name="content">The dictionary to copy.</param>
 91    /// <returns>A new dictionary with shallow copies of the OpenApiMediaType instances.</returns>
 92    internal static IDictionary<string, IOpenApiMediaType>? CreateShallowCopy(this IDictionary<string, IOpenApiMediaType
 93    {
 094        if (content == null)
 95        {
 096            return null;
 97        }
 98
 099        var clone = new Dictionary<string, IOpenApiMediaType>();
 0100        foreach (var kvp in content)
 101        {
 0102            clone[kvp.Key] = kvp.Value.CreateShallowCopy();
 103        }
 0104        return clone;
 105    }
 106
 107    /// <summary>
 108    /// Creates a shallow copy of a dictionary of OpenApiExample instances.
 109    /// </summary>
 110    /// <param name="examples">The dictionary to copy.</param>
 111    /// <returns>A new dictionary with shallow copies of the OpenApiExample instances.</returns>
 112    internal static IDictionary<string, IOpenApiExample>? CreateShallowCopy(this IDictionary<string, IOpenApiExample>? e
 113    {
 0114        if (examples == null)
 115        {
 0116            return null;
 117        }
 118
 0119        var clone = new Dictionary<string, IOpenApiExample>();
 0120        foreach (var kvp in examples)
 121        {
 0122            clone[kvp.Key] = kvp.Value.CreateShallowCopy();
 123        }
 0124        return clone;
 125    }
 126
 127    /// <summary>
 128    /// Creates a shallow copy of a list of OpenApiSchema instances.
 129    /// </summary>
 130    /// <param name="schemas">The list to copy.</param>
 131    /// <returns>A new list containing shallow copies of the OpenApiSchema instances.</returns>
 132    internal static IList<IOpenApiSchema>? CreateShallowCopy(this IList<IOpenApiSchema>? schemas)
 133    {
 0134        if (schemas == null)
 135        {
 0136            return null;
 137        }
 0138        var cloneList = new List<IOpenApiSchema>();
 0139        foreach (var schema in schemas)
 140        {
 0141            cloneList.Add(schema.CreateShallowCopy());
 142        }
 0143        return cloneList;
 144    }
 145    /// <summary>
 146    /// Creates a shallow copy of a dictionary of OpenApiSchema instances.
 147    /// </summary>
 148    /// <param name="schemas">The dictionary to copy.</param>
 149    /// <returns>A new dictionary containing shallow copies of the OpenApiSchema instances.</returns>
 150    internal static Dictionary<string, IOpenApiSchema>? CreateShallowCopy(this IDictionary<string, IOpenApiSchema>? sche
 151    {
 1152        if (schemas == null)
 153        {
 0154            return null;
 155        }
 1156        var clone = new Dictionary<string, IOpenApiSchema>();
 4157        foreach (var kvp in schemas)
 158        {
 1159            clone[kvp.Key] = kvp.Value.CreateShallowCopy();
 160        }
 1161        return clone;
 162    }
 163
 164    /// <summary>
 165    /// Creates a shallow copy of a dictionary of IOpenApiLink instances.
 166    /// </summary>
 167    /// <param name="links">The dictionary of IOpenApiLink instances to copy.</param>
 168    /// <returns>A new dictionary containing shallow copies of the IOpenApiLink instances.</returns>
 169    internal static IDictionary<string, IOpenApiLink>? CreateShallowCopy(this IDictionary<string, IOpenApiLink>? links)
 170    {
 0171        if (links == null)
 172        {
 0173            return null;
 174        }
 175
 0176        var clone = new Dictionary<string, IOpenApiLink>();
 0177        foreach (var kvp in links)
 178        {
 0179            clone[kvp.Key] = kvp.Value.CreateShallowCopy();
 180        }
 0181        return clone;
 182    }
 183
 184    /// <summary>
 185    /// Creates a shallow copy of an OpenApiServer instance.
 186    /// </summary>
 187    /// <param name="server">The OpenApiServer instance to copy.</param>
 188    /// <returns>A new OpenApiServer instance with the same properties as the input instance.</returns>
 189    internal static OpenApiServer CreateShallowCopy(this OpenApiServer server)
 190    {
 1191        var clone = new OpenApiServer
 1192        {
 1193            Url = server.Url,
 1194            Description = server.Description,
 1195            Extensions = server.Extensions.CreateShallowCopy()
 1196        };
 197        // Clone Variables dictionary if it exists
 1198        if (server.Variables != null)
 199        {
 1200            clone.Variables = new Dictionary<string, OpenApiServerVariable>();
 4201            foreach (var variable in server.Variables)
 202            {
 1203                clone.Variables[variable.Key] = new OpenApiServerVariable(variable.Value);
 204            }
 205        }
 1206        return clone;
 207    }
 208
 209    /// <summary>
 210    /// Creates a shallow copy of a RuntimeExpressionAnyWrapper instance.
 211    /// </summary>
 212    /// <param name="expressionWrapper">The RuntimeExpressionAnyWrapper instance to copy.</param>
 213    /// <returns>A new RuntimeExpressionAnyWrapper instance with the same properties as the input instance.</returns>
 214    internal static RuntimeExpressionAnyWrapper CreateShallowCopy(this RuntimeExpressionAnyWrapper expressionWrapper)
 215    {
 1216        return new RuntimeExpressionAnyWrapper
 1217        {
 1218            Expression = expressionWrapper.Expression,
 1219            Any = expressionWrapper.Any != null ? DeepClone(expressionWrapper.Any) : null
 1220        };
 221    }
 222
 223    /// <summary>
 224    /// Creates a shallow copy of a dictionary of RuntimeExpressionAnyWrapper instances.
 225    /// </summary>
 226    /// <param name="parameters">The dictionary of RuntimeExpressionAnyWrapper instances to copy.</param>
 227    /// <returns>A new dictionary containing shallow copies of the RuntimeExpressionAnyWrapper instances.</returns>
 228    internal static IDictionary<string, RuntimeExpressionAnyWrapper>? CreateShallowCopy(this IDictionary<string, Runtime
 229    {
 1230        if (parameters == null)
 231        {
 1232            return null;
 233        }
 234
 0235        var clone = new Dictionary<string, RuntimeExpressionAnyWrapper>();
 0236        foreach (var kvp in parameters)
 237        {
 0238            clone[kvp.Key] = kvp.Value.CreateShallowCopy();
 239        }
 0240        return clone;
 241    }
 242
 243    /// <summary>
 244    /// Clones a JsonNode instance.
 245    /// </summary>
 246    /// <param name="value">The JsonNode to clone.</param>
 247    /// <returns>A new JsonNode instance that is a deep clone of the input value.</returns>
 3248    internal static JsonNode? DeepClone(JsonNode? value) => value?.DeepClone();
 249}