Skip to content

chore: rename annotations to metadata #2241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025
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 @@
/// <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 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 @@
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 Expand Up @@ -239,7 +239,7 @@
/// <summary>
/// Serialize <see cref="OpenApiDocument"/> to OpenAPI object V2.0.
/// </summary>
public void SerializeAsV2(IOpenApiWriter writer)

Check warning on line 242 in src/Microsoft.OpenApi/Models/OpenApiDocument.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 242 in src/Microsoft.OpenApi/Models/OpenApiDocument.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 242 in src/Microsoft.OpenApi/Models/OpenApiDocument.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
Utils.CheckArgumentNull(writer);

Expand Down Expand Up @@ -533,7 +533,7 @@
}
else
{
string relativePath = OpenApiConstants.ComponentsSegment + reference.Type.GetDisplayName() + "/" + reference.Id;

Check warning on line 536 in src/Microsoft.OpenApi/Models/OpenApiDocument.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this hardcoded path-delimiter. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 536 in src/Microsoft.OpenApi/Models/OpenApiDocument.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this hardcoded path-delimiter. (https://rules.sonarsource.com/csharp/RSPEC-1075)

Check warning on line 536 in src/Microsoft.OpenApi/Models/OpenApiDocument.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this hardcoded path-delimiter. (https://rules.sonarsource.com/csharp/RSPEC-1075)

uriLocation = useExternal
? Workspace?.GetDocumentId(reference.ExternalResource)?.OriginalString + relativePath
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 @@
/// <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 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 @@
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 Expand Up @@ -229,7 +229,7 @@
/// <summary>
/// Serialize <see cref="OpenApiOperation"/> to Open Api v2.0.
/// </summary>
public void SerializeAsV2(IOpenApiWriter writer)

Check warning on line 232 in src/Microsoft.OpenApi/Models/OpenApiOperation.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 232 in src/Microsoft.OpenApi/Models/OpenApiOperation.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 232 in src/Microsoft.OpenApi/Models/OpenApiOperation.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
Utils.CheckArgumentNull(writer);

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 @@
{
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 @@
{
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 @@
{
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 @@
}
}
},
Annotations = new Dictionary<string, object> { { "key1", "value" } },
Metadata = new Dictionary<string, object> { { "key1", "value" } },
Components = AdvancedComponentsWithReference
};

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

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

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

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

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]
public void SerializeExamplesDoesNotThrowNullReferenceException()

Check warning on line 1850 in test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs

View workflow job for this annotation

GitHub Actions / Build

Add at least one assertion to this test case. (https://rules.sonarsource.com/csharp/RSPEC-2699)
{
OpenApiDocument doc = new OpenApiDocument
{
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