about summary refs log tree commit diff
path: root/Utilities/LibMatrix.DebugDataValidationApi/Controllers/ValidationController.cs
blob: 1b936143cf34e3c4fc943e623df99c7297c1fe31 (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, "$"));
    }
}