Skip to content

Commit

Permalink
add documentation to WoT.Definition, fix minor deserialization bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
FadySalama committed Feb 7, 2024
1 parent 935ab0c commit b68c446
Show file tree
Hide file tree
Showing 9 changed files with 794 additions and 827 deletions.
97 changes: 57 additions & 40 deletions WoT/TDHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public override void WriteJson(JsonWriter writer, DataSchema value, JsonSerializ
if (value.Default != null) jo.Add("default", JToken.FromObject(value.Default));
if (value.Unit != null) jo.Add("unit", JToken.FromObject(value.Unit));
if (value.OneOf != null) jo.Add("oneOf", JToken.FromObject(value.OneOf));
if (value.AllOf != null) jo.Add("allOf", JToken.FromObject(value.AllOf));
if (value.Enum != null) jo.Add("enum", JToken.FromObject(value.Enum));
if (value.Format != null) jo.Add("format", JToken.FromObject(value.Format));
if (value.Type != null) jo.Add("type", JToken.FromObject(value.Type));
Expand Down Expand Up @@ -145,9 +144,9 @@ protected static ArraySchema FillArraySchemaObject(JToken schemaObj, JsonSeriali
}


if (schemaObj["const"] != null) schema.Const = schemaObj["const"];
if (schemaObj["default"] != null) schema.Default = schemaObj["default"];
if (schemaObj["enum"] != null) schema.Enum = schemaObj["enum"].ToObject<Object[]>();
if (schemaObj["const"] != null) schema.Const = schemaObj["const"].ToObject<List<object>>();
if (schemaObj["default"] != null) schema.Default = schemaObj["default"].ToObject<List<object>>();
if (schemaObj["enum"] != null) schema.Enum = schemaObj["enum"].ToObject<List<object>[]>();

return schema;
}
Expand Down Expand Up @@ -194,9 +193,9 @@ protected static ObjectSchema FillObjectSchemaObject(JToken schemaObj, JsonSeria
if (schemaObj["required"] != null) schema.Required = schemaObj["required"].ToObject<string[]>();
if (schemaObj["properties"] != null) schema.Properties = serializer.Deserialize(new JTokenReader(schemaObj["properties"]), objectType: typeof(Dictionary<string, DataSchema>)) as Dictionary<string, DataSchema>;

if (schemaObj["const"] != null) schema.Const = schemaObj["const"];
if (schemaObj["default"] != null) schema.Default = schemaObj["default"];
if (schemaObj["enum"] != null) schema.Enum = schemaObj["enum"].ToObject<Object[]>();
if (schemaObj["const"] != null) schema.Const = schemaObj["const"].ToObject<Dictionary<string, object>>();
if (schemaObj["default"] != null) schema.Default = schemaObj["default"].ToObject<Dictionary<string, object>>();
if (schemaObj["enum"] != null) schema.Enum = schemaObj["enum"].ToObject<Dictionary<string, object>[]>();

return schema;
}
Expand Down Expand Up @@ -245,7 +244,6 @@ protected static void CommonFiller<T>(T schema, JToken schemaObj, JsonSerializer
if (schemaObj["writeOnly"] != null) schema.WriteOnly = (bool)schemaObj["writeOnly"];
if (schemaObj["titles"] != null) schema.Titles = schemaObj["titles"].ToObject<MultiLanguage>();
if (schemaObj["descriptions"] != null) schema.Descriptions = schemaObj["descriptions"].ToObject<MultiLanguage>();
if (schemaObj["allOf"] != null) schema.AllOf = serializer.Deserialize(new JTokenReader(schemaObj["allOf"]), objectType: typeof(DataSchema[])) as DataSchema[];
if (schemaObj["oneOf"] != null) schema.OneOf = serializer.Deserialize(new JTokenReader(schemaObj["oneOf"]), objectType: typeof(DataSchema[])) as DataSchema[];

if (schemaObj["@type"] != null)
Expand Down Expand Up @@ -378,16 +376,21 @@ public override Form ReadJson(JsonReader reader, Type objectType, Form existingV
schema.OriginalJson = schemaObj.ToString();
if (schemaObj["contentCoding"] != null) schema.ContentCoding = schemaObj["contentCoding"].ToObject<string>();
if (schemaObj["subprotocol"] != null) schema.Subprotocol = schemaObj["subprotocol"].ToObject<string>();
if (schemaObj["additionalExpectedResponse"] != null)

if (schemaObj["response"] != null)
{
schema.AdditionalExpectedResponse = schemaObj["additionalExpectedResponse"].ToObject<AdditionalExpectedResponse>();
}
else
{ //Default value handling
string contentType = schema.ContentType;
schema.AdditionalExpectedResponse = new AdditionalExpectedResponse(contentType);
schema.Response = schemaObj["response"].ToObject<ExpectedResponse>();
}

if (schemaObj["additionalExpectedResponse"] != null)
{
schema.AdditionalExpectedResponse = schemaObj["additionalExpectedResponse"].ToObject<AdditionalExpectedResponse[]>();
//Default value handling
for (int i = 0; i < schema.AdditionalExpectedResponse.Length; i++)
{
if (schema.AdditionalExpectedResponse[i].ContentType == null) schema.AdditionalExpectedResponse[i].ContentType = schema.ContentType;
}
}

if (schemaObj["security"] != null) schema.Security = newSerializer.Deserialize<string[]>(new JTokenReader(schemaObj["security"]));

Expand Down Expand Up @@ -444,14 +447,19 @@ public override PropertyForm ReadJson(JsonReader reader, Type objectType, Proper
if (schemaObj["contentCoding"] != null) schema.ContentCoding = schemaObj["contentCoding"].ToObject<string>();
if (schemaObj["subprotocol"] != null) schema.Subprotocol = schemaObj["subprotocol"].ToObject<string>();

if (schemaObj["additionalExpectedResponse"] != null)
if (schemaObj["response"] != null)
{
schema.AdditionalExpectedResponse = schemaObj["additionalExpectedResponse"].ToObject<AdditionalExpectedResponse>();
schema.Response = schemaObj["response"].ToObject<ExpectedResponse>();
}
else
{//Default value handling
string contentType = schema.ContentType;
schema.AdditionalExpectedResponse = new AdditionalExpectedResponse(contentType);

if (schemaObj["additionalExpectedResponse"] != null)
{
schema.AdditionalExpectedResponse = schemaObj["additionalExpectedResponse"].ToObject<AdditionalExpectedResponse[]>();
//Default value handling
for (int i = 0; i < schema.AdditionalExpectedResponse.Length; i++)
{
if (schema.AdditionalExpectedResponse[i].ContentType == null) schema.AdditionalExpectedResponse[i].ContentType = schema.ContentType;
}
}

schema.OriginalJson = schemaObj.ToString();
Expand Down Expand Up @@ -514,14 +522,19 @@ public override ActionForm ReadJson(JsonReader reader, Type objectType, ActionFo
if (schemaObj["contentCoding"] != null) schema.ContentCoding = schemaObj["contentCoding"].ToObject<string>();
if (schemaObj["subprotocol"] != null) schema.Subprotocol = schemaObj["subprotocol"].ToObject<string>();

if (schemaObj["additionalExpectedResponse"] != null)
if (schemaObj["response"] != null)
{
schema.AdditionalExpectedResponse = schemaObj["additionalExpectedResponse"].ToObject<AdditionalExpectedResponse>();
schema.Response = schemaObj["response"].ToObject<ExpectedResponse>();
}
else
{//Default value handling
string contentType = schema.ContentType;
schema.AdditionalExpectedResponse = new AdditionalExpectedResponse(contentType);

if (schemaObj["additionalExpectedResponse"] != null)
{
schema.AdditionalExpectedResponse = schemaObj["additionalExpectedResponse"].ToObject<AdditionalExpectedResponse[]>();
//Default value handling
for (int i = 0; i < schema.AdditionalExpectedResponse.Length; i++)
{
if (schema.AdditionalExpectedResponse[i].ContentType == null) schema.AdditionalExpectedResponse[i].ContentType = schema.ContentType;
}
}

schema.OriginalJson = schemaObj.ToString();
Expand Down Expand Up @@ -588,14 +601,19 @@ public override EventForm ReadJson(JsonReader reader, Type objectType, EventForm
if (schemaObj["contentCoding"] != null) schema.ContentCoding = schemaObj["contentCoding"].ToObject<string>();
if (schemaObj["subprotocol"] != null) schema.Subprotocol = schemaObj["subprotocol"].ToObject<string>();

if (schemaObj["additionalExpectedResponse"] != null)
if (schemaObj["response"] != null)
{
schema.AdditionalExpectedResponse = schemaObj["additionalExpectedResponse"].ToObject<AdditionalExpectedResponse>();
schema.Response = schemaObj["response"].ToObject<ExpectedResponse>();
}
else
{//Default value handling
string contentType = schema.ContentType;
schema.AdditionalExpectedResponse = new AdditionalExpectedResponse(contentType);

if (schemaObj["additionalExpectedResponse"] != null)
{
schema.AdditionalExpectedResponse = schemaObj["additionalExpectedResponse"].ToObject<AdditionalExpectedResponse[]>();
//Default value handling
for (int i = 0; i < schema.AdditionalExpectedResponse.Length; i++)
{
if (schema.AdditionalExpectedResponse[i].ContentType == null) schema.AdditionalExpectedResponse[i].ContentType = schema.ContentType;
}
}

schema.OriginalJson = schemaObj.ToString();
Expand Down Expand Up @@ -852,9 +870,9 @@ protected static ArrayPropertyAffordance FillArrayPropertyAffordanceObject(JToke
}


if (propObj["const"] != null) schema.Const = propObj["const"];
if (propObj["default"] != null) schema.Default = propObj["default"];
if (propObj["enum"] != null) schema.Enum = propObj["enum"].ToObject<Object[]>();
if (propObj["const"] != null) schema.Const = propObj["const"].ToObject<List<object>>();
if (propObj["default"] != null) schema.Default = propObj["default"].ToObject<List<object>>();
if (propObj["enum"] != null) schema.Enum = propObj["enum"].ToObject<List<object>[]>();

return schema;
}
Expand Down Expand Up @@ -901,9 +919,9 @@ protected static ObjectPropertyAffordance FillObjectPropertyAffordanceObject(JTo
if (propObj["required"] != null) schema.Required = propObj["required"].ToObject<string[]>();
if (propObj["properties"] != null) schema.Properties = serializer.Deserialize(new JTokenReader(propObj["properties"]), objectType: typeof(Dictionary<string, DataSchema>)) as Dictionary<string, DataSchema>;

if (propObj["const"] != null) schema.Const = propObj["const"];
if (propObj["default"] != null) schema.Default = propObj["default"];
if (propObj["enum"] != null) schema.Enum = propObj["enum"].ToObject<Object[]>();
if (propObj["const"] != null) schema.Const = propObj["const"].ToObject<Dictionary<string, object>>();
if (propObj["default"] != null) schema.Default = propObj["default"].ToObject<Dictionary<string, object>>();
if (propObj["enum"] != null) schema.Enum = propObj["enum"].ToObject<Dictionary<string, object>[]>();

return schema;
}
Expand Down Expand Up @@ -947,7 +965,6 @@ protected static void CommonFiller<T>(T propertyAffordance, JToken propObj, Json
if (propObj["writeOnly"] != null) propertyAffordance.WriteOnly = (bool)propObj["writeOnly"];
if (propObj["titles"] != null) propertyAffordance.Titles = propObj["titles"].ToObject<MultiLanguage>();
if (propObj["descriptions"] != null) propertyAffordance.Descriptions = propObj["descriptions"].ToObject<MultiLanguage>();
if (propObj["allOf"] != null) propertyAffordance.AllOf = serializer.Deserialize(new JTokenReader(propObj["allOf"]), objectType: typeof(DataSchema[])) as DataSchema[];
if (propObj["oneOf"] != null) propertyAffordance.OneOf = serializer.Deserialize(new JTokenReader(propObj["oneOf"]), objectType: typeof(DataSchema[])) as DataSchema[];
if (propObj["forms"] != null) propertyAffordance.Forms = serializer.Deserialize(new JTokenReader(propObj["forms"]), objectType: typeof(PropertyForm[])) as PropertyForm[];
if (propObj["@type"] != null)
Expand Down
Loading

0 comments on commit b68c446

Please sign in to comment.