NET8 Web API project.
My controller actions don’t have a typed input parameter. The incoming JSON is readed from request body stream and validated against the schema using NJsonSchema and sent either to another service or saved to the database. No manipulations are performed on it.
The project has a swagger enabled and in this situation it does not show the scheme for the input parameter in swagger-ui. But I need the input parameter scheme (by which this is validated) to be visible in UI as well as in the final OpenAPI specification (swagger.json) file. Are there any ready-made solutions or nugget packages for this situation?
I look towards the package Microsoft.OpenApi.Readers, but things a little bit complicated there.
Simplified code example:
[HttpPost("upload")]
[ProducesResponseType<SimpleModel>(200)]
public async Task<IActionResult> Upload()
{
using var sr = new StreamReader(Request.Body);
var requestBody = await sr.ReadToEndAsync();
// Used for checking is JSON valid
var model = JObject.Parse(requestBody);
var validationErrors = _jsonSchema.Validate(model);
if (validationErrors.Count > 0)
return BadRequest(validationErrors);
/*
* do some useful non typed stuff with input model
*/
return Ok();
}