Skip to content

Commit 07893ca

Browse files
committed
- removes duplicated openapi extensions
1 parent 0971117 commit 07893ca

19 files changed

+3166
-3645
lines changed

src/Microsoft.OpenApi.OData.Reader/Edm/ODataSegment.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Microsoft.OData.Edm;
1010
using Microsoft.OpenApi.OData.Common;
1111
using Microsoft.OData.Edm.Vocabularies;
12-
using Microsoft.OpenApi.OData.OpenApiExtensions;
1312

1413
namespace Microsoft.OpenApi.OData.Edm
1514
{
@@ -109,7 +108,7 @@ public string GetPathItemName(OpenApiConvertSettings settings)
109108
return GetPathItemName(settings, new HashSet<string>());
110109
}
111110
/// <summary>
112-
/// Profides a suffix for the operation id based on the operation path.
111+
/// Provides a suffix for the operation id based on the operation path.
113112
/// </summary>
114113
/// <param name="path">Path to use to deduplicate.</param>
115114
/// <param name="settings">The settings.</param>
@@ -131,7 +130,8 @@ public string GetPathHash(OpenApiConvertSettings settings, ODataPath path = defa
131130
/// <summary>
132131
/// Provides any deprecation information for the segment.
133132
/// </summary>
134-
public OpenApiDeprecationExtension Deprecation { get; set; }
133+
[Obsolete("This property never returned any value or was used by the library.")]
134+
public Microsoft.OpenApi.OData.OpenApiExtensions.OpenApiDeprecationExtension Deprecation { get; set; }
135135
/// <summary>
136136
/// Returns the list of <see cref="IEdmVocabularyAnnotatable"/> this segment refers to.
137137
/// </summary>

src/Microsoft.OpenApi.OData.Reader/Edm/RecordExpressionExtensions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal static class RecordExpressionExtensions
2929
Utils.CheckArgumentNull(record, nameof(record));
3030
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
3131

32-
return (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
32+
return (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
3333
property.Value is IEdmIntegerConstantExpression value) ?
3434
value.Value :
3535
null;
@@ -46,7 +46,7 @@ public static string GetString(this IEdmRecordExpression record, string property
4646
Utils.CheckArgumentNull(record, nameof(record));
4747
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
4848

49-
return (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
49+
return (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
5050
property.Value is IEdmStringConstantExpression value) ?
5151
value.Value :
5252
null;
@@ -63,7 +63,7 @@ public static string GetString(this IEdmRecordExpression record, string property
6363
Utils.CheckArgumentNull(record, nameof(record));
6464
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
6565

66-
return (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
66+
return (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
6767
property.Value is IEdmBooleanConstantExpression value) ?
6868
value.Value :
6969
null;
@@ -80,7 +80,7 @@ public static string GetString(this IEdmRecordExpression record, string property
8080
Utils.CheckArgumentNull(record, nameof(record));
8181
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
8282

83-
return (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
83+
return (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
8484
property.Value is IEdmDateConstantExpression value) ?
8585
value.Value :
8686
null;
@@ -99,7 +99,7 @@ public static string GetString(this IEdmRecordExpression record, string property
9999
Utils.CheckArgumentNull(record, nameof(record));
100100
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
101101

102-
return (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
102+
return (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
103103
property.Value is IEdmEnumMemberExpression value &&
104104
value.EnumMembers != null &&
105105
value.EnumMembers.Any() &&
@@ -121,7 +121,7 @@ public static T GetRecord<T>(this IEdmRecordExpression record, string propertyNa
121121
Utils.CheckArgumentNull(record, nameof(record));
122122
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
123123

124-
if (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
124+
if (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
125125
property.Value is IEdmRecordExpression recordValue)
126126
{
127127
T a = new();
@@ -143,7 +143,7 @@ public static string GetPropertyPath(this IEdmRecordExpression record, string pr
143143
Utils.CheckArgumentNull(record, nameof(record));
144144
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
145145

146-
return (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
146+
return (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
147147
property.Value is IEdmPathExpression value) ?
148148
value.Path :
149149
null;
@@ -160,7 +160,7 @@ public static IList<string> GetCollectionPropertyPath(this IEdmRecordExpression
160160
Utils.CheckArgumentNull(record, nameof(record));
161161
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
162162

163-
if (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
163+
if (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
164164
property.Value is IEdmCollectionExpression value && value.Elements != null)
165165
{
166166
IList<string> properties =
@@ -189,7 +189,7 @@ public static IList<string> GetCollection(this IEdmRecordExpression record, stri
189189
Utils.CheckArgumentNull(record, nameof(record));
190190
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
191191

192-
if (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
192+
if (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
193193
property.Value is IEdmCollectionExpression collection && collection.Elements != null)
194194
{
195195
IList<string> items = collection.Elements
@@ -215,7 +215,7 @@ public static IList<T> GetCollection<T>(this IEdmRecordExpression record, string
215215
Utils.CheckArgumentNull(record, nameof(record));
216216
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
217217

218-
if (record.Properties?.FirstOrDefault(e => e.Name == propertyName) is IEdmPropertyConstructor property &&
218+
if (record.Properties?.FirstOrDefault(e => propertyName.Equals(e.Name, StringComparison.Ordinal)) is IEdmPropertyConstructor property &&
219219
property.Value is IEdmCollectionExpression collection && collection.Elements != null)
220220
{
221221
IList<T> items = new List<T>();

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiErrorSchemaGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using Microsoft.OpenApi.Models;
1111
using Microsoft.OpenApi.OData.Common;
1212
using Microsoft.OpenApi.OData.Edm;
13-
using Microsoft.OpenApi.OData.OpenApiExtensions;
13+
using Microsoft.OpenApi.MicrosoftExtensions;
1414

1515
namespace Microsoft.OpenApi.OData.Generator
1616
{

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using Microsoft.OpenApi.Exceptions;
1616
using System.Linq;
1717
using Microsoft.OpenApi.Interfaces;
18-
using Microsoft.OpenApi.OData.OpenApiExtensions;
18+
using Microsoft.OpenApi.MicrosoftExtensions;
1919
using Microsoft.OpenApi.OData.Vocabulary.Core;
2020

2121
namespace Microsoft.OpenApi.OData.Generator
@@ -324,9 +324,8 @@ public static OpenApiSchema CreateEnumTypeSchema(this ODataContext context, IEdm
324324
var enumFlagsExtension = new OpenApiEnumFlagsExtension
325325
{
326326
IsFlags = true,
327-
Style = "simple"
328327
};
329-
schema.Extensions.Add(enumFlagsExtension.Name, enumFlagsExtension);
328+
schema.Extensions.Add(OpenApiEnumFlagsExtension.Name, enumFlagsExtension);
330329
}
331330

332331
var extension = (context.Settings.OpenApiSpecVersion == OpenApiSpecVersion.OpenApi2_0 ||
@@ -345,7 +344,7 @@ public static OpenApiSchema CreateEnumTypeSchema(this ODataContext context, IEdm
345344
}
346345

347346
if(extension?.ValuesDescriptions.Any() ?? false)
348-
schema.Extensions.Add(extension.Name, extension);
347+
schema.Extensions.Add(OpenApiEnumValuesDescriptionExtension.Name, extension);
349348
schema.Title = enumType.Name;
350349
return schema;
351350
}

src/Microsoft.OpenApi.OData.Reader/OpenApiExtensions/OpenApiDeprecationExtension.cs

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,23 @@
44
// ------------------------------------------------------------
55

66
using System;
7-
using Microsoft.OpenApi.Interfaces;
8-
using Microsoft.OpenApi.OData.Common;
9-
using Microsoft.OpenApi.Writers;
107

118
namespace Microsoft.OpenApi.OData.OpenApiExtensions;
129

13-
/// <summary>
14-
/// Extension element for OpenAPI to add deprecation information. x-ms-deprecation
15-
/// </summary>
16-
public class OpenApiDeprecationExtension : IOpenApiExtension
10+
/// <inheritdoc />
11+
[Obsolete("This class is deprecated. Use Microsoft.OpenApi.MicrosoftExtensions.OpenApiDeprecationExtension instead.")]
12+
public class OpenApiDeprecationExtension : Microsoft.OpenApi.MicrosoftExtensions.OpenApiDeprecationExtension
1713
{
1814
/// <summary>
19-
/// Name of the extension as used in the description.
15+
/// Name of the extension use in OpenAPI document.
2016
/// </summary>
21-
public string Name => "x-ms-deprecation";
17+
public new string Name => Microsoft.OpenApi.MicrosoftExtensions.OpenApiDeprecationExtension.Name;
2218
/// <summary>
2319
/// The date at which the element has been/will be removed entirely from the service.
2420
/// </summary>
25-
public DateTime? RemovalDate { get; set; }
21+
public new DateTime? RemovalDate { get => base.RemovalDate.HasValue ? base.RemovalDate.Value.DateTime : default; set => base.RemovalDate = value.HasValue ? new DateTimeOffset(value.Value) : default; }
2622
/// <summary>
2723
/// The date at which the element has been/will be deprecated.
2824
/// </summary>
29-
public DateTime? Date { get; set; }
30-
/// <summary>
31-
/// The version this revision was introduced.
32-
/// </summary>
33-
public string Version { get; set; }
34-
/// <summary>
35-
/// The description of the revision.
36-
/// </summary>
37-
public string Description { get; set; }
38-
/// <inheritdoc />
39-
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
40-
{
41-
if(writer == null)
42-
throw new ArgumentNullException(nameof(writer));
43-
44-
if(RemovalDate.HasValue || Date.HasValue || !string.IsNullOrEmpty(Version) || !string.IsNullOrEmpty(Description))
45-
{
46-
writer.WriteStartObject();
47-
48-
if(RemovalDate.HasValue)
49-
writer.WriteProperty(nameof(RemovalDate).ToFirstCharacterLowerCase(), RemovalDate.Value);
50-
if(Date.HasValue)
51-
writer.WriteProperty(nameof(Date).ToFirstCharacterLowerCase(), Date.Value);
52-
if(!string.IsNullOrEmpty(Version))
53-
writer.WriteProperty(nameof(Version).ToFirstCharacterLowerCase(), Version);
54-
if(!string.IsNullOrEmpty(Description))
55-
writer.WriteProperty(nameof(Description).ToFirstCharacterLowerCase(), Description);
56-
57-
writer.WriteEndObject();
58-
}
59-
}
25+
public new DateTime? Date { get => base.Date.HasValue ? base.Date.Value.DateTime : default; set => base.Date = value.HasValue ? new DateTimeOffset(value.Value) : default; }
6026
}

src/Microsoft.OpenApi.OData.Reader/OpenApiExtensions/OpenApiEnumFlagsExtension.cs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,15 @@
44
// ------------------------------------------------------------
55

66
using System;
7-
using Microsoft.OpenApi.Interfaces;
8-
using Microsoft.OpenApi.OData.Common;
9-
using Microsoft.OpenApi.Writers;
107

118
namespace Microsoft.OpenApi.OData.OpenApiExtensions;
129

13-
/// <summary>
14-
/// Extension element for OpenAPI to add deprecation information. x-ms-enum-flags
15-
/// </summary>
16-
public class OpenApiEnumFlagsExtension : IOpenApiExtension
10+
/// <inheritdoc />
11+
[Obsolete("This class is deprecated. Use Microsoft.OpenApi.MicrosoftExtensions.OpenApiEnumFlagsExtension instead.")]
12+
public class OpenApiEnumFlagsExtension : Microsoft.OpenApi.MicrosoftExtensions.OpenApiEnumFlagsExtension
1713
{
1814
/// <summary>
1915
/// Name of the extension as used in the description.
2016
/// </summary>
21-
public string Name => "x-ms-enum-flags";
22-
/// <summary>
23-
/// Whether the enum is a flagged enum.
24-
/// </summary>
25-
public bool IsFlags { get; set; }
26-
/// <summary>
27-
/// The serialization style of the flagged enum.
28-
/// </summary>
29-
public string Style { get; set; }
30-
/// <inheritdoc />
31-
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
32-
{
33-
if(writer == null)
34-
throw new ArgumentNullException(nameof(writer));
35-
36-
writer.WriteStartObject();
37-
writer.WriteProperty(nameof(IsFlags).ToFirstCharacterLowerCase(), IsFlags);
38-
writer.WriteProperty(nameof(Style).ToFirstCharacterLowerCase(),Style);
39-
writer.WriteEndObject();
40-
}
17+
public new string Name => Microsoft.OpenApi.MicrosoftExtensions.OpenApiEnumFlagsExtension.Name;
4118
}

src/Microsoft.OpenApi.OData.Reader/OpenApiExtensions/OpenApiEnumValuesDescriptionExtension.cs

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/Microsoft.OpenApi.OData.Reader/OpenApiExtensions/OpenApiPrimaryErrorMessageExtension.cs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,11 @@
44
// ------------------------------------------------------------
55

66
using System;
7-
using Microsoft.OpenApi.Any;
8-
using Microsoft.OpenApi.Interfaces;
9-
using Microsoft.OpenApi.Writers;
107

118
namespace Microsoft.OpenApi.OData.OpenApiExtensions;
129

13-
/// <summary>
14-
/// Extension element for OpenAPI to add tag the primary error message to use on error types. x-ms-primary-error-message
15-
/// </summary>
16-
public class OpenApiPrimaryErrorMessageExtension : IOpenApiExtension
10+
/// <inheritdoc />
11+
[Obsolete("This class is deprecated. Use Microsoft.OpenApi.MicrosoftExtensions.OpenApiPrimaryErrorMessageExtension instead.")]
12+
public class OpenApiPrimaryErrorMessageExtension : Microsoft.OpenApi.MicrosoftExtensions.OpenApiPrimaryErrorMessageExtension
1713
{
18-
/// <summary>
19-
/// Name of the extension as used in the description.
20-
/// </summary>
21-
public static string Name => "x-ms-primary-error-message";
22-
/// <inheritdoc />
23-
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
24-
{
25-
if(writer == null)
26-
throw new ArgumentNullException(nameof(writer));
27-
writer.WriteValue(IsPrimaryErrorMessage);
28-
}
29-
/// <summary>
30-
/// Whether this property is the primary error message to use on error types.
31-
/// </summary>
32-
public bool IsPrimaryErrorMessage { get; set; }
33-
/// <summary>
34-
/// Parses the <see cref="IOpenApiAny"/> to <see cref="OpenApiPrimaryErrorMessageExtension"/>.
35-
/// </summary>
36-
/// <param name="source">The source object.</param>
37-
/// <returns>The <see cref="OpenApiPrimaryErrorMessageExtension"/>.</returns>
38-
public static OpenApiPrimaryErrorMessageExtension Parse(IOpenApiAny source)
39-
{
40-
if (source is not OpenApiBoolean rawObject) throw new ArgumentOutOfRangeException(nameof(source));
41-
return new OpenApiPrimaryErrorMessageExtension() {
42-
IsPrimaryErrorMessage = rawObject.Value
43-
};
44-
}
4514
}

0 commit comments

Comments
 (0)