Skip to content

Commit

Permalink
Fix for \packages endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
juileetikekar committed Nov 14, 2024
1 parent a5a3814 commit df25c22
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/IO.Swagger.Lib.V3/Controllers/AASXFileServerAPIApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,18 @@ public virtual async Task<IActionResult> GetAASXByPackageId([FromRoute] [Require
public virtual IActionResult GetAllAASXPackageIds([FromQuery] string? aasId, [FromQuery] int? limit, [FromQuery] string? cursor)
{
_logger.LogInformation($"Received request to get all the AASX packages.");
var decodedAasId = _decoderService.Decode("aasId", aasId);

if (decodedAasId == null)
string decodedAasId = null;
if (!string.IsNullOrEmpty(aasId))
{
throw new NotAllowed($"Cannot proceed as {nameof(decodedAasId)} is null");
decodedAasId = _decoderService.Decode("aasId", aasId);
}

var packages = _fileService.GetAllAASXPackageIds(decodedAasId);

var authResult = _authorizationService.AuthorizeAsync(User, packages, "SecurityPolicy").Result;
if (!authResult.Succeeded)
{
var failedReasons = authResult.Failure.FailureReasons;
var failedReasons = authResult.Failure.FailureReasons;
var authorizationFailureReasons = failedReasons.ToList();
if (authorizationFailureReasons.Count != 0)
{
Expand Down
20 changes: 20 additions & 0 deletions src/IO.Swagger.Lib.V3/Formatters/AasResponseFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public override bool CanWriteResult(OutputFormatterCanWriteContext context)
{
return base.CanWriteResult(context);
}
if (typeof(PackageDescriptionPagedResult).IsAssignableFrom(context.ObjectType))
{
return base.CanWriteResult(context);
}
else
return false;

Check notice

Code scanning / CodeQL

Missed ternary opportunity Note

Both branches of this 'if' statement return - consider using '?' to express intent better.
}
Expand Down Expand Up @@ -305,6 +309,22 @@ public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context)
jsonNode.WriteTo(writer);
writer.FlushAsync().GetAwaiter().GetResult();
}
else if(typeof(PackageDescriptionPagedResult).IsAssignableFrom(context.ObjectType))
{
JsonNode jsonNode = null;
var options = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
if (context.Object is PackageDescriptionPagedResult pagedResult)
{
jsonNode = JsonSerializer.SerializeToNode(pagedResult, options);
}
var writer = new Utf8JsonWriter(response.Body);

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable Warning

Disposable 'Utf8JsonWriter' is created but not disposed.
jsonNode.WriteTo(writer);

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
jsonNode
may be null at this access because of
this
assignment.
writer.FlushAsync().GetAwaiter().GetResult();
}

return Task.FromResult(response);
}
Expand Down

0 comments on commit df25c22

Please sign in to comment.