Skip to content
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
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.Collections.Generic;
Expand All @@ -9,11 +9,11 @@ namespace Microsoft.OpenApi.Interfaces
/// Represents an Open API element that can be annotated with
/// non-serializable properties in a property bag.
/// </summary>
public interface IOpenApiAnnotatable
public interface IMetadataContainer
{
/// <summary>
/// A collection of properties associated with the current OpenAPI element.
/// </summary>
IDictionary<string, object> Annotations { get; set; }
IDictionary<string, object> Metadata { get; set; }
}
}
6 changes: 3 additions & 3 deletions src/Microsoft.OpenApi/Models/OpenApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Microsoft.OpenApi.Models
/// <summary>
/// Describes an OpenAPI object (OpenAPI document). See: https://spec.openapis.org
/// </summary>
public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IOpenApiAnnotatable
public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IMetadataContainer
{
/// <summary>
/// Register components in the document to the workspace
Expand Down Expand Up @@ -109,7 +109,7 @@ public ISet<OpenApiTag>? Tags
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <inheritdoc />
public IDictionary<string, object>? Annotations { get; set; }
public IDictionary<string, object>? Metadata { get; set; }

/// <summary>
/// Implements IBaseDocument
Expand Down Expand Up @@ -143,7 +143,7 @@ public OpenApiDocument(OpenApiDocument? document)
Tags = document?.Tags != null ? new HashSet<OpenApiTag>(document.Tags, OpenApiTagComparer.Instance) : null;
ExternalDocs = document?.ExternalDocs != null ? new(document?.ExternalDocs) : null;
Extensions = document?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(document.Extensions) : null;
Annotations = document?.Annotations != null ? new Dictionary<string, object>(document.Annotations) : null;
Metadata = document?.Metadata != null ? new Dictionary<string, object>(document.Metadata) : null;
BaseUri = document?.BaseUri != null ? document.BaseUri : new(OpenApiConstants.BaseRegistryUri + Guid.NewGuid());
}

Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.OpenApi/Models/OpenApiOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.OpenApi.Models
/// <summary>
/// Operation Object.
/// </summary>
public class OpenApiOperation : IOpenApiSerializable, IOpenApiExtensible, IOpenApiAnnotatable
public class OpenApiOperation : IOpenApiSerializable, IOpenApiExtensible, IMetadataContainer
{
/// <summary>
/// Default value for <see cref="Deprecated"/>.
Expand Down Expand Up @@ -127,7 +127,7 @@ public ISet<OpenApiTagReference>? Tags
public IDictionary<string, IOpenApiExtension>? Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <inheritdoc />
public IDictionary<string, object>? Annotations { get; set; }
public IDictionary<string, object>? Metadata { get; set; }

/// <summary>
/// Parameterless constructor
Expand All @@ -153,7 +153,7 @@ public OpenApiOperation(OpenApiOperation operation)
Security = operation.Security != null ? new List<OpenApiSecurityRequirement>(operation.Security) : null;
Servers = operation.Servers != null ? new List<OpenApiServer>(operation.Servers) : null;
Extensions = operation.Extensions != null ? new Dictionary<string, IOpenApiExtension>(operation.Extensions) : null;
Annotations = operation.Annotations != null ? new Dictionary<string, object>(operation.Annotations) : null;
Metadata = operation.Metadata != null ? new Dictionary<string, object>(operation.Metadata) : null;
}

/// <summary>
Expand Down
22 changes: 11 additions & 11 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class OpenApiDocumentTests
{
Version = "1.0.0"
},
Annotations = new Dictionary<string, object> { { "key1", "value" } },
Metadata = new Dictionary<string, object> { { "key1", "value" } },
Components = TopLevelReferencingComponents
};

Expand All @@ -102,7 +102,7 @@ public class OpenApiDocumentTests
{
Version = "1.0.0"
},
Annotations = new Dictionary<string, object> { { "key1", "value" } },
Metadata = new Dictionary<string, object> { { "key1", "value" } },
Components = TopLevelSelfReferencingComponentsWithOtherProperties
};

Expand All @@ -112,7 +112,7 @@ public class OpenApiDocumentTests
{
Version = "1.0.0"
},
Annotations = new Dictionary<string, object> { { "key1", "value" } },
Metadata = new Dictionary<string, object> { { "key1", "value" } },
Components = TopLevelSelfReferencingComponents
};

Expand Down Expand Up @@ -489,7 +489,7 @@ public class OpenApiDocumentTests
}
}
},
Annotations = new Dictionary<string, object> { { "key1", "value" } },
Metadata = new Dictionary<string, object> { { "key1", "value" } },
Components = AdvancedComponentsWithReference
};

Expand Down Expand Up @@ -865,7 +865,7 @@ public class OpenApiDocumentTests
}
}
},
Annotations = new Dictionary<string, object> { { "key1", "value" } },
Metadata = new Dictionary<string, object> { { "key1", "value" } },
Components = AdvancedComponents
};

Expand Down Expand Up @@ -1024,7 +1024,7 @@ public class OpenApiDocumentTests
}
}
},
Annotations = new Dictionary<string, object> { { "key1", "value" } },
Metadata = new Dictionary<string, object> { { "key1", "value" } },
Components = AdvancedComponents
};

Expand Down Expand Up @@ -1324,7 +1324,7 @@ public class OpenApiDocumentTests
}
}
},
Annotations = new Dictionary<string, object> { { "key1", "value" } },
Metadata = new Dictionary<string, object> { { "key1", "value" } },
Components = AdvancedComponents
};

Expand Down Expand Up @@ -1830,7 +1830,7 @@ public void OpenApiDocumentCopyConstructorWithAnnotationsSucceeds()
{
var baseDocument = new OpenApiDocument
{
Annotations = new Dictionary<string, object>
Metadata = new Dictionary<string, object>
{
["key1"] = "value1",
["key2"] = 2
Expand All @@ -1839,11 +1839,11 @@ public void OpenApiDocumentCopyConstructorWithAnnotationsSucceeds()

var actualDocument = new OpenApiDocument(baseDocument);

Assert.Equal(baseDocument.Annotations["key1"], actualDocument.Annotations["key1"]);
Assert.Equal(baseDocument.Metadata["key1"], actualDocument.Metadata["key1"]);

baseDocument.Annotations["key1"] = "value2";
baseDocument.Metadata["key1"] = "value2";

Assert.NotEqual(baseDocument.Annotations["key1"], actualDocument.Annotations["key1"]);
Assert.NotEqual(baseDocument.Metadata["key1"], actualDocument.Metadata["key1"]);
}

[Fact]
Expand Down
10 changes: 5 additions & 5 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class OpenApiOperationTests
Description = "serverDescription"
}
},
Annotations = new Dictionary<string, object> { { "key1", "value1" }, { "key2", 2 } },
Metadata = new Dictionary<string, object> { { "key1", "value1" }, { "key2", 2 } },
};

private static OpenApiOperation _advancedOperationWithTagsAndSecurity => new()
Expand Down Expand Up @@ -844,7 +844,7 @@ public void OpenApiOperationCopyConstructorWithAnnotationsSucceeds()
{
var baseOperation = new OpenApiOperation
{
Annotations = new Dictionary<string, object>
Metadata = new Dictionary<string, object>
{
["key1"] = "value1",
["key2"] = 2
Expand All @@ -853,11 +853,11 @@ public void OpenApiOperationCopyConstructorWithAnnotationsSucceeds()

var actualOperation = new OpenApiOperation(baseOperation);

Assert.Equal(baseOperation.Annotations["key1"], actualOperation.Annotations["key1"]);
Assert.Equal(baseOperation.Metadata["key1"], actualOperation.Metadata["key1"]);

baseOperation.Annotations["key1"] = "value2";
baseOperation.Metadata["key1"] = "value2";

Assert.NotEqual(baseOperation.Annotations["key1"], actualOperation.Annotations["key1"]);
Assert.NotEqual(baseOperation.Metadata["key1"], actualOperation.Metadata["key1"]);
}
}
}
12 changes: 6 additions & 6 deletions test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ namespace Microsoft.OpenApi.Extensions
namespace Microsoft.OpenApi.Interfaces
{
public interface IDiagnostic { }
public interface IOpenApiAnnotatable
public interface IMetadataContainer
{
System.Collections.Generic.IDictionary<string, object> Annotations { get; set; }
System.Collections.Generic.IDictionary<string, object> Metadata { get; set; }
}
public interface IOpenApiElement { }
public interface IOpenApiExtensible : Microsoft.OpenApi.Interfaces.IOpenApiElement
Expand Down Expand Up @@ -706,17 +706,17 @@ namespace Microsoft.OpenApi.Models
public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { }
public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { }
}
public class OpenApiDocument : Microsoft.OpenApi.Interfaces.IOpenApiAnnotatable, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
public class OpenApiDocument : Microsoft.OpenApi.Interfaces.IMetadataContainer, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
{
public OpenApiDocument() { }
public OpenApiDocument(Microsoft.OpenApi.Models.OpenApiDocument? document) { }
public System.Collections.Generic.IDictionary<string, object>? Annotations { get; set; }
public System.Uri BaseUri { get; }
public Microsoft.OpenApi.Models.OpenApiComponents? Components { get; set; }
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Interfaces.IOpenApiExtension>? Extensions { get; set; }
public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; }
public Microsoft.OpenApi.Models.OpenApiInfo Info { get; set; }
public System.Uri? JsonSchemaDialect { get; set; }
public System.Collections.Generic.IDictionary<string, object>? Metadata { get; set; }
public Microsoft.OpenApi.Models.OpenApiPaths Paths { get; set; }
public System.Collections.Generic.IList<Microsoft.OpenApi.Models.OpenApiSecurityRequirement>? Security { get; set; }
public System.Collections.Generic.IList<Microsoft.OpenApi.Models.OpenApiServer>? Servers { get; set; }
Expand Down Expand Up @@ -894,17 +894,17 @@ namespace Microsoft.OpenApi.Models
public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { }
public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { }
}
public class OpenApiOperation : Microsoft.OpenApi.Interfaces.IOpenApiAnnotatable, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
public class OpenApiOperation : Microsoft.OpenApi.Interfaces.IMetadataContainer, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
{
public const bool DeprecatedDefault = false;
public OpenApiOperation() { }
public OpenApiOperation(Microsoft.OpenApi.Models.OpenApiOperation operation) { }
public System.Collections.Generic.IDictionary<string, object>? Annotations { get; set; }
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback>? Callbacks { get; set; }
public bool Deprecated { get; set; }
public string? Description { get; set; }
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Interfaces.IOpenApiExtension>? Extensions { get; set; }
public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; }
public System.Collections.Generic.IDictionary<string, object>? Metadata { get; set; }
public string? OperationId { get; set; }
public System.Collections.Generic.IList<Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter>? Parameters { get; set; }
public Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody? RequestBody { get; set; }
Expand Down