Skip to content

Commit f5ec4a2

Browse files
author
Caitlin Bales (MSFT)
committed
Add logging for reserved word translation
1 parent 1c0cc49 commit f5ec4a2

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

src/GraphODataTemplateWriter/.config/TemplateWriterSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"AvailableLanguages": [ "Android", "ObjC", "CSharp", "PHP", "Python", "TypeScript", "GraphEndpointList" ],
33
"TargetLanguage": "CSharp",
44
"Plugins": [ ],

src/GraphODataTemplateWriter/CodeHelpers/Android/TypeHelperAndroid.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static string SanitizePropertyName(this string property, OdcmObject odcmP
9797
{
9898
if (ReservedNames.Contains(property))
9999
{
100-
logger.Info("Property {0} is a reserved word in Android. Converting to {1}{0}", property, ReservedPrefix);
100+
logger.Info("Property \"{0}\" is a reserved word in Android. Converting to \"{1}{0}\"", property, ReservedPrefix);
101101
return ReservedPrefix + property;
102102
}
103103

@@ -107,7 +107,7 @@ public static string SanitizePropertyName(this string property, OdcmObject odcmP
107107
if (odcmProperty.Projection.Type.Name.ToUpperFirstChar() == odcmProperty.Name.ToUpperFirstChar())
108108
{
109109
// Name the property: {metadataName} + "Property"
110-
logger.Info("Property type {0} has the same name as the class. Converting to {0}Property", property);
110+
logger.Info("Property type \"{0}\" has the same name as the class. Converting to \"{0}Property\"", property);
111111
return string.Concat(property, "Property");
112112
}
113113

src/GraphODataTemplateWriter/CodeHelpers/CSharp/TypeHelperCSharp.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public static string GetSanitizedPropertyName(this string property, OdcmProperty
238238
{
239239
var reservedPrefix = string.IsNullOrEmpty(prefix) ? DefaultReservedPrefix : prefix;
240240

241-
logger.Info("Property {0} is a reserved word in .NET. Converting to {1}{0}", property.ToUpperFirstChar(), reservedPrefix);
241+
logger.Info("Property \"{0}\" is a reserved word in .NET. Converting to \"{1}{0}\"", property.ToUpperFirstChar(), reservedPrefix);
242242
return string.Concat(reservedPrefix, property.ToUpperFirstChar());
243243
}
244244

@@ -251,7 +251,7 @@ public static string GetSanitizedPropertyName(this string property, OdcmProperty
251251
if (odcmProperty.Projection.Type.Name.ToUpperFirstChar() == odcmProperty.Class.Name.ToUpperFirstChar())
252252
{
253253
// Name the property: {metadataName} + "Property"
254-
logger.Info("Property type {0} has the same name as the class. Converting to {0}Property", property);
254+
logger.Info("Property type \"{0}\" has the same name as the class. Converting to \"{0}Property\"", property);
255255
return string.Concat(property, "Property");
256256
}
257257

src/GraphODataTemplateWriter/CodeHelpers/ObjC/TypeHelperObjC.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.ObjC
77
using Microsoft.Graph.ODataTemplateWriter.Extensions;
88
using Microsoft.Graph.ODataTemplateWriter.Settings;
99
using Vipr.Core.CodeModel;
10+
using NLog;
1011

1112
public static class TypeHelperObjC
1213
{
1314
public static string Prefix = ConfigurationService.Settings.NamespacePrefix;
1415

16+
private static Logger logger = LogManager.GetCurrentClassLogger();
17+
1518
private static ICollection<string> reservedNames;
1619
public static ICollection<string> ReservedNames
1720
{
@@ -157,6 +160,10 @@ public static string SanitizePropertyName(this OdcmProperty property)
157160
{
158161
if (ReservedNames.Contains(property.Name.ToLower()))
159162
{
163+
logger.Info("Property \"{0}\" is a reserved word in Objective-C. Converting to \"{1}{0}\"",
164+
property.Name.ToUpperFirstChar(),
165+
property.Class.Name.ToLowerFirstChar()
166+
);
160167
return property.Class.Name.ToLowerFirstChar() + property.Name.ToUpperFirstChar();
161168
}
162169
return property.Name;

src/GraphODataTemplateWriter/CodeHelpers/PHP/TypeHelperPHP.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.PHP
66
using Microsoft.Graph.ODataTemplateWriter.Extensions;
77
using Vipr.Core.CodeModel;
88
using System;
9+
using NLog;
910

1011
public static class TypeHelperPHP
1112
{
1213
public const string ReservedPrefix = "Graph";
14+
private static Logger logger = LogManager.GetCurrentClassLogger();
15+
1316
public static HashSet<string> ReservedNames
1417
{
1518
get
@@ -120,6 +123,7 @@ public static string SanitizeEntityName(this String name)
120123
{
121124
if (ReservedNames.Contains(name))
122125
{
126+
logger.Info("Property \"{0}\" is a reserved word in PHP. Converting to \"{1}{0}\"", name, ReservedPrefix);
123127
return ReservedPrefix + name.ToCheckedCase();
124128
}
125129

@@ -130,6 +134,7 @@ public static string SanitizePropertyName(this String name, String entityName)
130134
{
131135
if (name == "properties")
132136
{
137+
logger.Info("Property \"{0}\" is a reserved word in PHP. Converting to \"{1}{0}\"", name, ReservedPrefix);
133138
return entityName + name.ToCheckedCase();
134139
}
135140

src/GraphODataTemplateWriter/CodeHelpers/Python/TypeHelperPython.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.Python
55
using System.Collections.Generic;
66
using Microsoft.Graph.ODataTemplateWriter.Extensions;
77
using Vipr.Core.CodeModel;
8+
using NLog;
89

910
public static class TypeHelperPython
1011
{
1112
public const string ReservedPrefix = "$$__$$";
13+
private static Logger logger = LogManager.GetCurrentClassLogger();
14+
1215
public static ICollection<string> ReservedNames
1316
{
1417
get
@@ -102,6 +105,7 @@ public static string GetToLowerFirstCharName(this OdcmProperty property)
102105
public static string SanitizePropertyName(this OdcmProperty property)
103106
{
104107
if (ReservedNames.Contains(property.Name.ToLower())) {
108+
logger.Info("Property \"{0}\" is a reserved word in Python. Converting to \"{1}{0}\"", property.Name, ReservedPrefix);
105109
return ReservedPrefix + property.Name;
106110
}
107111
return property.Name;

0 commit comments

Comments
 (0)