< Summary

Information
Class: Anichron.API.Infrastructure.ProblemCodeDocumentTransformer
Assembly: Anichron.API
File(s): /home/runner/work/anichron/anichron/src/Anichron.API/Infrastructure/ProblemCodeDocumentTransformer.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 40
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TransformAsync(...)100%22100%
ErrorCode()100%11100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.API/Infrastructure/ProblemCodeDocumentTransformer.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Mvc;
 2using Microsoft.AspNetCore.OpenApi;
 3using Microsoft.OpenApi;
 4using System.Text.Json.Nodes;
 5
 6namespace Anichron.API.Infrastructure;
 7
 8/// <summary>Describes the <c>code</c> extension that the API's own problems carry, and each field error, as an <c>Error
 9internal sealed class ProblemCodeDocumentTransformer : IOpenApiDocumentTransformer
 10{
 11    private const string errorCodeSchema = "ErrorCode";
 12    private const string errorsProperty = "errors";
 13
 14    public Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerContext context, CancellationToken ca
 115    {
 116        var schemas = document.Components!.Schemas!;
 117        document.AddComponent(errorCodeSchema, ErrorCode());
 718        foreach (var name in new[] { nameof(ProblemDetails), nameof(HttpValidationProblemDetails) })
 219            schemas[name].Properties![ApiProblems.CodeExtension] = new OpenApiSchemaReference(errorCodeSchema, document)
 20
 121        schemas[nameof(HttpValidationProblemDetails)].Properties![errorsProperty] = new OpenApiSchema
 122        {
 123            Type = JsonSchemaType.Object,
 124            AdditionalProperties = new OpenApiSchema
 125            {
 126                Type = JsonSchemaType.Array,
 127                Items = new OpenApiSchemaReference(errorCodeSchema, document),
 128            },
 129        };
 30
 131        return Task.CompletedTask;
 132    }
 33
 34    private static OpenApiSchema ErrorCode()
 135        => new()
 136        {
 137            Type = JsonSchemaType.String,
 138            Enum = [.. ErrorCodes.All().Select(code => (JsonNode)code)],
 139        };
 40}