-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathJsonBooleanValidator.cs
More file actions
27 lines (24 loc) · 767 Bytes
/
JsonBooleanValidator.cs
File metadata and controls
27 lines (24 loc) · 767 Bytes
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
27
using System.Collections.Generic;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json.Linq;
namespace Swashbuckle.AspNetCore.ApiTesting
{
public class JsonBooleanValidator : IJsonValidator
{
public bool CanValidate(OpenApiSchema schema) => schema.Type == "boolean";
public bool Validate(
OpenApiSchema schema,
OpenApiDocument openApiDocument,
JToken instance,
out IEnumerable<string> errorMessages)
{
if (instance.Type != JTokenType.Boolean)
{
errorMessages = [$"Path: {instance.Path}. Instance is not of type 'boolean'"];
return false;
}
errorMessages = [];
return true;
}
}
}