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

namespace LibMatrix.DebugDataValidationApi.Controllers;

[ApiController]
[Route("/")]
public class ValidationController : ControllerBase {
    private readonly ILogger<ValidationController> _logger;

    public ValidationController(ILogger<ValidationController> logger) {
        _logger = logger;
    }

    [HttpPost("/validate/{type}")]
    public async Task<bool> Get([FromRoute] string type, [FromBody] JsonElement content) {
        Type t = Type.GetType(type);
        if (t is null) {
            Console.WriteLine($"Type `{type}` does not exist!");
            throw new ArgumentException($"Unknown type {type}!");
        }
        Console.WriteLine($"Validating {type}...");
        return content.FindExtraJsonElementFields(t, "$");
    }
}