Adds draft schema document and initial logic to validate config against schema

This commit is contained in:
Neil Dorin
2020-01-20 16:29:01 -07:00
parent 1017464980
commit aa64cc917c
6 changed files with 849 additions and 7 deletions

View File

@@ -11,9 +11,9 @@ using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Core.Config
{
public class DeviceConfig
public class DeviceConfig : PropertiesConfigBase
{
[JsonProperty("key")]
[JsonProperty("key", Required = Required.Always)]
public string Key { get; set; }
[JsonProperty("uid")]
@@ -25,12 +25,87 @@ namespace PepperDash.Essentials.Core.Config
[JsonProperty("group")]
public string Group { get; set; }
[JsonProperty("type")]
[JsonProperty("type", Required = Required.Always)]
public string Type { get; set; }
[JsonProperty("properties")]
[JsonProperty("properties", Required = Required.Always)]
[JsonConverter(typeof(DevicePropertiesConverter))]
public JToken Properties { get; set; }
public DeviceConfig()
{
SchemaJson = @"
{
'definitions': {},
'$schema': 'http://json-schema.org/draft-07/schema#',
'$id': 'http://example.com/root.json',
'type': 'object',
'title': 'The Root Schema',
'properties': {
'name': {
'$id': '#/properties/name',
'type': 'string',
'title': 'The Name Schema',
'default': '',
'examples': [
'App Server'
],
'pattern': '^(.*)$'
},
'group': {
'$id': '#/properties/group',
'type': 'string',
'title': 'The Group Schema',
'default': '',
'examples': [
'appServer'
],
'pattern': '^(.*)$'
},
'properties': {
'$id': '#/properties/properties',
'type': 'object',
'title': 'The Properties Schema'
},
'uid': {
'$id': '#/properties/uid',
'type': 'integer',
'title': 'The Uid Schema',
'default': 0,
'examples': [
4
]
},
'key': {
'$id': '#/properties/key',
'type': 'string',
'title': 'The Key Schema',
'default': '',
'examples': [
'display-1'
],
'pattern': '^(.*)$'
},
'type': {
'$id': '#/properties/type',
'type': 'string',
'title': 'The Type Schema',
'default': '',
'examples': [
'appServer'
],
'pattern': '^(.*)$'
}
},
'required': [
'group',
'properties',
'key',
'type'
]
}
";
}
}
/// <summary>
@@ -59,7 +134,7 @@ namespace PepperDash.Essentials.Core.Config
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException("SOD OFF HOSER");
throw new NotImplementedException("Not Supported");
}
}
}