Skip to content
Draft
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"cSpell.words": [
"csdl",
"Hidi"
"Hidi",
"Xunit"
]
}
46 changes: 46 additions & 0 deletions src/Microsoft.OpenApi/Attributes/ExperimentalAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

#if !NET8_0_OR_GREATER
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Indicates that an API is experimental and may change in the future.
/// </summary>
[AttributeUsage(
AttributeTargets.Assembly |
AttributeTargets.Module |
AttributeTargets.Class |
AttributeTargets.Struct |
AttributeTargets.Enum |
AttributeTargets.Constructor |
AttributeTargets.Method |
AttributeTargets.Property |
AttributeTargets.Field |
AttributeTargets.Event |
AttributeTargets.Interface |
AttributeTargets.Delegate,
Inherited = false)]
internal sealed class ExperimentalAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="ExperimentalAttribute"/> class.
/// </summary>
/// <param name="diagnosticId">The diagnostic ID reported when the API is used.</param>
public ExperimentalAttribute(string diagnosticId)
{
DiagnosticId = diagnosticId;
}

/// <summary>
/// Gets the diagnostic ID reported when the API is used.
/// </summary>
public string DiagnosticId { get; }

/// <summary>
/// Gets or sets the URL format used by the diagnostic.
/// </summary>
public string? UrlFormat { get; set; }
}
}
#endif
17 changes: 17 additions & 0 deletions src/Microsoft.OpenApi/Interfaces/IDeepCopyable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

namespace Microsoft.OpenApi;
/// <summary>
/// Interface for deep copyable objects.
/// </summary>
/// <typeparam name="T">The type of the resulting object.</typeparam>
[System.Diagnostics.CodeAnalysis.Experimental("OPENAPI001")]
public interface IDeepCopyable<out T>
{
/// <summary>
/// Create a deep copy of the current instance.
/// </summary>
[System.Diagnostics.CodeAnalysis.Experimental("OPENAPI001")]
T CreateDeepCopy();
}
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net8.0'))">true</IsAotCompatible>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<NoWarn>NU5048</NoWarn>
<NoWarn>$(NoWarn);NU5048;OPENAPI001</NoWarn>
<Nullable>enable</Nullable>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.OpenApi/Models/BaseOpenApiReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
/// <summary>
/// The OpenApiDocument that is hosting the OpenApiReference instance. This is used to enable dereferencing the reference.
/// </summary>
public OpenApiDocument? HostDocument { get => hostDocument; init => hostDocument = value; }

Check warning on line 58 in src/Microsoft.OpenApi/Models/BaseOpenApiReference.cs

View workflow job for this annotation

GitHub Actions / Build

Make this an auto-implemented property and remove its backing field.

private string? _referenceV3;
/// <summary>
Expand Down Expand Up @@ -295,6 +295,12 @@
Utils.CheckArgumentNull(currentDocument);
hostDocument ??= currentDocument;
}

internal void SetHostDocument(OpenApiDocument currentDocument)
{
Utils.CheckArgumentNull(currentDocument);
hostDocument = currentDocument;
}
/// <summary>
/// Gets the property value from a JsonObject node.
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiCallback.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand All @@ -9,7 +9,7 @@ namespace Microsoft.OpenApi
/// <summary>
/// Callback Object: A map of possible out-of band callbacks related to the parent operation.
/// </summary>
public class OpenApiCallback : IOpenApiExtensible, IOpenApiCallback
public class OpenApiCallback : IOpenApiExtensible, IOpenApiCallback, IDeepCopyable<IOpenApiCallback>
{
/// <inheritdoc/>
public Dictionary<RuntimeExpression, IOpenApiPathItem>? PathItems { get; set; }
Expand Down Expand Up @@ -113,5 +113,11 @@ public IOpenApiCallback CreateShallowCopy()
{
return new OpenApiCallback(this);
}
/// <inheritdoc/>
[System.Diagnostics.CodeAnalysis.Experimental("OPENAPI001")]
public IOpenApiCallback CreateDeepCopy()
{
return new OpenApiDeepCopyContext().Copy(this);
}
}
}
9 changes: 8 additions & 1 deletion src/Microsoft.OpenApi/Models/OpenApiComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.OpenApi
/// <summary>
/// Components Object.
/// </summary>
public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible
public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible, IDeepCopyable<OpenApiComponents>
{
/// <summary>
/// An object to hold reusable <see cref="IOpenApiSchema"/> Objects.
Expand Down Expand Up @@ -96,6 +96,13 @@ public OpenApiComponents(OpenApiComponents? components)
Extensions = components?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(components.Extensions) : null;
}

/// <inheritdoc/>
[System.Diagnostics.CodeAnalysis.Experimental("OPENAPI001")]
public OpenApiComponents CreateDeepCopy()
{
return new OpenApiDeepCopyContext().Copy(this);
}

/// <summary>
/// Serialize <see cref="OpenApiComponents"/> to Open API v3.2.
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiContact.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand All @@ -9,7 +9,7 @@ namespace Microsoft.OpenApi
/// <summary>
/// Contact Object.
/// </summary>
public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible
public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible, IDeepCopyable<OpenApiContact>
{
/// <summary>
/// The identifying name of the contact person/organization.
Expand Down Expand Up @@ -47,6 +47,12 @@ public OpenApiContact(OpenApiContact contact)
Email = contact?.Email ?? Email;
Extensions = contact?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(contact.Extensions) : null;
}
/// <inheritdoc/>
[System.Diagnostics.CodeAnalysis.Experimental("OPENAPI001")]
public OpenApiContact CreateDeepCopy()
{
return new OpenApiDeepCopyContext().Copy(this);
}
/// <summary>
/// Serialize <see cref="OpenApiContact"/> to Open Api v3.2
/// </summary>
Expand Down
Loading
Loading