about summary refs log tree commit diff
path: root/Utilities/LibMatrix.DebugDataValidationApi/Controllers/ValidationController.cs
blob: 3420e56262d3a5bc8991742793823ef923ba968a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System.Text.Json;
using LibMatrix.Extensions;
using Microsoft.AspNetCore.Mvc;

namespace LibMatrix.DebugDataValidationApi.Controllers;

[ApiController]
[Route("/")]
public class ValidationController(ILogger<ValidationController> logger) : ControllerBase {
    [HttpPost("/validate/{type}")]
    public Task<bool> Get([FromRoute] string type, [FromBody] JsonElement content) {
        var t = Type.GetType(type);
        if (t is null) {
            logger.LogWarning($"Type `{type}` does not exist!");
            throw new ArgumentException($"Unknown type {type}!");
        }

        logger.LogInformation($"Validating {type}...");
        return Task.FromResult(content.FindExtraJsonElementFields(t, "$"));
    }
}