< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.OpenApi.OpenApiComponentClone
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/OpenApi/OpenApiComponentClone.cs
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
27%
Covered lines: 77
Uncovered lines: 207
Coverable lines: 284
Total lines: 645
Line coverage: 27.1%
Branch coverage
21%
Covered branches: 30
Total branches: 138
Branch coverage: 21.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/12/2025 - 17:27:19 Line coverage: 27.1% (77/284) Branch coverage: 21.7% (30/138) Total lines: 645 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd 12/12/2025 - 17:27:19 Line coverage: 27.1% (77/284) Branch coverage: 21.7% (30/138) Total lines: 645 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Clone(...)100%210%
Clone(...)0%4260%
Clone(...)0%2040%
Clone(...)100%210%
Clone(...)100%210%
ConvertToSchema(...)0%4260%
Clone(...)0%2040%
Clone(...)25%9433.33%
Clone(...)100%210%
Clone(...)0%2040%
Clone(...)0%2040%
Clone(...)0%4260%
Clone(...)100%210%
Clone(...)0%620%
Clone(...)100%210%
Clone(...)0%2040%
Clone(...)0%2040%
Clone(...)0%4260%
Clone(...)0%7280%
Clone(...)100%210%
Clone(...)50%22100%
Clone(...)50%5466.66%
Clone(...)47.61%4242100%
Clone(...)100%210%
Clone(...)0%2040%
Clone(...)100%44100%
Clone(...)0%2040%
Clone(...)0%2040%
Clone(...)100%210%
Clone(...)0%620%
Clone(...)0%620%
Clone(...)0%620%
Clone(...)0%2040%
JsonNodeClone(...)100%22100%

File(s)

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

#LineLine coverage
 1using Microsoft.OpenApi;
 2using System.Text.Json.Nodes;
 3
 4namespace Kestrun.OpenApi;
 5
 6/// <summary>
 7/// Helper methods for cloning OpenAPI components.
 8/// </summary>
 9public static class OpenApiComponentClone
 10{
 11    #region Parameter
 12    /// <summary>
 13    /// Clones an OpenApiParameterReference instance.
 14    /// </summary>
 15    /// <param name="parameter">The OpenApiParameterReference to clone.</param>
 16    /// <returns>A new OpenApiParameterReference instance with the same properties as the input parameter.</returns>
 17    public static OpenApiParameterReference Clone(this OpenApiParameterReference parameter)
 18    {
 019        var clone = new OpenApiParameterReference(parameter.Reference.Id!)
 020        {
 021            Description = parameter.Description,
 022        };
 023        return clone;
 24    }
 25
 26    /// <summary>
 27    /// Clones an OpenApiParameter instance.
 28    /// </summary>
 29    /// <param name="parameter">The OpenApiParameter to clone.</param>
 30    /// <returns>A new OpenApiParameter instance with the same properties as the input parameter.</returns>
 31    public static OpenApiParameter Clone(this OpenApiParameter parameter)
 32    {
 033        var clone = new OpenApiParameter
 034        {
 035            Name = parameter.Name,
 036            In = parameter.In,
 037            Description = parameter.Description,
 038            Required = parameter.Required,
 039            Style = parameter.Style,
 040            Explode = parameter.Explode,
 041            AllowReserved = parameter.AllowReserved,
 042            Schema = parameter.Schema?.Clone(),
 043            Examples = parameter.Examples?.Clone(),
 044            Example = JsonNodeClone(parameter.Example),
 045            Content = parameter.Content?.Clone(),
 046            Extensions = parameter.Extensions.Clone(),
 047            AllowEmptyValue = parameter.AllowEmptyValue,
 048            Deprecated = parameter.Deprecated
 049        };
 050        return clone;
 51    }
 52
 53    /// <summary>
 54    /// Clones an IOpenApiParameter instance.
 55    /// </summary>
 56    /// <param name="parameter">The IOpenApiParameter instance to clone.</param>
 57    /// <returns>A cloned instance of IOpenApiParameter.</returns>
 58    /// <exception cref="InvalidOperationException">Thrown when the IOpenApiParameter implementation is unsupported.</ex
 59    public static IOpenApiParameter Clone(this IOpenApiParameter parameter)
 60    {
 61        // Determine the actual type of IOpenApiParameter and clone accordingly
 062        return parameter switch
 063        {
 064            OpenApiParameter param => param.Clone(),
 065            OpenApiParameterReference paramRef => paramRef.Clone(),
 066            _ => throw new InvalidOperationException("Unsupported IOpenApiParameter implementation."),
 067        };
 68    }
 69    #endregion
 70    #region RequestBody
 71    /// <summary>
 72    /// Clones an OpenApiRequestBodyReference instance.
 73    /// </summary>
 74    /// <param name="requestBody">The OpenApiRequestBodyReference to clone.</param>
 75    /// <returns>A new OpenApiRequestBodyReference instance with the same properties as the input requestBody.</returns>
 76    public static OpenApiRequestBodyReference Clone(this OpenApiRequestBodyReference requestBody)
 77    {
 078        var clone = new OpenApiRequestBodyReference(requestBody.Reference.Id!)
 079        {
 080            Description = requestBody.Description,
 081        };
 082        return clone;
 83    }
 84    /// <summary>
 85    /// Clones an OpenApiRequestBody instance.
 86    /// </summary>
 87    /// <param name="requestBody">The OpenApiRequestBody to clone.</param>
 88    /// <returns>A new OpenApiRequestBody instance with the same properties as the input requestBody.</returns>
 89    public static OpenApiRequestBody Clone(this OpenApiRequestBody requestBody)
 90    {
 091        var clone = new OpenApiRequestBody
 092        {
 093            Description = requestBody.Description,
 094            Required = requestBody.Required,
 095            Content = requestBody.Content.Clone(),
 096            Extensions = requestBody.Extensions.Clone()
 097        };
 098        return clone;
 99    }
 100
 101    /// <summary>
 102    /// Converts an OpenApiRequestBody to an OpenApiSchema.
 103    /// </summary>
 104    /// <param name="requestBody">The OpenApiRequestBody to convert.</param>
 105    /// <returns>An OpenApiSchema representing the request body.</returns>
 106    public static OpenApiSchema ConvertToSchema(this OpenApiRequestBody requestBody)
 107    {
 0108        var clone = new OpenApiSchema
 0109        {
 0110            Description = requestBody.Description,
 0111            Properties = requestBody.Content?.Values.FirstOrDefault()?.Schema?.Properties.Clone(),
 0112            Extensions = requestBody.Extensions.Clone()
 0113        };
 0114        return clone;
 115    }
 116    /// <summary>
 117    /// Clones an IOpenApiRequestBody instance.
 118    /// </summary>
 119    /// <param name="parameter">The IOpenApiRequestBody instance to clone.</param>
 120    /// <returns>A cloned instance of IOpenApiRequestBody.</returns>
 121    /// <exception cref="InvalidOperationException">Thrown when the IOpenApiRequestBody implementation is unsupported.</
 122    public static IOpenApiRequestBody Clone(this IOpenApiRequestBody parameter)
 123    {
 124        // Determine the actual type of IOpenApiParameter and clone accordingly
 0125        return parameter switch
 0126        {
 0127            OpenApiRequestBody param => param.Clone(),
 0128            OpenApiRequestBodyReference paramRef => paramRef.Clone(),
 0129            _ => throw new InvalidOperationException("Unsupported IOpenApiRequestBody implementation."),
 0130        };
 131    }
 132    #endregion
 133    #region Extensions
 134    /// <summary>
 135    /// Clones a dictionary of OpenApiExtension instances.
 136    /// </summary>
 137    /// <param name="extensions">The dictionary to clone.</param>
 138    /// <returns>A new dictionary with cloned OpenApiExtension instances.</returns>
 139    public static IDictionary<string, IOpenApiExtension>? Clone(this IDictionary<string, IOpenApiExtension>? extensions)
 140    {
 5141        if (extensions == null)
 142        {
 5143            return null;
 144        }
 145
 0146        var clone = new Dictionary<string, IOpenApiExtension>();
 0147        foreach (var kvp in extensions)
 148        {
 0149            clone[kvp.Key] = kvp.Value.Clone();
 150        }
 0151        return clone;
 152    }
 153
 154    /// <summary>
 155    /// Clones an OpenApiExtension instance.
 156    /// </summary>
 157    /// <param name="extension">The OpenApiExtension to clone.</param>
 158    /// <returns>A new OpenApiExtension instance with the same properties as the input extension.</returns>
 159    /// <exception cref="InvalidOperationException">Thrown when the extension is of an unsupported type.</exception>
 0160    public static IOpenApiExtension Clone(this IOpenApiExtension extension) => throw new InvalidOperationException("Unsu
 161
 162    #endregion
 163
 164    #region Header
 165    /// <summary>
 166    /// Clones a dictionary of IOpenApiHeader instances.
 167    /// </summary>
 168    /// <param name="headers">The dictionary of headers to clone.</param>
 169    /// <returns>A new dictionary with cloned IOpenApiHeader instances.</returns>
 170    public static IDictionary<string, IOpenApiHeader>? Clone(this IDictionary<string, IOpenApiHeader>? headers)
 171    {
 0172        if (headers == null)
 173        {
 0174            return null;
 175        }
 176
 0177        var clone = new Dictionary<string, IOpenApiHeader>();
 0178        foreach (var kvp in headers)
 179        {
 0180            clone[kvp.Key] = kvp.Value.Clone();
 181        }
 0182        return clone;
 183    }
 184
 185    /// <summary>
 186    /// Clones an IOpenApiHeader instance.
 187    /// </summary>
 188    /// <param name="header">The IOpenApiHeader to clone.</param>
 189    /// <returns>A new IOpenApiHeader instance with the same properties as the input header.</returns>
 190    /// <exception cref="InvalidOperationException">Thrown when the header is of an unsupported type.</exception>
 191    public static IOpenApiHeader Clone(this IOpenApiHeader header) =>
 0192    header switch
 0193    {
 0194        OpenApiHeader headerObj => headerObj.Clone(),
 0195        OpenApiHeaderReference headerRef => headerRef.Clone(),
 0196        _ => throw new InvalidOperationException("Unsupported IOpenApiHeader implementation.")
 0197    };
 198
 199    /// <summary>
 200    /// Clones an OpenApiHeader instance.
 201    /// </summary>
 202    /// <param name="header">The OpenApiHeader to clone.</param>
 203    /// <returns>A new OpenApiHeader instance with the same properties as the input header.</returns>
 204    public static OpenApiHeader Clone(this OpenApiHeader header)
 205    {
 0206        var clone = new OpenApiHeader
 0207        {
 0208            Description = header.Description,
 0209            Required = header.Required,
 0210            Deprecated = header.Deprecated,
 0211            Style = header.Style,
 0212            Explode = header.Explode,
 0213            AllowEmptyValue = header.AllowEmptyValue,
 0214            Schema = header.Schema?.Clone(),
 0215            Examples = header.Examples?.Clone(),
 0216            Example = JsonNodeClone(header.Example),
 0217            Content = header.Content?.Clone(),
 0218            Extensions = header.Extensions.Clone(),
 0219            AllowReserved = header.AllowReserved
 0220        };
 0221        return clone;
 222    }
 223    /// <summary>
 224    /// Clones an OpenApiHeaderReference instance.
 225    /// </summary>
 226    /// <param name="header">The OpenApiHeaderReference to clone.</param>
 227    /// <returns>A new OpenApiHeaderReference instance with the same properties as the input header.</returns>
 228    public static OpenApiHeaderReference Clone(this OpenApiHeaderReference header)
 229    {
 0230        var clone = new OpenApiHeaderReference(header.Reference.Id!)
 0231        {
 0232            Description = header.Description,
 0233        };
 0234        return clone;
 235    }
 236    #endregion
 237    #region Response
 238
 239    /// <summary>
 240    /// Clones an OpenApiResponse instance.
 241    /// </summary>
 242    /// <param name="response">The OpenApiResponse to clone.</param>
 243    /// <returns>A new OpenApiResponse instance with the same properties as the input response.</returns>
 244    public static OpenApiResponse Clone(this OpenApiResponse response)
 245    {
 0246        var clone = new OpenApiResponse
 0247        {
 0248            Description = response.Description,
 0249            Headers = response.Headers?.Clone(),
 0250            Content = Clone(response.Content),
 0251            Links = response.Links.Clone(),
 0252            Extensions = response.Extensions.Clone()
 0253        };
 0254        return clone;
 255    }
 256    /// <summary>
 257    /// Clones an OpenApiResponseReference instance.
 258    /// </summary>
 259    /// <param name="response">The OpenApiResponseReference to clone.</param>
 260    /// <returns>A new OpenApiResponseReference instance with the same properties as the input response.</returns>
 261    public static OpenApiResponseReference Clone(this OpenApiResponseReference response)
 262    {
 0263        var clone = new OpenApiResponseReference(response.Reference.Id!)
 0264        {
 0265            Description = response.Description,
 0266        };
 0267        return clone;
 268    }
 269
 270    /// <summary>
 271    /// Clones an IOpenApiResponse instance.
 272    /// </summary>
 273    /// <param name="response"> The IOpenApiResponse instance to clone.</param>
 274    /// <returns>A cloned IOpenApiResponse instance.</returns>
 275    /// <exception cref="InvalidOperationException">Thrown when the IOpenApiResponse implementation is unsupported.</exc
 276    public static IOpenApiResponse Clone(this IOpenApiResponse response)
 277    {
 278        // Determine the actual type of IOpenApiResponse and clone accordingly
 0279        return response switch
 0280        {
 0281            OpenApiResponse resp => resp.Clone(),
 0282            OpenApiResponseReference respRef => respRef.Clone(),
 0283            _ => throw new InvalidOperationException("Unsupported IOpenApiResponse implementation."),
 0284        };
 285    }
 286
 287    #endregion
 288    #region MediaType
 289    /// <summary>
 290    /// Clones a dictionary of OpenApiMediaType instances.
 291    /// </summary>
 292    /// <param name="content">The dictionary to clone.</param>
 293    /// <returns>A new dictionary with cloned OpenApiMediaType instances.</returns>
 294    public static IDictionary<string, OpenApiMediaType>? Clone(this IDictionary<string, OpenApiMediaType>? content)
 295    {
 0296        if (content == null)
 297        {
 0298            return null;
 299        }
 300
 0301        var clone = new Dictionary<string, OpenApiMediaType>();
 0302        foreach (var kvp in content)
 303        {
 0304            clone[kvp.Key] = kvp.Value.Clone();
 305        }
 0306        return clone;
 307    }
 308
 309    /// <summary>
 310    /// Clones an OpenApiMediaType instance.
 311    /// </summary>
 312    /// <param name="mediaType">The OpenApiMediaType to clone.</param>
 313    /// <returns>A new OpenApiMediaType instance with the same properties as the input mediaType.</returns>
 314    public static OpenApiMediaType Clone(this OpenApiMediaType mediaType)
 315    {
 0316        var clone = new OpenApiMediaType
 0317        {
 0318            Schema = mediaType.Schema?.Clone(),
 0319            Example = mediaType.Example != null ? JsonNodeClone(mediaType.Example) : null,
 0320            Examples = mediaType.Examples.Clone(),
 0321            Encoding = mediaType.Encoding != null ? new Dictionary<string, OpenApiEncoding>(mediaType.Encoding) : null,
 0322            Extensions = mediaType.Extensions.Clone()
 0323        };
 0324        return clone;
 325    }
 326    #endregion
 327    #region Example
 328    /// <summary>
 329    /// Clones a dictionary of OpenApiExample instances.
 330    /// </summary>
 331    /// <param name="examples">The dictionary to clone.</param>
 332    /// <returns>A new dictionary with cloned OpenApiExample instances.</returns>
 333    public static IDictionary<string, IOpenApiExample>? Clone(this IDictionary<string, IOpenApiExample>? examples)
 334    {
 0335        if (examples == null)
 336        {
 0337            return null;
 338        }
 339
 0340        var clone = new Dictionary<string, IOpenApiExample>();
 0341        foreach (var kvp in examples)
 342        {
 0343            clone[kvp.Key] = kvp.Value switch
 0344            {
 0345                OpenApiExample exampleObj => exampleObj.Clone(),
 0346                OpenApiExampleReference exampleRef => exampleRef.Clone(),
 0347                _ => throw new InvalidOperationException("Unsupported IOpenApiExample implementation."),
 0348            };
 349        }
 0350        return clone;
 351    }
 352
 353    /// <summary>
 354    /// Clones an OpenApiExampleReference instance.
 355    /// </summary>
 356    /// <param name="example">The OpenApiExampleReference to clone.</param>
 357    /// <returns>A new OpenApiExampleReference instance with the same properties as the input instance.</returns>
 358    public static OpenApiExampleReference Clone(this OpenApiExampleReference example)
 359    {
 0360        var clone = new OpenApiExampleReference(example.Reference.Id!)
 0361        {
 0362            Description = example.Description,
 0363            Summary = example.Summary
 0364        };
 0365        return clone;
 366    }
 367
 368    /// <summary>
 369    /// Clones an OpenApiExample instance.
 370    /// </summary>
 371    /// <param name="example">The OpenApiExample to clone.</param>
 372    /// <returns>A new OpenApiExample instance with the same properties as the input example.</returns>
 373    public static OpenApiExample Clone(this OpenApiExample example)
 374    {
 2375        var clone = new OpenApiExample
 2376        {
 2377            Summary = example.Summary,
 2378            Description = example.Description,
 2379            Value = example.Value != null ? JsonNodeClone(example.Value) : null,
 2380            ExternalValue = example.ExternalValue,
 2381            Extensions = example.Extensions.Clone()
 2382        };
 2383        return clone;
 384    }
 385    #endregion
 386    #region Schema
 387    /// <summary>
 388    /// Clones an IOpenApiSchema instance.
 389    /// </summary>
 390    /// <param name="schema">The IOpenApiSchema to clone.</param>
 391    /// <returns>A new IOpenApiSchema instance with the same properties as the input schema.</returns>
 392    public static IOpenApiSchema Clone(this IOpenApiSchema schema) =>
 3393    schema switch
 3394    {
 0395        OpenApiSchemaReference schemaRef => schemaRef.Clone(),
 3396        OpenApiSchema schemaObj => schemaObj.Clone(),
 0397        _ => throw new InvalidOperationException("Unsupported IOpenApiSchema implementation.")
 3398    };
 399
 400    /// <summary>
 401    /// Clones an OpenApiSchema instance.
 402    /// </summary>
 403    /// <param name="schema">The OpenApiSchema to clone.</param>
 404    /// <returns>A new OpenApiSchema instance with the same properties as the input schema.</returns>
 405    public static OpenApiSchema Clone(this OpenApiSchema schema)
 406    {
 3407        var clone = new OpenApiSchema()
 3408        {
 3409            Title = schema.Title,
 3410            Id = schema.Id,
 3411            Const = schema.Const,
 3412            Schema = schema.Schema,
 3413            Comment = schema.Comment,
 3414            Vocabulary = schema.Vocabulary != null ? new Dictionary<string, bool>(schema.Vocabulary) : null,
 3415            DynamicAnchor = schema.DynamicAnchor,
 3416            DynamicRef = schema.DynamicRef,
 3417            Definitions = schema.Definitions.Clone(),
 3418            UnevaluatedProperties = schema.UnevaluatedProperties,
 3419            ExclusiveMaximum = schema.ExclusiveMaximum,
 3420            ExclusiveMinimum = schema.ExclusiveMinimum,
 3421
 3422            Type = schema.Type,
 3423            Format = schema.Format,
 3424            Description = schema.Description,
 3425            Maximum = schema.Maximum,
 3426            Minimum = schema.Minimum,
 3427            MaxLength = schema.MaxLength,
 3428            MinLength = schema.MinLength,
 3429            Pattern = schema.Pattern,
 3430            MultipleOf = schema.MultipleOf,
 3431            Default = JsonNodeClone(schema.Default),
 3432            ReadOnly = schema.ReadOnly,
 3433            WriteOnly = schema.WriteOnly,
 3434            AllOf = schema.AllOf?.Clone(),
 3435            OneOf = schema.OneOf?.Clone(),
 3436            AnyOf = schema.AnyOf?.Clone(),
 3437            Not = schema.Not?.Clone(),
 3438            Required = schema.Required != null ? new HashSet<string>(schema.Required) : null,
 3439            Items = schema.Items?.Clone(),
 3440            MaxItems = schema.MaxItems,
 3441            MinItems = schema.MinItems,
 3442            UniqueItems = schema.UniqueItems,
 3443            Properties = schema.Properties.Clone(),
 3444            PatternProperties = schema.PatternProperties?.Clone(),
 3445            MaxProperties = schema.MaxProperties,
 3446            MinProperties = schema.MinProperties,
 3447            AdditionalPropertiesAllowed = schema.AdditionalPropertiesAllowed,
 3448            AdditionalProperties = schema.AdditionalProperties?.Clone(),
 3449            Discriminator = schema.Discriminator != null ? new(schema.Discriminator) : null,
 3450            Example = schema.Example != null ? JsonNodeClone(schema.Example) : null,
 3451            Examples = schema.Examples != null ? [.. schema.Examples] : null,
 3452            Enum = schema.Enum != null ? [.. schema.Enum] : null,
 3453            ExternalDocs = schema.ExternalDocs != null ? new(schema.ExternalDocs) : null,
 3454            Deprecated = schema.Deprecated,
 3455            Xml = schema.Xml != null ? new(schema.Xml) : null,
 3456            Extensions = schema.Extensions.Clone(),
 3457            Metadata = schema is IMetadataContainer { Metadata: not null } mContainer ? new Dictionary<string, object>(m
 3458            UnrecognizedKeywords = schema.UnrecognizedKeywords != null ? new Dictionary<string, JsonNode>(schema.Unrecog
 3459            DependentRequired = schema.DependentRequired != null ? new Dictionary<string, HashSet<string>>(schema.Depend
 3460        };
 3461        return clone;
 462    }
 463    /// <summary>
 464    /// Clones an OpenApiSchemaReference instance.
 465    /// </summary>
 466    /// <param name="schemaRef">The OpenApiSchemaReference to clone</param>
 467    /// <returns>A new OpenApiSchemaReference instance with the same properties as the input instance.</returns>
 468    public static OpenApiSchemaReference Clone(this OpenApiSchemaReference schemaRef)
 469    {
 0470        var cloneRef = new OpenApiSchemaReference(referenceId: schemaRef.Reference.Id!)
 0471        {
 0472            Reference = schemaRef.Reference,
 0473            Title = schemaRef.Title,
 0474            Description = schemaRef.Description
 0475        };
 0476        return cloneRef;
 477    }
 478    /// <summary>
 479    /// Clones a list of OpenApiSchema instances.
 480    /// </summary>
 481    /// <param name="schemas">The list to clone.</param>
 482    /// <returns>A new list containing cloned OpenApiSchema instances.</returns>
 483    public static IList<IOpenApiSchema>? Clone(this IList<IOpenApiSchema>? schemas)
 484    {
 0485        if (schemas == null)
 486        {
 0487            return null;
 488        }
 0489        var cloneList = new List<IOpenApiSchema>();
 0490        foreach (var schema in schemas)
 491        {
 0492            cloneList.Add(schema.Clone());
 493        }
 0494        return cloneList;
 495    }
 496    /// <summary>
 497    /// Clones a dictionary of OpenApiSchema instances.
 498    /// </summary>
 499    /// <param name="schemas">The dictionary to clone.</param>
 500    /// <returns>A new dictionary containing cloned OpenApiSchema instances.</returns>
 501    public static Dictionary<string, IOpenApiSchema>? Clone(this IDictionary<string, IOpenApiSchema>? schemas)
 502    {
 6503        if (schemas == null)
 504        {
 5505            return null;
 506        }
 1507        var clone = new Dictionary<string, IOpenApiSchema>();
 6508        foreach (var kvp in schemas)
 509        {
 2510            clone[kvp.Key] = kvp.Value.Clone();
 511        }
 1512        return clone;
 513    }
 514    #endregion
 515    #region Link
 516    /// <summary>
 517    /// Clones a dictionary of IOpenApiLink instances.
 518    /// </summary>
 519    /// <param name="links">The dictionary of IOpenApiLink instances to clone.</param>
 520    /// <returns>A new dictionary containing cloned IOpenApiLink instances.</returns>
 521    public static IDictionary<string, IOpenApiLink>? Clone(this IDictionary<string, IOpenApiLink>? links)
 522    {
 0523        if (links == null)
 524        {
 0525            return null;
 526        }
 527
 0528        var clone = new Dictionary<string, IOpenApiLink>();
 0529        foreach (var kvp in links)
 530        {
 0531            clone[kvp.Key] = kvp.Value.Clone();
 532        }
 0533        return clone;
 534    }
 535
 536    /// <summary>
 537    /// Clones an IOpenApiLink instance.
 538    /// </summary>
 539    /// <param name="link">The IOpenApiLink to clone.</param>
 540    /// <returns>A new IOpenApiLink instance with the same properties as the input link.</returns>
 541    public static IOpenApiLink Clone(this IOpenApiLink link) =>
 0542    link switch
 0543    {
 0544        OpenApiLink linkObj => linkObj.Clone(),
 0545        OpenApiLinkReference linkRef => linkRef.Clone(),
 0546        _ => throw new InvalidOperationException("Unsupported IOpenApiLink implementation.")
 0547    };
 548
 549    /// <summary>
 550    /// Clones an OpenApiLinkReference instance.
 551    /// </summary>
 552    /// <param name="link">The OpenApiLinkReference instance to clone.</param>
 553    /// <returns>A new OpenApiLinkReference instance with the same properties as the input instance.</returns>
 554    public static OpenApiLinkReference Clone(this OpenApiLinkReference link)
 555    {
 0556        var clone = new OpenApiLinkReference(link.Reference.Id!)
 0557        {
 0558            Reference = link.Reference
 0559        };
 0560        return clone;
 561    }
 562
 563    /// <summary>
 564    /// Clones an OpenApiLink instance.
 565    /// </summary>
 566    /// <param name="link">The OpenApiLink instance to clone.</param>
 567    /// <returns>A new OpenApiLink instance with the same properties as the input instance.</returns>
 568    public static OpenApiLink Clone(this OpenApiLink link)
 569    {
 0570        var clone = new OpenApiLink
 0571        {
 0572            OperationRef = link.OperationRef,
 0573            OperationId = link.OperationId,
 0574            Parameters = link.Parameters.Clone(),
 0575            RequestBody = link.RequestBody!.Clone(),
 0576            Description = link.Description,
 0577            Server = link.Server?.Clone(),
 0578            Extensions = link.Extensions.Clone()
 0579        };
 0580        return clone;
 581    }
 582    #endregion
 583
 584    /// <summary>
 585    /// Clones an OpenApiServer instance.
 586    /// </summary>
 587    /// <param name="server">The OpenApiServer instance to clone.</param>
 588    /// <returns>A new OpenApiServer instance with the same properties as the input instance.</returns>
 589    public static OpenApiServer Clone(this OpenApiServer server)
 590    {
 0591        var clone = new OpenApiServer
 0592        {
 0593            Url = server.Url,
 0594            Description = server.Description,
 0595            Variables = server.Variables != null ? new Dictionary<string, OpenApiServerVariable>(server.Variables) : nul
 0596            Extensions = server.Extensions.Clone()
 0597        };
 0598        return clone;
 599    }
 600
 601    #region RuntimeExpression
 602    /// <summary>
 603    /// Clones a RuntimeExpressionAnyWrapper instance.
 604    /// </summary>
 605    /// <param name="expressionWrapper">The RuntimeExpressionAnyWrapper instance to clone.</param>
 606    /// <returns>A new RuntimeExpressionAnyWrapper instance with the same properties as the input instance.</returns>
 607    public static RuntimeExpressionAnyWrapper Clone(this RuntimeExpressionAnyWrapper expressionWrapper)
 608    {
 0609        return new RuntimeExpressionAnyWrapper
 0610        {
 0611            Expression = expressionWrapper.Expression,
 0612            Any = expressionWrapper.Any != null ? JsonNodeClone(expressionWrapper.Any) : null
 0613        };
 614    }
 615
 616    /// <summary>
 617    /// Clones a dictionary of RuntimeExpressionAnyWrapper instances.
 618    /// </summary>
 619    /// <param name="parameters">The dictionary of RuntimeExpressionAnyWrapper instances to clone.</param>
 620    /// <returns>A new dictionary that is a deep clone of the input dictionary.</returns>
 621    public static IDictionary<string, RuntimeExpressionAnyWrapper>? Clone(this IDictionary<string, RuntimeExpressionAnyW
 622    {
 0623        if (parameters == null)
 624        {
 0625            return null;
 626        }
 627
 0628        var clone = new Dictionary<string, RuntimeExpressionAnyWrapper>();
 0629        foreach (var kvp in parameters)
 630        {
 0631            clone[kvp.Key] = kvp.Value.Clone();
 632        }
 0633        return clone;
 634    }
 635
 636    #endregion
 637    #region JsonNode
 638    /// <summary>
 639    /// Clones a JsonNode instance.
 640    /// </summary>
 641    /// <param name="value">The JsonNode to clone.</param>
 642    /// <returns>A new JsonNode instance that is a deep clone of the input value.</returns>
 5643    public static JsonNode? JsonNodeClone(JsonNode? value) => value?.DeepClone();
 644    #endregion
 645}

Methods/Properties

Clone(Microsoft.OpenApi.OpenApiParameterReference)
Clone(Microsoft.OpenApi.OpenApiParameter)
Clone(Microsoft.OpenApi.IOpenApiParameter)
Clone(Microsoft.OpenApi.OpenApiRequestBodyReference)
Clone(Microsoft.OpenApi.OpenApiRequestBody)
ConvertToSchema(Microsoft.OpenApi.OpenApiRequestBody)
Clone(Microsoft.OpenApi.IOpenApiRequestBody)
Clone(System.Collections.Generic.IDictionary`2<System.String,Microsoft.OpenApi.IOpenApiExtension>)
Clone(Microsoft.OpenApi.IOpenApiExtension)
Clone(System.Collections.Generic.IDictionary`2<System.String,Microsoft.OpenApi.IOpenApiHeader>)
Clone(Microsoft.OpenApi.IOpenApiHeader)
Clone(Microsoft.OpenApi.OpenApiHeader)
Clone(Microsoft.OpenApi.OpenApiHeaderReference)
Clone(Microsoft.OpenApi.OpenApiResponse)
Clone(Microsoft.OpenApi.OpenApiResponseReference)
Clone(Microsoft.OpenApi.IOpenApiResponse)
Clone(System.Collections.Generic.IDictionary`2<System.String,Microsoft.OpenApi.OpenApiMediaType>)
Clone(Microsoft.OpenApi.OpenApiMediaType)
Clone(System.Collections.Generic.IDictionary`2<System.String,Microsoft.OpenApi.IOpenApiExample>)
Clone(Microsoft.OpenApi.OpenApiExampleReference)
Clone(Microsoft.OpenApi.OpenApiExample)
Clone(Microsoft.OpenApi.IOpenApiSchema)
Clone(Microsoft.OpenApi.OpenApiSchema)
Clone(Microsoft.OpenApi.OpenApiSchemaReference)
Clone(System.Collections.Generic.IList`1<Microsoft.OpenApi.IOpenApiSchema>)
Clone(System.Collections.Generic.IDictionary`2<System.String,Microsoft.OpenApi.IOpenApiSchema>)
Clone(System.Collections.Generic.IDictionary`2<System.String,Microsoft.OpenApi.IOpenApiLink>)
Clone(Microsoft.OpenApi.IOpenApiLink)
Clone(Microsoft.OpenApi.OpenApiLinkReference)
Clone(Microsoft.OpenApi.OpenApiLink)
Clone(Microsoft.OpenApi.OpenApiServer)
Clone(Microsoft.OpenApi.RuntimeExpressionAnyWrapper)
Clone(System.Collections.Generic.IDictionary`2<System.String,Microsoft.OpenApi.RuntimeExpressionAnyWrapper>)
JsonNodeClone(System.Text.Json.Nodes.JsonNode)