private void WriteProperty(StreamWriter writer, TypeScriptProperty property, int propertyOrder) { if (!string.IsNullOrEmpty(property.Comment)) { WritePropertyComment(writer, property.Comment); } if (string.IsNullOrEmpty(property.ArrayItemName)) { writer.WriteLine(Tab(1) + "@XMLChild({})"); } else { writer.WriteLine(Tab(1) + "@XMLChild({"); writer.WriteLine(Tab(2) + "name: \"{0}\",", property.ArrayItemName); writer.WriteLine(Tab(2) + "implicitStructure: \"{0}.$\"", property.Name); writer.WriteLine(Tab(1) + "})"); } var propertyName = property.Required ? property.Name : property.Name + StringConstants.QuestionMark; writer.WriteLine(Tab(1) + "public {0}: {1};", propertyName, property.Type); writer.WriteLine(); }
protected override TypeScriptType RamlTypeToSchemaType(RamlType ramlType, ConversionOptions options) { if (ramlType == null) { return(null); } var typeScriptType = new TypeScriptType(); typeScriptType.Name = ramlType.Name; // check if it is enum if (ramlType.Enum != null) { typeScriptType.Enum = new TypeScriptEnum(); var enumTypeName = RamlDataTypeToTypeScriptDataType(ramlType.Enum.ItemsTypeName); if (enumTypeName == null) { enumTypeName = GetRefDataType(ramlType.Enum.ItemsTypeName); } typeScriptType.Enum.EnumValues = new List <string>(); foreach (string enumValue in ramlType.Enum.EnumValues) { typeScriptType.Enum.EnumValues.Add(enumValue); } return(typeScriptType); } // check if it is array if (ramlType.Array != null) { typeScriptType.Array = new TypeScriptArray(); typeScriptType.Array.ItemName = ramlType.Array.ItemName; var arrayElementTypeName = RamlDataTypeToTypeScriptDataType(ramlType.Array.ItemsTypeName); if (arrayElementTypeName == null) { arrayElementTypeName = GetRefDataType(ramlType.Array.ItemsTypeName); } if (arrayElementTypeName != null) { typeScriptType.Array.ItemsTypeName = arrayElementTypeName; } return(typeScriptType); } if (ramlType.Description != null && options.GenerateDescriptions) { typeScriptType.Comment = ramlType.Description; } if (ramlType.Properties == null || ramlType.Properties.Count == 0) { return(typeScriptType); } typeScriptType.Properties = new List <TypeScriptProperty>(); foreach (RamlProperty ramlProperty in ramlType.Properties) { var typeScriptProperty = new TypeScriptProperty(); typeScriptProperty.Name = ramlProperty.Name; var typeName = RamlDataTypeToTypeScriptDataType(ramlProperty.Type); if (typeName != null) { typeScriptProperty.Type = typeName; } else { typeScriptProperty.Type = ramlProperty.Type; } typeScriptProperty.ArrayItemName = ramlProperty.ArrayItemName; if (ramlProperty.Description != null && options.GenerateDescriptions) { typeScriptProperty.Comment = ramlProperty.Description; } typeScriptProperty.Required = ramlProperty.Required; typeScriptType.Properties.Add(typeScriptProperty); } return(typeScriptType); }