public List <ReusableType> Iteratereusable(CogsModel model) { List <ReusableType> res = new List <ReusableType>(); foreach (var reuseabletype in model.ReusableDataTypes) { ReusableType define = new ReusableType(); define.Name = reuseabletype.Name; foreach (var prop in reuseabletype.Properties) { var temp = new JsonSchemaProp(); temp.MultiplicityElement = new Cardinality(); temp.Name = prop.Name; if (IsReusableType(prop.DataType.Name)) { temp.Reference = "#/definitions/" + prop.DataType.Name; } else if (IsSimpleType(prop.DataType.Name)) { temp.Reference = "#/simpleType/" + prop.DataType.Name; } else if (IsItemType(prop.DataType.Name)) { temp.Reference = "#/definitions/Reference"; } else { if (TypeBelongToInt(prop.DataType.Name)) { temp.Type = "integer"; temp.original_type = prop.DataType.Name; } else if (TypeBelongToNum(prop.DataType.Name)) { temp.Type = "number"; temp.original_type = prop.DataType.Name; } else { temp.Type = prop.DataType.Name.ToLower(); } } temp.MultiplicityElement.MinCardinality = prop.MinCardinality; temp.MultiplicityElement.MaxCardinality = prop.MaxCardinality; temp.Description = prop.Description; define.Properties.Add(temp); } res.Add(define); } return(res); }
public void SetJsonSchemaProp(JsonSchema temp, Property property) { var prop = new JsonSchemaProp(); prop.MultiplicityElement = new Cardinality(); prop.Name = property.Name; if (IsReusableType(property.DataType.Name)) { prop.Reference = "#/definitions/" + property.DataType.Name; } else if (IsSimpleType(property.DataType.Name)) { prop.Reference = "#/simpleType/" + property.DataType.Name; } else if (IsItemType(property.DataType.Name)) { prop.Reference = "#/definitions/Reference"; } else { if (TypeBelongToInt(property.DataType.Name)) { prop.Type = "integer"; prop.original_type = property.DataType.Name; } else if (TypeBelongToNum(property.DataType.Name)) { prop.Type = "number"; prop.original_type = property.DataType.Name; } else { prop.Type = property.DataType.Name.ToLower(); } } prop.MultiplicityElement.MinCardinality = property.MinCardinality; prop.MultiplicityElement.MinCardinality = property.MinCardinality; if (property.MinCardinality == "1") { temp.Required.Add(property.Name); } prop.MultiplicityElement.MaxCardinality = property.MaxCardinality; prop.Description = property.Description; temp.Properties.Add(prop); }