Skip to content

Commit 6912454

Browse files
authored
Merge pull request #676 from microsoft/feat/upgrade-oai
feat/upgrade oai
2 parents 2f6459e + fa5c1d3 commit 6912454

File tree

134 files changed

+2221
-1871
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+2221
-1871
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
# IDE0009: Member access should be qualified.
44
dotnet_diagnostic.IDE0009.severity = none
55
dotnet_diagnostic.CA2016.severity = warning
6+
7+
[*.cs]
8+
dotnet_public_api_analyzer.require_api_files = true

src/Microsoft.OpenApi.OData.Reader/Common/CryptographyExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static string GetHashSHA256(this string input)
2222
Utils.CheckArgumentNull(input, nameof(input));
2323

2424
var inputBytes = Encoding.UTF8.GetBytes(input);
25-
var hashBytes = hasher.Value.ComputeHash(inputBytes);
25+
if (hasher.Value?.ComputeHash(inputBytes) is not {} hashBytes) return string.Empty;
2626
var hash = new StringBuilder();
2727
foreach (var b in hashBytes)
2828
{

src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs

Lines changed: 78 additions & 64 deletions
Large diffs are not rendered by default.

src/Microsoft.OpenApi.OData.Reader/Common/OpenApiOperationExtensions.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal static class OpenApiOperationExtensions
2424
/// <param name="addNoContent">Optional: Whether to add a 204 no content response.</param>
2525
/// <param name="schema">Optional: The OpenAPI schema of the response.</param>
2626
/// <param name="document">The OpenAPI document to lookup references.</param>
27-
public static void AddErrorResponses(this OpenApiOperation operation, OpenApiConvertSettings settings, OpenApiDocument document, bool addNoContent = false, IOpenApiSchema schema = null)
27+
public static void AddErrorResponses(this OpenApiOperation operation, OpenApiConvertSettings settings, OpenApiDocument document, bool addNoContent = false, IOpenApiSchema? schema = null)
2828
{
2929
Utils.CheckArgumentNull(operation, nameof(operation));
3030
Utils.CheckArgumentNull(settings, nameof(settings));
@@ -39,7 +39,7 @@ public static void AddErrorResponses(this OpenApiOperation operation, OpenApiCon
3939
{
4040
if (settings.UseSuccessStatusCodeRange)
4141
{
42-
OpenApiResponse response = null;
42+
OpenApiResponse? response = null;
4343
if (schema != null)
4444
{
4545
response = new()
@@ -57,22 +57,25 @@ public static void AddErrorResponses(this OpenApiOperation operation, OpenApiCon
5757
}
5858
};
5959
}
60-
operation.Responses.Add(Constants.StatusCodeClass2XX, response ?? Constants.StatusCodeClass2XX.GetResponse(document));
60+
if ((response ?? Constants.StatusCodeClass2XX.GetResponse(document)) is {} x2xxResponse)
61+
operation.Responses.Add(Constants.StatusCodeClass2XX, x2xxResponse);
6162
}
62-
else
63+
else if (Constants.StatusCode204.GetResponse(document) is {} x204Response)
6364
{
64-
operation.Responses.Add(Constants.StatusCode204, Constants.StatusCode204.GetResponse(document));
65+
operation.Responses.Add(Constants.StatusCode204, x204Response);
6566
}
6667
}
6768

68-
if (settings.ErrorResponsesAsDefault)
69+
if (settings.ErrorResponsesAsDefault && Constants.StatusCodeDefault.GetResponse(document) is {} defaultResponse)
6970
{
70-
operation.Responses.Add(Constants.StatusCodeDefault, Constants.StatusCodeDefault.GetResponse(document));
71+
operation.Responses.Add(Constants.StatusCodeDefault, defaultResponse);
7172
}
7273
else
7374
{
74-
operation.Responses.Add(Constants.StatusCodeClass4XX, Constants.StatusCodeClass4XX.GetResponse(document));
75-
operation.Responses.Add(Constants.StatusCodeClass5XX, Constants.StatusCodeClass5XX.GetResponse(document));
75+
if (Constants.StatusCodeClass4XX.GetResponse(document) is {} x4xxResponse)
76+
operation.Responses.Add(Constants.StatusCodeClass4XX, x4xxResponse);
77+
if (Constants.StatusCodeClass5XX.GetResponse(document) is {} x5xxResponse)
78+
operation.Responses.Add(Constants.StatusCodeClass5XX, x5xxResponse);
7679
}
7780
}
7881
}

src/Microsoft.OpenApi.OData.Reader/Common/Utils.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public static class Utils
2828
/// </summary>
2929
/// <typeparam name="T">The type of the term.</typeparam>
3030
/// <returns>The qualified name.</returns>
31-
public static string GetTermQualifiedName<T>()
31+
public static string? GetTermQualifiedName<T>()
3232
{
3333
object[] attributes = typeof(T).GetCustomAttributes(typeof(TermAttribute), false);
34-
if (attributes == null && attributes.Length == 0)
34+
if (attributes == null || attributes.Length == 0)
3535
{
3636
return null;
3737
}
@@ -45,7 +45,7 @@ public static string GetTermQualifiedName<T>()
4545
/// </summary>
4646
/// <param name="input">The input string.</param>
4747
/// <returns>The changed string.</returns>
48-
public static string UpperFirstChar(string input)
48+
public static string? UpperFirstChar(string? input)
4949
{
5050
if (input == null)
5151
{
@@ -129,7 +129,7 @@ internal static string ToFirstCharacterLowerCase(this string input)
129129
/// </summary>
130130
/// <param name="path">The <see cref="ODataPath"/>.</param>
131131
/// <param name="navigationPropertyName">Optional: The navigation property name.</param>
132-
internal static string NavigationPropertyPath(this ODataPath path, string navigationPropertyName = null)
132+
internal static string NavigationPropertyPath(this ODataPath path, string? navigationPropertyName = null)
133133
{
134134
string value = string.Join("/",
135135
path.Segments.OfType<ODataNavigationPropertySegment>().Select(e => e.Identifier));
@@ -176,7 +176,7 @@ private static Dictionary<string, string> GetCustomXMLAttributesValueMapping(IEd
176176
{
177177
Dictionary<string, string> attributesValueMap = new();
178178

179-
if ((!customXMLAttributesMapping?.Any() ?? true) ||
179+
if (customXMLAttributesMapping is not {Count:>0} ||
180180
model == null ||
181181
element == null)
182182
{
@@ -187,10 +187,10 @@ private static Dictionary<string, string> GetCustomXMLAttributesValueMapping(IEd
187187
{
188188
string attributeName = item.Key.Split(':').Last(); // example, 'ags:IsHidden' --> 'IsHidden'
189189
string extensionName = item.Value;
190-
EdmStringConstant customXMLAttribute = model.DirectValueAnnotationsManager.GetDirectValueAnnotations(element)?
190+
var customXMLAttribute = model.DirectValueAnnotationsManager.GetDirectValueAnnotations(element)?
191191
.Where(x => x.Name.Equals(attributeName, StringComparison.OrdinalIgnoreCase))?
192192
.FirstOrDefault()?.Value as EdmStringConstant;
193-
string attributeValue = customXMLAttribute?.Value;
193+
var attributeValue = customXMLAttribute?.Value;
194194

195195
if (!string.IsNullOrEmpty(attributeValue))
196196
{
@@ -212,10 +212,10 @@ private static Dictionary<string, string> GetCustomXMLAttributesValueMapping(IEd
212212
internal static bool IsBaseTypeReferencedAsTypeInModel(
213213
this IEdmModel model,
214214
IEdmStructuredType baseType,
215-
IEnumerable<IEdmStructuredType> structuredTypes = null,
216-
IEnumerable<IEdmAction> actions = null)
215+
IEnumerable<IEdmStructuredType>? structuredTypes = null,
216+
IEnumerable<IEdmAction>? actions = null)
217217
{
218-
string baseTypeName = baseType?.FullTypeName();
218+
string baseTypeName = baseType.FullTypeName();
219219
bool isBaseTypeEntity = Constants.EntityName.Equals(baseTypeName?.Split('.').Last(), StringComparison.OrdinalIgnoreCase);
220220

221221
if (!string.IsNullOrEmpty(baseTypeName) && !isBaseTypeEntity)
@@ -253,7 +253,7 @@ internal static bool IsBaseTypeReferencedAsTypeInModel(
253253
/// </summary>
254254
/// <param name="segment">The target <see cref="ODataSegment"/>.</param>
255255
/// <returns>The entity type of the target <paramref name="segment"/>.</returns>
256-
internal static IEdmEntityType EntityTypeFromPathSegment(this ODataSegment segment)
256+
internal static IEdmEntityType? EntityTypeFromPathSegment(this ODataSegment segment)
257257
{
258258
CheckArgumentNull(segment, nameof(segment));
259259

@@ -279,12 +279,12 @@ internal static IEdmEntityType EntityTypeFromPathSegment(this ODataSegment segme
279279
/// </summary>
280280
/// <param name="segment">The target <see cref="ODataOperationSegment"/>.</param>
281281
/// <returns>The entity type of the target <paramref name="segment"/>.</returns>
282-
private static IEdmEntityType EntityTypeFromOperationSegment(this ODataSegment segment)
282+
private static IEdmEntityType? EntityTypeFromOperationSegment(this ODataSegment segment)
283283
{
284284
CheckArgumentNull(segment, nameof(segment));
285285

286286
if (segment is ODataOperationSegment operationSegment &&
287-
operationSegment.Operation.Parameters.FirstOrDefault() is IEdmOperationParameter bindingParameter)
287+
operationSegment.Operation?.Parameters.FirstOrDefault() is IEdmOperationParameter bindingParameter)
288288
{
289289
IEdmTypeReference bindingType = bindingParameter.Type;
290290

@@ -339,10 +339,10 @@ internal static bool TryAddPath(this IDictionary<string, IOpenApiPathItem> pathI
339339
}
340340

341341
ODataSegment lastSecondSegment = path.Segments.ElementAt(path.Count - secondLastSegmentIndex);
342-
IEdmEntityType boundEntityType = lastSecondSegment?.EntityTypeFromPathSegment();
342+
var boundEntityType = lastSecondSegment?.EntityTypeFromPathSegment();
343343

344-
IEdmEntityType operationEntityType = lastSegment.EntityTypeFromOperationSegment();
345-
IEnumerable<IEdmStructuredType> derivedTypes = (operationEntityType != null)
344+
var operationEntityType = lastSegment.EntityTypeFromOperationSegment();
345+
var derivedTypes = (operationEntityType != null)
346346
? context.Model.FindAllDerivedTypes(operationEntityType)
347347
: null;
348348

0 commit comments

Comments
 (0)