Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions 36 src/Microsoft.OpenApi/Any/OpenApiAnyCloneHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.Reflection;

namespace Microsoft.OpenApi.Any
{
/// <summary>
/// Contains logic for cloning objects through copy constructors.
/// </summary>
public class OpenApiAnyCloneHelper
{
/// <summary>
/// Clones an instance of <see cref="IOpenApiAny"/> object from the copy constructor
/// </summary>
/// <param name="obj">The object instance.</param>
/// <returns>A clone copy or the object itself.</returns>
public static IOpenApiAny CloneFromCopyConstructor(IOpenApiAny obj)
{
if (obj != null)
{
var t = obj.GetType();
foreach (ConstructorInfo ci in t.GetConstructors())
{
ParameterInfo[] pi = ci.GetParameters();
if (pi.Length == 1 && pi[0].ParameterType == t)
{
return (IOpenApiAny)ci.Invoke(new object[] { obj });
}
}
}

return obj;
}
}
}
14 changes: 14 additions & 0 deletions 14 src/Microsoft.OpenApi/Any/OpenApiArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using Microsoft.OpenApi.Writers;
using System;
using System.Collections.Generic;

namespace Microsoft.OpenApi.Any
Expand All @@ -16,6 +17,19 @@ public class OpenApiArray : List<IOpenApiAny>, IOpenApiAny
/// </summary>
public AnyType AnyType { get; } = AnyType.Array;

/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiArray() { }

/// <summary>
/// Initializes a copy of <see cref="OpenApiArray"/> object
/// </summary>
public OpenApiArray(OpenApiArray array)
{
AnyType = array.AnyType;
}

/// <summary>
/// Write out contents of OpenApiArray to passed writer
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions 13 src/Microsoft.OpenApi/Any/OpenApiNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ public class OpenApiNull : IOpenApiAny
/// </summary>
public AnyType AnyType { get; } = AnyType.Null;
baywet marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiNull() { }

/// <summary>
/// Initializes a copy of <see cref="OpenApiNull"/> object
/// </summary>
public OpenApiNull(OpenApiNull openApiNull)
{
AnyType = openApiNull.AnyType;
}

/// <summary>
/// Write out null representation
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions 13 src/Microsoft.OpenApi/Any/OpenApiObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ public class OpenApiObject : Dictionary<string, IOpenApiAny>, IOpenApiAny
/// </summary>
public AnyType AnyType { get; } = AnyType.Object;
baywet marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Parameterless constructor
/// </summary>
public OpenApiObject() { }

/// <summary>
/// Initializes a copy of <see cref="OpenApiObject"/> object
/// </summary>
public OpenApiObject(OpenApiObject obj)
{
AnyType = obj.AnyType;
}

/// <summary>
/// Serialize OpenApiObject to writer
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions 9 src/Microsoft.OpenApi/Any/OpenApiPrimitive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public OpenApiPrimitive(T value)
Value = value;
}

/// <summary>
/// Initializes a copy of an <see cref="IOpenApiPrimitive"/> object
/// </summary>
/// <param name="openApiPrimitive"></param>
public OpenApiPrimitive(OpenApiPrimitive<T> openApiPrimitive)
{
Value = openApiPrimitive.Value;
}

/// <summary>
/// The kind of <see cref="IOpenApiAny"/>.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions 16 src/Microsoft.OpenApi/Models/OpenApiCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ public class OpenApiCallback : IOpenApiSerializable, IOpenApiReferenceable, IOpe
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiCallback() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiCallback"/> object
/// </summary>
public OpenApiCallback(OpenApiCallback callback)
{
PathItems = new(callback.PathItems);
UnresolvedReference = callback.UnresolvedReference;
Reference = new(callback.Reference);
Extensions = new Dictionary<string, IOpenApiExtension>(callback.Extensions);
}

/// <summary>
/// Add a <see cref="OpenApiPathItem"/> into the <see cref="PathItems"/>.
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions 22 src/Microsoft.OpenApi/Models/OpenApiComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiComponents() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiComponents"/> object
/// </summary>
public OpenApiComponents(OpenApiComponents components)
{
Schemas = new Dictionary<string, OpenApiSchema>(components.Schemas);
Responses = new Dictionary<string, OpenApiResponse>(components.Responses);
Parameters = new Dictionary<string, OpenApiParameter>(components.Parameters);
Examples = new Dictionary<string, OpenApiExample>(components.Examples);
RequestBodies = new Dictionary<string, OpenApiRequestBody>(components.RequestBodies);
Headers = new Dictionary<string, OpenApiHeader>(components.Headers);
SecuritySchemes = new Dictionary<string, OpenApiSecurityScheme>(components.SecuritySchemes);
Links = new Dictionary<string, OpenApiLink>(components.Links);
Callbacks = new Dictionary<string, OpenApiCallback>(components.Callbacks);
Extensions = new Dictionary<string, IOpenApiExtension>(components.Extensions);
}

/// <summary>
/// Serialize <see cref="OpenApiComponents"/> to Open Api v3.0.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions 16 src/Microsoft.OpenApi/Models/OpenApiContact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiContact() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiContact"/> instance
/// </summary>
public OpenApiContact(OpenApiContact contact)
{
Name = contact.Name;
Url = new Uri(contact.Url.OriginalString);
Email = contact.Email;
Extensions = new Dictionary<string, IOpenApiExtension>(contact.Extensions);
}

/// <summary>
/// Serialize <see cref="OpenApiContact"/> to Open Api v3.0
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions 14 src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ public class OpenApiDiscriminator : IOpenApiSerializable
/// </summary>
public IDictionary<string, string> Mapping { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiDiscriminator() { }

/// <summary>
/// Initializes a copy of an <see cref="OpenApiDiscriminator"/> instance
/// </summary>
public OpenApiDiscriminator(OpenApiDiscriminator discriminator)
{
PropertyName = discriminator.PropertyName;
Mapping = new Dictionary<string, string>(discriminator.Mapping);
}

/// <summary>
/// Serialize <see cref="OpenApiDiscriminator"/> to Open Api v3.0
/// </summary>
Expand Down
23 changes: 21 additions & 2 deletions 23 src/Microsoft.OpenApi/Models/OpenApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Services;
Expand Down Expand Up @@ -64,6 +62,27 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiDocument() {}

baywet marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Initializes a copy of an an <see cref="OpenApiDocument"/> object
/// </summary>
public OpenApiDocument(OpenApiDocument document)
{
Workspace = new(document.Workspace);
Info = new(document.Info);
Servers = new List<OpenApiServer>(document.Servers);
Paths = new(document.Paths);
Components = new(document.Components);
SecurityRequirements = new List<OpenApiSecurityRequirement>(document.SecurityRequirements);
Tags = new List<OpenApiTag>(document.Tags);
ExternalDocs = new(document.ExternalDocs);
Extensions = new Dictionary<string, IOpenApiExtension>(document.Extensions);
}

/// <summary>
/// Serialize <see cref="OpenApiDocument"/> to the latest patch of OpenAPI object V3.0.
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions 18 src/Microsoft.OpenApi/Models/OpenApiEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiEncoding() {}

/// <summary>
/// Initializes a copy of an <see cref="OpenApiEncoding"/> object
/// </summary>
public OpenApiEncoding(OpenApiEncoding encoding)
{
ContentType = encoding.ContentType;
Headers = new Dictionary<string, OpenApiHeader>(encoding.Headers);
Style = encoding.Style;
Explode = encoding.Explode;
AllowReserved = encoding.AllowReserved;
Extensions = new Dictionary<string, IOpenApiExtension>(encoding.Extensions);
}

/// <summary>
/// Serialize <see cref="OpenApiExternalDocs"/> to Open Api v3.0.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions 9 src/Microsoft.OpenApi/Models/OpenApiError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public OpenApiError(string pointer, string message)
Message = message;
}

/// <summary>
/// Initializes a copy of an <see cref="OpenApiError"/> object
/// </summary>
public OpenApiError(OpenApiError error)
baywet marked this conversation as resolved.
Show resolved Hide resolved
{
Pointer = error.Pointer;
Message = error.Message;
}

/// <summary>
/// Message explaining the error.
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions 19 src/Microsoft.OpenApi/Models/OpenApiExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ public class OpenApiExample : IOpenApiSerializable, IOpenApiReferenceable, IOpen
/// </summary>
public bool UnresolvedReference { get; set; } = false;

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiExample() {}

/// <summary>
/// Initializes a copy of <see cref="OpenApiExample"/> object
/// </summary>
public OpenApiExample(OpenApiExample example)
{
Summary = example.Summary;
Description = example.Description;
Value = OpenApiAnyCloneHelper.CloneFromCopyConstructor(example.Value);
ExternalValue = example.ExternalValue;
Extensions = new Dictionary<string, IOpenApiExtension>(example.Extensions);
Reference = new(example.Reference);
UnresolvedReference = example.UnresolvedReference;
}

/// <summary>
/// Serialize <see cref="OpenApiExample"/> to Open Api v3.0
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions 15 src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ public class OpenApiExternalDocs : IOpenApiSerializable, IOpenApiExtensible
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiExternalDocs() {}

/// <summary>
/// Initializes a copy of an <see cref="OpenApiExternalDocs"/> object
/// </summary>
public OpenApiExternalDocs(OpenApiExternalDocs externalDocs)
{
Description = externalDocs.Description;
Url = new Uri(externalDocs.Url.OriginalString);
Extensions = new Dictionary<string, IOpenApiExtension>(externalDocs.Extensions);
}

/// <summary>
/// Serialize <see cref="OpenApiExternalDocs"/> to Open Api v3.0.
/// </summary>
Expand Down
26 changes: 26 additions & 0 deletions 26 src/Microsoft.OpenApi/Models/OpenApiHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,32 @@ public class OpenApiHeader : IOpenApiSerializable, IOpenApiReferenceable, IOpenA
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// Parameter-less constructor
/// </summary>
public OpenApiHeader() {}

/// <summary>
/// Initializes a copy of an <see cref="OpenApiHeader"/> object
/// </summary>
public OpenApiHeader(OpenApiHeader header)
{
UnresolvedReference = header.UnresolvedReference;
Reference = new(header.Reference);
Description = header.Description;
Required = header.Required;
Deprecated = header.Deprecated;
AllowEmptyValue = header.AllowEmptyValue;
Style = header.Style;
Explode = header.Explode;
AllowReserved = header.AllowReserved;
Schema = new(header.Schema);
Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(header.Example);
Examples = new Dictionary<string, OpenApiExample>(header.Examples);
Content = new Dictionary<string, OpenApiMediaType>(header.Content);
Extensions = new Dictionary<string, IOpenApiExtension>(header.Extensions);
}

/// <summary>
/// Serialize <see cref="OpenApiHeader"/> to Open Api v3.0
/// </summary>
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.