JsonSchema schema = null;
try
{ //schemaJson holds the description of the object "shape" - ie what properties it has and what type they are
string schemaJson = @"{
'description':'material',
'type':'object',
'properties':{
'srn':{
'type':'string'
},
'restriction':{
'type':'string'
},
'id':{
'type':'string'
},
'source':{
'type':'string'
},
'schema':{
'type':'string'
},
'ref':{
'type':'string'
},
'title':{
'type':'string'
},
'description':{
'type':'string'
},
}
}";
var sJson = schemaJson.ToString();
//schema now holds the JsonSchema describing what the object should look like in terms of "shape" (properties etc)
schema = JsonSchema.Parse(sJson);
}
catch(Exception ex)
{
string str = ex + "";
}
try
{
JObject fieldsRequest = JObject.Parse(@"{
'srn': 'srnstring',
'restriction': 'Client',
'id': '36d5c83c-db06-4ebb-aaf9-b146a54e7b1c',
'source': 'F1',
'schema': 'MaterialsFieldsRequest',
'ref': 'form-Uri-ReferenceEquals',
'title': 'FieldType',
'description': 'This is the FieldType',
}");
//fieldsRequest is a JObject that may or may not be a valid implementation of that schema
bool valid = fieldsRequest.IsValid(schema); //is it a valid implementation?
if (valid)
material.Fields = fieldsRequest; //if valid use the JObject
}
catch (Exception ex)
{
//ToDo: if not valid, do what?
}
Colleagues are saying they want the Payload to be completely Json Schema and the whole Response object to be completely Json Schema - but of course these have to contain DATA not the DESCRIPTION of data - so this confuses me and does not make sense to me
Help! Am I misunderstanding something vital here? These guys are much brighter than me so I fear I must have the fundamentals all wrong?
public class MaterialExtension
{
public string Srn { get; set; }
public string Restriction { get; set; }
public string Id { get; set; }
public string Source { get; set; }
public string Category { get; set; }
public string FormUri { get; set; }
public string CountryCode { get; set; }
public string RegionCode { get; set; }
}
public class Material : JsonSchema
{
[JsonProperty(PropertyName = "x-st")]
public MaterialExtension Extension { get; set; }
}