Skip to content

Commit 86a5f1a

Browse files
authored
Merge pull request #175 from microsoftgraph/vidadhee/ObjcModelGen
Vidadhee/objc model gen
2 parents bca4cc4 + 527eed3 commit 86a5f1a

File tree

7 files changed

+331
-38
lines changed

7 files changed

+331
-38
lines changed

Templates/ObjC/Base/SharedObjC.template.tt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ private string GetJsonToObjCExpressionConversion(string expr,OdcmProperty prop)
118118
expr);
119119
}
120120

121+
if(GetObjCTypeIdentifier(prop,true)=="MSDuration")
122+
{
123+
return String.Format(@"[{0} ms_durationFromString: {1}]",
124+
GetObjCTypeIdentifier(prop,true),
125+
expr);
126+
}
127+
121128
if(prop.IsEnum())
122129
{
123130
return String.Format(
@@ -136,6 +143,11 @@ private string GetJsonToObjCExpressionConversion(string expr,OdcmProperty prop)
136143
expr);
137144
}
138145

146+
if(type.Name == "Byte")
147+
{
148+
return expr;
149+
}
150+
139151
return String.Format(
140152
@"[{0} {1}]",
141153
expr,
@@ -190,6 +202,27 @@ private string SetDictionaryPropertyInJsonConvertibleForm(OdcmProperty prop, str
190202
// Dictionary entries can either be directly NSJSON-typed, or convertible to
191203
// a NSJSON type via [MSObject getNSJsonSerializationCompatibleValue].
192204
//
205+
206+
if(GetObjCTypeIdentifier(prop,true)=="NSDate" ||
207+
GetObjCTypeIdentifier(prop,true)=="MSDate")
208+
{
209+
return String.Format(@"self.dictionary[@""{0}""] = {1};",
210+
prop.Name,
211+
String.Format(@"[{0} ms_toString]",GetObjCToJsonConvertibleExpressionConversion(prop,val)));
212+
}
213+
214+
if(GetObjCTypeIdentifier(prop,true)=="MSTimeOfDay")
215+
{
216+
return String.Format(@"self.dictionary[@""{0}""] = {1};",
217+
prop.Name,
218+
String.Format(@"[{0} ms_toString]",GetObjCToJsonConvertibleExpressionConversion(prop,val)));
219+
}
220+
221+
if(GetObjCTypeIdentifier(prop,true)=="MSDuration")
222+
{
223+
return String.Format(@"self.dictionary[@""{0}""] = {1};",prop.Name,String.Format(@"{0}.durationString",GetObjCToJsonConvertibleExpressionConversion(prop,val)));
224+
}
225+
193226
return String.Format(@"self.dictionary[@""{0}""] = {1};",prop.Name,GetObjCToJsonConvertibleExpressionConversion(prop,val));
194227
}
195228

@@ -203,15 +236,15 @@ private string GetHydratedIVarFromDictionary(OdcmProperty prop)
203236

204237
if ([{0} isKindOfClass:[NSArray class]]){{
205238
for (id {2} in {0}){{
206-
[{0}Result addObject:{3}];
239+
[{0}Result addObject:{2}];
207240
}}
208241
}}
209242

210243
_{0} = {0}Result;
211244
",
212245
GetObjCProperty(prop),
213246
prop.Name,
214-
prop.Projection.Type.Name.ToLowerFirstChar(),
247+
"temp"+prop.Projection.Type.Name.ToUpperFirstChar(),
215248
GetJsonToObjCExpressionConversion(prop.Projection.Type.Name.ToLowerFirstChar(), prop));
216249
}
217250

Templates/ObjC/Models/EnumType.m.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var typeName = GetObjCTypeIdentifier(entity);
77
var valueTypeName = typeName + "Value";
88
#>
99

10-
#include <<#=typeName#>.h>
10+
#import "<#=typeName#>.h"
1111

1212
@interface <#=typeName#> () {
1313
<#=valueTypeName#> _enumValue;

Templates/ObjC/Models/Models.h.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import "MSDate.h"
66
#import "MSTimeOfDay.h"
7+
#import "MSDuration.h"
78
<#
89
var enums = model.GetEnumTypes();
910
foreach(var e in enums)

Templates/Templates.csproj

Lines changed: 274 additions & 1 deletion
Large diffs are not rendered by default.

src/GraphODataTemplateWriter/.config/ObjCSettings.json

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,12 @@
1010

1111
{ "Template": "EntityType", "SubProcessor": "EntityType", "Type": "Model", "Name": "<Class>" },
1212
{ "Template": "ComplexType", "SubProcessor": "ComplexType", "Type": "Model", "Name": "<Class>", "Ignore": "methodResponse" },
13-
{ "Template": "EnumType", "SubProcessor": "EnumType", "Type": "Model", "Name": "<Class>" },
14-
{ "Template": "EntityRequest", "SubProcessor": "EntityType", "Type": "Request", "Name": "<Class>Request" },
15-
{ "Template": "EntityRequestBuilder", "SubProcessor": "EntityType", "Type": "Request", "Name": "<Class>RequestBuilder" },
16-
{ "Template": "StreamRequest", "SubProcessor": "StreamProperty", "Type": "Request", "Name": "<Class><Property>Request" },
17-
{ "Template": "MethodRequest", "SubProcessor": "Method", "Type": "Request", "Name": "<Class><Method>Request" },
18-
{ "Template": "MethodRequestBuilder", "SubProcessor": "Method", "Type": "Request", "Name": "<Class><Method>RequestBuilder" }
13+
{ "Template": "EnumType", "SubProcessor": "EnumType", "Type": "Model", "Name": "<Class>" }
1914
],
2015

2116
"ObjC": [
2217
{ "Template": "Models", "SubProcessor": "Other", "Type": "Model", "Name": "Models" },
23-
{ "Template": "ODataEntities", "SubProcessor": "Other", "Type": "Model", "Name": "ODataEntities" },
24-
25-
{ "Template": "StreamRequest", "SubProcessor": "MediaEntityType", "Type": "Request", "Name": "<Class>StreamRequest" },
26-
27-
{ "Template": "EntityWithReferenceRequest", "SubProcessor": "EntityReferenceType", "Type": "Request", "Name": "<Class>WithReferenceRequest" },
28-
{ "Template": "EntityWithReferenceRequestBuilder", "SubProcessor": "EntityReferenceType", "Type": "Request", "Name": "<Class>WithReferenceRequestBuilder" },
29-
{ "Template": "EntityReferenceRequest", "SubProcessor": "EntityReferenceType", "Type": "Request", "Name": "<Class>ReferenceRequest" },
30-
{ "Template": "EntityReferenceRequestBuilder", "SubProcessor": "EntityReferenceType", "Type": "Request", "Name": "<Class>ReferenceRequestBuilder" },
31-
32-
{ "Template": "EntityCollectionRequest", "SubProcessor": "NavigationCollectionProperty", "Type": "Request", "Name": "<Class><Property>CollectionRequest", "Exclude": "daysOfWeek;ignorableCollection2", "Ignore": "ignorableCollection" },
33-
{ "Template": "EntityCollectionRequestBuilder", "SubProcessor": "NavigationCollectionProperty", "Type": "Request", "Name": "<Class><Property>CollectionRequestBuilder", "Exclude": "daysOfWeek;ignorableCollection2", "Ignore": "ignorableCollection" },
34-
{ "Template": "EntityCollectionRequest", "SubProcessor": "CollectionReferenceProperty", "Type": "Request", "Name": "<Class><Property>CollectionWithReferencesRequest", "Exclude": "daysOfWeek;ignorableCollection2", "Ignore": "ignorableCollection" },
35-
{ "Template": "EntityCollectionRequestBuilder", "SubProcessor": "CollectionReferenceProperty", "Type": "Request", "Name": "<Class><Property>CollectionWithReferencesRequestBuilder", "Exclude": "daysOfWeek;ignorableCollection2", "Ignore": "ignorableCollection" },
36-
37-
{ "Template": "EntityCollectionReferenceRequest", "SubProcessor": "CollectionReferenceProperty", "Type": "Request", "Name": "<Class><Property>CollectionReferencesRequest", "Exclude": "daysOfWeek;ignorableCollection2", "Ignore": "ignorableCollection" },
38-
{ "Template": "EntityCollectionReferenceRequestBuilder", "SubProcessor": "CollectionReferenceProperty", "Type": "Request", "Name": "<Class><Property>CollectionReferencesRequestBuilder", "Exclude": "daysOfWeek;ignorableCollection2", "Ignore": "ignorableCollection" },
39-
40-
{ "Template": "MethodCollection", "SubProcessor": "Method", "Type": "Request", "Name": "<Class><Method>Collection", "Matches": "specialCollection" },
41-
42-
{ "Template": "EntityRequest", "SubProcessor": "ComplexType", "Type": "Request", "Name": "<Class>Request", "Matches": "navigable" },
43-
{ "Template": "EntityRequestBuilder", "SubProcessor": "ComplexType", "Type": "Request", "Name": "<Class>RequestBuilder", "Matches": "navigable" }
18+
{ "Template": "ODataEntities", "SubProcessor": "Other", "Type": "Model", "Name": "ODataEntities" }
4419
]
4520
}
4621
}

src/GraphODataTemplateWriter/CodeHelpers/ObjC/CodeWriterObjC.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public string GetImportsClass(IEnumerable<OdcmProperty> references, IEnumerable<
133133
{
134134
imports.AppendFormat("#import <UIKit/UiKit.h>").AppendLine();
135135
}
136-
else if (type.IsComplex() && !type.IsSystem() && type.GetTypeString() != "id" &&
136+
else if (!type.IsSystem() && type.IsComplex() && type.GetTypeString() != "id" &&
137137
type.GetTypeString() != classType)
138138
{
139139
classes.AppendFormat("{0}, ", type.GetTypeString());

src/GraphODataTemplateWriter/CodeHelpers/ObjC/TypeHelperObjC.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public static ICollection<string> ReservedNames
8181
"readwrite",
8282
"readonly",
8383
"inline",
84-
"operations"
84+
"operations",
85+
"Duration",
86+
"False"
87+
8588
};
8689
}
8790
return reservedNames;
@@ -107,7 +110,8 @@ public static string GetTypeString(this OdcmType type)
107110
return "NSString";
108111
case "Double":
109112
case "Float":
110-
return "CGFloat";
113+
case "Single":
114+
return "double";
111115
case "DateTimeOffset":
112116
return "NSDate";
113117
case "Date":
@@ -121,9 +125,16 @@ public static string GetTypeString(this OdcmType type)
121125
case "Stream":
122126
return "NSStream";
123127
case "Duration":
124-
return "Duration";
128+
return "MSDuration";
125129
case "NSDictionary":
126130
return "NSDictionary";
131+
case "JSON":
132+
return "NSDictionary";
133+
case "Json":
134+
return "NSDictionary";
135+
case "Byte":
136+
return "Byte";
137+
127138
default:
128139
return Prefix + type.Name.ToUpperFirstChar();
129140
}
@@ -138,7 +149,7 @@ public static bool IsComplex(this OdcmType type)
138149
{
139150
string t = GetTypeString(type);
140151
return
141-
!(t == "int32_t" || t == "int64_t" || t == "int16_t" || t == "BOOL" || t == "Byte" || t == "CGFloat");
152+
!(t == "int32_t" || t == "int64_t" || t == "int16_t" || t == "BOOL" || t == "Byte" || t == "double");
142153
}
143154

144155
public static bool IsComplex(this OdcmProperty property)
@@ -194,7 +205,7 @@ public static bool IsSystem(this OdcmProperty property)
194205
public static bool IsSystem(this OdcmType type)
195206
{
196207
string t = GetTypeString(type);
197-
return (t.Contains("int") || t == "BOOL" || t == "Byte" || t == "NSString" || t == "NSDate" || t == "NSStream" || t == "CGFloat");
208+
return (t == "int32_t" || t == "int64_t" || t == "int16_t" || t == "BOOL" || t == "Byte" || t == "NSString" || t == "NSDate" || t == "NSStream" || t == "double");
198209
}
199210

200211
public static bool IsComplexCollectionOpenType(this OdcmProperty property, OdcmModel model)
@@ -250,7 +261,7 @@ public static string GetNSNumberValueMethod(this OdcmType type)
250261
{
251262
return "boolValue";
252263
}
253-
else if (objectiveCType.Equals("CGFloat"))
264+
else if (objectiveCType.Equals("double"))
254265
{
255266
return "floatValue";
256267
}

0 commit comments

Comments
 (0)