Skip to content

Commit 33fc7cb

Browse files
committed
fix: renames annotations schema property to metadata to match #2241
1 parent a2291cd commit 33fc7cb

File tree

7 files changed

+25
-36
lines changed

7 files changed

+25
-36
lines changed

src/Microsoft.OpenApi/Interfaces/IMetadataContainer.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33

44
using System.Collections.Generic;
55

6-
namespace Microsoft.OpenApi.Interfaces
6+
namespace Microsoft.OpenApi.Interfaces;
7+
/// <summary>
8+
/// Represents an Open API element that can be annotated with
9+
/// non-serializable properties in a property bag.
10+
/// </summary>
11+
public interface IMetadataContainer
712
{
813
/// <summary>
9-
/// Represents an Open API element that can be annotated with
10-
/// non-serializable properties in a property bag.
14+
/// A collection of properties associated with the current OpenAPI element to be used by the application.
15+
/// Metadata are NOT (de)serialized with the schema and can be used for custom properties.
1116
/// </summary>
12-
public interface IMetadataContainer
13-
{
14-
/// <summary>
15-
/// A collection of properties associated with the current OpenAPI element.
16-
/// </summary>
17-
Dictionary<string, object>? Metadata { get; set; }
18-
}
17+
Dictionary<string, object>? Metadata { get; set; }
1918
}

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte
1717
/// </summary>
1818
public string? Title { get; }
1919

20+
2021
/// <summary>
2122
/// $schema, a JSON Schema dialect identifier. Value must be a URI
2223
/// </summary>
@@ -280,12 +281,6 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte
280281
/// </summary>
281282
public Dictionary<string, JsonNode>? UnrecognizedKeywords { get; }
282283

283-
/// <summary>
284-
/// Any annotation to attach to the schema to be used by the application.
285-
/// Annotations are NOT (de)serialized with the schema and can be used for custom properties.
286-
/// </summary>
287-
public Dictionary<string, object>? Annotations { get; }
288-
289284
/// <summary>
290285
/// Follow JSON Schema definition:https://json-schema.org/draft/2020-12/json-schema-validation#section-6.5.4
291286
/// </summary>

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.OpenApi.Models
1818
/// <summary>
1919
/// The Schema Object allows the definition of input and output data types.
2020
/// </summary>
21-
public class OpenApiSchema : IOpenApiExtensible, IOpenApiSchema
21+
public class OpenApiSchema : IOpenApiExtensible, IOpenApiSchema, IMetadataContainer
2222
{
2323
/// <inheritdoc />
2424
public string? Title { get; set; }
@@ -248,7 +248,7 @@ public string? Minimum
248248
public Dictionary<string, JsonNode>? UnrecognizedKeywords { get; set; }
249249

250250
/// <inheritdoc />
251-
public Dictionary<string, object>? Annotations { get; set; }
251+
public Dictionary<string, object>? Metadata { get; set; }
252252

253253
/// <inheritdoc />
254254
public Dictionary<string, HashSet<string>>? DependentRequired { get; set; }
@@ -317,7 +317,7 @@ internal OpenApiSchema(IOpenApiSchema schema)
317317
Deprecated = schema.Deprecated;
318318
Xml = schema.Xml != null ? new(schema.Xml) : null;
319319
Extensions = schema.Extensions != null ? new Dictionary<string, IOpenApiExtension>(schema.Extensions) : null;
320-
Annotations = schema.Annotations != null ? new Dictionary<string, object>(schema.Annotations) : null;
320+
Metadata = schema is IMetadataContainer { Metadata: not null } mContainer ? new Dictionary<string, object>(mContainer.Metadata) : null;
321321
UnrecognizedKeywords = schema.UnrecognizedKeywords != null ? new Dictionary<string, JsonNode>(schema.UnrecognizedKeywords) : null;
322322
DependentRequired = schema.DependentRequired != null ? new Dictionary<string, HashSet<string>>(schema.DependentRequired) : null;
323323
}

src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ public string? Description
139139
/// <inheritdoc/>
140140
public Dictionary<string, JsonNode>? UnrecognizedKeywords { get => Target?.UnrecognizedKeywords; }
141141

142-
/// <inheritdoc/>
143-
public Dictionary<string, object>? Annotations { get => Target?.Annotations; }
144-
145142
/// <inheritdoc/>
146143
public Dictionary<string, HashSet<string>>? DependentRequired { get => Target?.DependentRequired; }
147144

test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class OpenApiDocumentTests
3636
["property1"] = new OpenApiSchema()
3737
{
3838
Type = JsonSchemaType.String,
39-
Annotations = new Dictionary<string, object> { { "key1", "value" } }
39+
Metadata = new Dictionary<string, object> { { "key1", "value" } }
4040
}
4141
}
4242
},
@@ -55,10 +55,10 @@ public class OpenApiDocumentTests
5555
["property1"] = new OpenApiSchema()
5656
{
5757
Type = JsonSchemaType.String,
58-
Annotations = new Dictionary<string, object> { { "key1", "value" } }
58+
Metadata = new Dictionary<string, object> { { "key1", "value" } }
5959
}
6060
},
61-
Annotations = new Dictionary<string, object> { { "key1", "value" } },
61+
Metadata = new Dictionary<string, object> { { "key1", "value" } },
6262
},
6363
["schema2"] = new OpenApiSchema()
6464
{

test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class OpenApiSchemaTests
3838
{
3939
Url = new("http://example.com/externalDocs")
4040
},
41-
Annotations = new Dictionary<string, object> { { "key1", "value1" }, { "key2", 2 } }
41+
Metadata = new Dictionary<string, object> { { "key1", "value1" }, { "key2", 2 } }
4242
};
4343

4444
public static readonly OpenApiSchema AdvancedSchemaObject = new()
@@ -473,24 +473,24 @@ public void OpenApiSchemaCopyConstructorSucceeds()
473473
}
474474

475475
[Fact]
476-
public void OpenApiSchemaCopyConstructorWithAnnotationsSucceeds()
476+
public void OpenApiSchemaCopyConstructorWithMetadataSucceeds()
477477
{
478478
var baseSchema = new OpenApiSchema
479479
{
480-
Annotations = new Dictionary<string, object>
480+
Metadata = new Dictionary<string, object>
481481
{
482482
["key1"] = "value1",
483483
["key2"] = 2
484484
}
485485
};
486486

487-
var actualSchema = baseSchema.CreateShallowCopy();
487+
var actualSchema = Assert.IsType<OpenApiSchema>(baseSchema.CreateShallowCopy());
488488

489-
Assert.Equal(baseSchema.Annotations["key1"], actualSchema.Annotations["key1"]);
489+
Assert.Equal(baseSchema.Metadata["key1"], actualSchema.Metadata["key1"]);
490490

491-
baseSchema.Annotations["key1"] = "value2";
491+
baseSchema.Metadata["key1"] = "value2";
492492

493-
Assert.NotEqual(baseSchema.Annotations["key1"], actualSchema.Annotations["key1"]);
493+
Assert.NotEqual(baseSchema.Metadata["key1"], actualSchema.Metadata["key1"]);
494494
}
495495

496496
public static TheoryData<JsonNode> SchemaExamples()

test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ namespace Microsoft.OpenApi.Models.Interfaces
415415
Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? AdditionalProperties { get; }
416416
bool AdditionalPropertiesAllowed { get; }
417417
System.Collections.Generic.List<Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema>? AllOf { get; }
418-
System.Collections.Generic.Dictionary<string, object>? Annotations { get; }
419418
System.Collections.Generic.List<Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema>? AnyOf { get; }
420419
string? Comment { get; }
421420
string? Const { get; }
@@ -1010,13 +1009,12 @@ namespace Microsoft.OpenApi.Models
10101009
public OpenApiResponses() { }
10111010
public OpenApiResponses(Microsoft.OpenApi.Models.OpenApiResponses openApiResponses) { }
10121011
}
1013-
public class OpenApiSchema : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable<Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema>, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema
1012+
public class OpenApiSchema : Microsoft.OpenApi.Interfaces.IMetadataContainer, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable<Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema>, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema
10141013
{
10151014
public OpenApiSchema() { }
10161015
public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? AdditionalProperties { get; set; }
10171016
public bool AdditionalPropertiesAllowed { get; set; }
10181017
public System.Collections.Generic.List<Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema>? AllOf { get; set; }
1019-
public System.Collections.Generic.Dictionary<string, object>? Annotations { get; set; }
10201018
public System.Collections.Generic.List<Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema>? AnyOf { get; set; }
10211019
public string? Comment { get; set; }
10221020
public string? Const { get; set; }
@@ -1042,6 +1040,7 @@ namespace Microsoft.OpenApi.Models
10421040
public int? MaxLength { get; set; }
10431041
public int? MaxProperties { get; set; }
10441042
public string? Maximum { get; set; }
1043+
public System.Collections.Generic.Dictionary<string, object>? Metadata { get; set; }
10451044
public int? MinItems { get; set; }
10461045
public int? MinLength { get; set; }
10471046
public int? MinProperties { get; set; }
@@ -1348,7 +1347,6 @@ namespace Microsoft.OpenApi.Models.References
13481347
public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? AdditionalProperties { get; }
13491348
public bool AdditionalPropertiesAllowed { get; }
13501349
public System.Collections.Generic.List<Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema>? AllOf { get; }
1351-
public System.Collections.Generic.Dictionary<string, object>? Annotations { get; }
13521350
public System.Collections.Generic.List<Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema>? AnyOf { get; }
13531351
public string? Comment { get; }
13541352
public string? Const { get; }

0 commit comments

Comments
 (0)