Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1bc424c
feat: migrates to the latest preview of OAI.net
baywet Mar 14, 2025
9029a2f
Merge branch 'main' into feat/upgrade-oai
baywet Mar 19, 2025
93f46f0
feat: enables null reference types for the library
baywet Mar 19, 2025
255a84b
chore: additional NRT fixes
baywet Mar 24, 2025
0868da2
chore: additional NRT fixes batch
baywet Mar 24, 2025
c815412
chore: another batch of NRT fixes
baywet Mar 24, 2025
176ff31
chore: another batch of NRT fixes
baywet Mar 24, 2025
a755dd8
chore: additional NRT fixes batch
baywet Mar 25, 2025
6827d88
chore: another batch of NRT fixes
baywet Mar 25, 2025
4ab5808
chore: additional NRT fixes
baywet Mar 25, 2025
6187536
chore: additional NRT fixes
baywet Mar 26, 2025
44f1e2a
chore: additional NRT fixes
baywet Mar 26, 2025
0de5fb1
chore: additional NRT fixes
baywet Mar 26, 2025
5362d83
chore: additional NRT fixes
baywet Mar 26, 2025
46722a9
chore: additional NRT fixes
baywet Mar 27, 2025
05faaeb
chore: additional NRT fixes
baywet Mar 27, 2025
3ae498c
chore: additional NRT fixes
baywet Mar 27, 2025
db8b41a
chore: additional NRT fixes
baywet Mar 27, 2025
3737e0b
chore: additional NRT fixes
baywet Mar 27, 2025
4f8fe87
chore: additional NRT fixes
baywet Mar 27, 2025
661b05a
chore: additional NRT fixes
baywet Mar 27, 2025
b15301d
chore: additional NRT fixes
baywet Mar 27, 2025
269c0d5
chore: additional NRT fixes
baywet Mar 27, 2025
769bdd0
Merge branch 'main' into feat/upgrade-oai
baywet Apr 1, 2025
618e727
chore: changes extensions to return null value when assembly info is …
baywet Apr 1, 2025
fa5c1d3
chore: typo fix
baywet Apr 1, 2025
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
# IDE0009: Member access should be qualified.
dotnet_diagnostic.IDE0009.severity = none
dotnet_diagnostic.CA2016.severity = warning

[*.cs]
dotnet_public_api_analyzer.require_api_files = true
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static string GetHashSHA256(this string input)
Utils.CheckArgumentNull(input, nameof(input));

var inputBytes = Encoding.UTF8.GetBytes(input);
var hashBytes = hasher.Value.ComputeHash(inputBytes);
if (hasher.Value?.ComputeHash(inputBytes) is not {} hashBytes) return string.Empty;
var hash = new StringBuilder();
foreach (var b in hashBytes)
{
Expand Down
142 changes: 78 additions & 64 deletions src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class OpenApiOperationExtensions
/// <param name="addNoContent">Optional: Whether to add a 204 no content response.</param>
/// <param name="schema">Optional: The OpenAPI schema of the response.</param>
/// <param name="document">The OpenAPI document to lookup references.</param>
public static void AddErrorResponses(this OpenApiOperation operation, OpenApiConvertSettings settings, OpenApiDocument document, bool addNoContent = false, IOpenApiSchema schema = null)
public static void AddErrorResponses(this OpenApiOperation operation, OpenApiConvertSettings settings, OpenApiDocument document, bool addNoContent = false, IOpenApiSchema? schema = null)
{
Utils.CheckArgumentNull(operation, nameof(operation));
Utils.CheckArgumentNull(settings, nameof(settings));
Expand All @@ -39,7 +39,7 @@ public static void AddErrorResponses(this OpenApiOperation operation, OpenApiCon
{
if (settings.UseSuccessStatusCodeRange)
{
OpenApiResponse response = null;
OpenApiResponse? response = null;
if (schema != null)
{
response = new()
Expand All @@ -57,22 +57,25 @@ public static void AddErrorResponses(this OpenApiOperation operation, OpenApiCon
}
};
}
operation.Responses.Add(Constants.StatusCodeClass2XX, response ?? Constants.StatusCodeClass2XX.GetResponse(document));
if ((response ?? Constants.StatusCodeClass2XX.GetResponse(document)) is {} x2xxResponse)
operation.Responses.Add(Constants.StatusCodeClass2XX, x2xxResponse);
}
else
else if (Constants.StatusCode204.GetResponse(document) is {} x204Response)
{
operation.Responses.Add(Constants.StatusCode204, Constants.StatusCode204.GetResponse(document));
operation.Responses.Add(Constants.StatusCode204, x204Response);
}
}

if (settings.ErrorResponsesAsDefault)
if (settings.ErrorResponsesAsDefault && Constants.StatusCodeDefault.GetResponse(document) is {} defaultResponse)
{
operation.Responses.Add(Constants.StatusCodeDefault, Constants.StatusCodeDefault.GetResponse(document));
operation.Responses.Add(Constants.StatusCodeDefault, defaultResponse);
}
else
{
operation.Responses.Add(Constants.StatusCodeClass4XX, Constants.StatusCodeClass4XX.GetResponse(document));
operation.Responses.Add(Constants.StatusCodeClass5XX, Constants.StatusCodeClass5XX.GetResponse(document));
if (Constants.StatusCodeClass4XX.GetResponse(document) is {} x4xxResponse)
operation.Responses.Add(Constants.StatusCodeClass4XX, x4xxResponse);
if (Constants.StatusCodeClass5XX.GetResponse(document) is {} x5xxResponse)
operation.Responses.Add(Constants.StatusCodeClass5XX, x5xxResponse);
}
}
}
32 changes: 16 additions & 16 deletions src/Microsoft.OpenApi.OData.Reader/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public static class Utils
/// </summary>
/// <typeparam name="T">The type of the term.</typeparam>
/// <returns>The qualified name.</returns>
public static string GetTermQualifiedName<T>()
public static string? GetTermQualifiedName<T>()
{
object[] attributes = typeof(T).GetCustomAttributes(typeof(TermAttribute), false);
if (attributes == null && attributes.Length == 0)
if (attributes == null || attributes.Length == 0)
{
return null;
}
Expand All @@ -45,7 +45,7 @@ public static string GetTermQualifiedName<T>()
/// </summary>
/// <param name="input">The input string.</param>
/// <returns>The changed string.</returns>
public static string UpperFirstChar(string input)
public static string? UpperFirstChar(string? input)
{
if (input == null)
{
Expand Down Expand Up @@ -129,7 +129,7 @@ internal static string ToFirstCharacterLowerCase(this string input)
/// </summary>
/// <param name="path">The <see cref="ODataPath"/>.</param>
/// <param name="navigationPropertyName">Optional: The navigation property name.</param>
internal static string NavigationPropertyPath(this ODataPath path, string navigationPropertyName = null)
internal static string NavigationPropertyPath(this ODataPath path, string? navigationPropertyName = null)
{
string value = string.Join("/",
path.Segments.OfType<ODataNavigationPropertySegment>().Select(e => e.Identifier));
Expand Down Expand Up @@ -176,7 +176,7 @@ private static Dictionary<string, string> GetCustomXMLAttributesValueMapping(IEd
{
Dictionary<string, string> attributesValueMap = new();

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

if (!string.IsNullOrEmpty(attributeValue))
{
Expand All @@ -212,10 +212,10 @@ private static Dictionary<string, string> GetCustomXMLAttributesValueMapping(IEd
internal static bool IsBaseTypeReferencedAsTypeInModel(
this IEdmModel model,
IEdmStructuredType baseType,
IEnumerable<IEdmStructuredType> structuredTypes = null,
IEnumerable<IEdmAction> actions = null)
IEnumerable<IEdmStructuredType>? structuredTypes = null,
IEnumerable<IEdmAction>? actions = null)
{
string baseTypeName = baseType?.FullTypeName();
string baseTypeName = baseType.FullTypeName();
bool isBaseTypeEntity = Constants.EntityName.Equals(baseTypeName?.Split('.').Last(), StringComparison.OrdinalIgnoreCase);

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

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

if (segment is ODataOperationSegment operationSegment &&
operationSegment.Operation.Parameters.FirstOrDefault() is IEdmOperationParameter bindingParameter)
operationSegment.Operation?.Parameters.FirstOrDefault() is IEdmOperationParameter bindingParameter)
{
IEdmTypeReference bindingType = bindingParameter.Type;

Expand Down Expand Up @@ -339,10 +339,10 @@ internal static bool TryAddPath(this IDictionary<string, IOpenApiPathItem> pathI
}

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

IEdmEntityType operationEntityType = lastSegment.EntityTypeFromOperationSegment();
IEnumerable<IEdmStructuredType> derivedTypes = (operationEntityType != null)
var operationEntityType = lastSegment.EntityTypeFromOperationSegment();
var derivedTypes = (operationEntityType != null)
? context.Model.FindAllDerivedTypes(operationEntityType)
: null;

Expand Down
Loading
Loading