Skip to content

Commit 6a32c84

Browse files
committed
Merge branch 'master' of https://github.com/dianambb/MSGraph-SDK-Code-Generator into AddEtagProperty
2 parents 8852eec + b2dd0fc commit 6a32c84

16 files changed

+1060
-55
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ Currently the following target languages are supported by this writer:
1212
- Python
1313

1414
# Contents
15-
- [Prerequisites](#Prerequisites)
16-
- [Getting started](#Getting-started)
17-
- [Using Vipr with this writer](#Using-Vipr-with-this-Writer)
18-
- [Using generated code](#Using-generated-code)
19-
- [Contributing](#Contributing)
20-
- [License](#License)
15+
- [Prerequisites](#prerequisites)
16+
- [Getting started](#getting-started)
17+
- [Using Vipr with this writer](#using-vipr-with-this-writer)
18+
- [Contributing](#contributing)
19+
- [License](#license)
2120

2221
## Prerequisites
2322
- [Visual Studio SDK](https://www.microsoft.com/en-us/download/details.aspx?id=40758)
@@ -36,9 +35,9 @@ For more information on submodules read [this chapter](http://git-scm.com/book/e
3635
## Using Vipr with this Writer
3736

3837
1. Build the solution in Visual Studio.
39-
2. Go to the `src\T4TemplateWriter\bin\debug` folder to find all compiled components.
38+
2. Go to the `src\GraphODataTemplateWriter\bin\debug` folder to find all compiled components.
4039
3. In that folder, modify `.config\TemplateWriterSettings.json` to specify your template mapping see [Template Writer Settings](##Template-Writer-Settings) for more details.
41-
4. Open a command prompt as administrator in the same folder and run `Vipr.exe <path-or-url-to-metadata> --writer="GraphODataTemplateWriter"`
40+
4. Open a command prompt as administrator in the same folder and run `Vipr.exe <path-or-url-to-metadata> --writer="GraphODataTemplateWriter"`. An example metadata file can be found in the root of this project.
4241

4342
By default, output source code will be put in a folder named "output" next to the Vipr executable.
4443

Templates/Android/BaseModel.template.tt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,15 @@
473473
return null;
474474
}
475475

476+
public string OdcmMethodReturnType(OdcmMethod method) {
477+
return method.ReturnType is OdcmPrimitiveType
478+
? method.ReturnType.GetTypeString() : method.ReturnType.Name.ToCheckedCase();
479+
}
480+
476481
public string CollectionPageGeneric(OdcmObject c) {
477482
if (c is OdcmMethod) {
478-
return "<" + ClassTypeName(c) + ", " + ITypeCollectionRequestBuilder(c) + ">";
483+
string returnType = OdcmMethodReturnType(c as OdcmMethod);
484+
return "<" + returnType + ", " + ITypeCollectionRequestBuilder(c) + ">";
479485
}
480486
return "<" + TypeName(c) + ", " + ITypeCollectionRequestBuilder(c) + ">";
481487
}

Templates/Android/generated/BaseMethodCollectionResponse.java.tt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ import com.google.gson.annotations.*;
1313
<#=CreateClassDef(BaseTypeCollectionResponse(c), null, "IJsonBackedObject")#>
1414

1515
@SerializedName("value")
16-
public List<<#=ClassTypeName(c)#>> value;
16+
public List<<#=OdcmMethodReturnType(c as OdcmMethod)#>> value;
1717

1818
@SerializedName("@odata.nextLink")
1919
public String nextLink;
2020

2121
<#=CreateRawJsonObject()#>
22-
<#=UpdateListPropertiesWithinSetRawObject(new [] { "value" })#>
22+
<# if ( ! ((c as OdcmMethod).ReturnType is OdcmPrimitiveType) ) { #>
23+
<#= UpdateListPropertiesWithinSetRawObject(new [] { "value" })#>
24+
<# } else { #>
25+
}
26+
<# } #>
2327
}

Templates/ObjC/Base/SharedObjC.template.tt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ private string GetJsonToObjCExpressionConversion(string expr,OdcmProperty prop)
105105
expr);
106106
}
107107

108+
if(GetObjCTypeIdentifier(prop,true)=="MSTimeOfDay")
109+
{
110+
return String.Format(@"[{0} ms_timeFromString: {1}]",
111+
GetObjCTypeIdentifier(prop,true),
112+
expr);
113+
}
114+
108115
if(prop.IsEnum())
109116
{
110117
return String.Format(
@@ -241,7 +248,21 @@ private string GetStaticBaseObject()
241248

242249
private string GeneratePropertyDeclarationLine(OdcmProperty prop)
243250
{
244-
return "@property (nonatomic, setter=" + GetObjCPropertySetter(prop) + ":, getter=" + GetObjCPropertyGetter(prop) + ") " + GetObjCTypeForVarDeclaration(prop) + " " + GetObjCProperty(prop) + ";";
251+
if(prop.IsCollection || prop.IsComplex())
252+
{
253+
if(prop.IsNullable==true)
254+
{
255+
return "@property (nullable, nonatomic, setter=" + GetObjCPropertySetter(prop) + ":, getter=" + GetObjCPropertyGetter(prop) + ") " + GetObjCTypeForVarDeclaration(prop) + " " + GetObjCProperty(prop) + ";";
256+
}
257+
else
258+
{
259+
return "@property (nonnull, nonatomic, setter=" + GetObjCPropertySetter(prop) + ":, getter=" + GetObjCPropertyGetter(prop) + ") " + GetObjCTypeForVarDeclaration(prop) + " " + GetObjCProperty(prop) + ";";
260+
}
261+
}
262+
else
263+
{
264+
return "@property (nonatomic, setter=" + GetObjCPropertySetter(prop) + ":, getter=" + GetObjCPropertyGetter(prop) + ") " + GetObjCTypeForVarDeclaration(prop) + " " + GetObjCProperty(prop) + ";";
265+
}
245266
}
246267

247268
private void PropertyGetterImplementation(OdcmProperty prop)
@@ -252,6 +273,17 @@ private void PropertyGetterImplementation(OdcmProperty prop)
252273
<#+
253274
if(IsObjCTypeSameAsJsonType(prop.Projection.Type))
254275
{
276+
#>
277+
<#+
278+
if(prop.IsNullable==true)
279+
{
280+
#>
281+
if([[NSNull null] isEqual:self.dictionary[@"<#=prop.Name#>"]])
282+
{
283+
return nil;
284+
}
285+
<#+
286+
}
255287
#>
256288
return self.dictionary[@"<#=prop.Name#>"];
257289
<#+
@@ -280,6 +312,7 @@ private void PropertyGetterImplementation(OdcmProperty prop)
280312
}
281313
#>
282314
}
315+
283316
<#+
284317
}
285318

@@ -304,6 +337,7 @@ private void PropertySetterImplementation(OdcmProperty prop)
304337
}
305338
#>
306339
}
340+
307341
<#+
308342
}
309343
#>

Templates/ObjC/Models/ComplexType.h.tt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ var baseEntity = entity.Base;
1515
<#
1616
foreach(var prop in entity.Properties.Where(prop => GetObjCTypeIdentifier(prop)!="NSStream" ))
1717
{
18-
#>
19-
<#=GeneratePropertyDeclarationLine(prop)#>
20-
<#
18+
#>
19+
<#=GeneratePropertyDeclarationLine(prop)#>
20+
<#
2121
}
2222

2323
#>

Templates/ObjC/Models/EntityType.h.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ IEnumerable<string> extraClasses = null;
1717
if (baseEntity == null)
1818
{
1919
#>
20-
@property (nonatomic, setter=setODataType:, getter=oDataType) NSString *oDataType;
21-
@property (nonatomic, setter=setODataEtag:, getter=oDataEtag) NSString *oDataEtag;
20+
@property (nullable, nonatomic, setter=setODataType:, getter=oDataType) NSString *oDataType;
21+
@property (nullable, nonatomic, setter=setODataEtag:, getter=oDataEtag) NSString *oDataEtag;
2222
<#
2323
}
2424

Templates/ObjC/Models/EnumType.m.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ foreach (var member in entity.Members.OrderBy(x => x.Value))
6363
{
6464
#>
6565
case <#=GetObjCEnumMember(entity,member)#>:
66-
return [<#=typeName#> <#=member.Name#>];
66+
return [<#=typeName#> <#=member.Name.ToLowerFirstChar()#>];
6767
<#
6868
}
6969
#>
@@ -111,7 +111,7 @@ foreach (var member in entity.Members.OrderBy(x => x.Value))
111111
{
112112
#>if([self isEqualToString:@"<#=member.Name#>"])
113113
{
114-
return [<#=typeName#> <#=member.Name#>];
114+
return [<#=typeName#> <#=member.Name.ToLowerFirstChar()#>];
115115
}
116116
else <#
117117
}

Templates/ObjC/Models/Models.h.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<#@ include file="SharedObjC.template.tt"#>
44

55
#import "MSDate.h"
6+
#import "MSTimeOfDay.h"
67
<#
78
var enums = model.GetEnumTypes();
89
foreach(var e in enums)

Templates/ObjC/Requests/EntityCollectionRequest.m.tt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if (innerEntityType.Equals(propName))
4848
- (<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *)getWithCompletion:(<#=propName+ collectionNamer#>CompletionHandler)completionHandler
4949
{
5050

51-
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask * task = [self collectionTaskWithRequest:[self get]
51+
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask * sessionDataTask = [self collectionTaskWithRequest:[self get]
5252
odObjectWithDictionary:^(id response){
5353
<#
5454
if (prop.IsSystem())
@@ -74,8 +74,8 @@ if (innerEntityType.Equals(propName))
7474
completionHandler(collectionResponse, nil, error);
7575
}
7676
}];
77-
[task execute];
78-
return task;
77+
[sessionDataTask execute];
78+
return sessionDataTask;
7979
}
8080

8181
<#
@@ -117,13 +117,13 @@ if (innerEntityType.Equals(propName))
117117

118118
- (<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *)add<#=innerEntity.Name.ToUpperFirstChar()#>:(<#=innerEntityType#>*)<#=innerEntity.Name.ToLowerFirstChar()#> withCompletion:(<#=innerEntityType#>CompletionHandler)completionHandler
119119
{
120-
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *task = [self taskWithRequest:[self add<#=innerEntity.Name.ToUpperFirstChar()#>:<#=innerEntity.Name.ToLowerFirstChar()#>]
120+
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *sessionDataTask = [self taskWithRequest:[self add<#=innerEntity.Name.ToUpperFirstChar()#>:<#=innerEntity.Name.ToLowerFirstChar()#>]
121121
odObjectWithDictionary:^(NSDictionary *response){
122122
return [[<#=innerEntityType#> alloc] initWithDictionary:response];
123123
}
124124
completion:completionHandler];
125-
[task execute];
126-
return task;
125+
[sessionDataTask execute];
126+
return sessionDataTask;
127127
}
128128

129129
<#

Templates/ObjC/Requests/EntityRequest.m.tt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ var entityName = writer.GetPrefix() + entity.Name.ToUpperFirstChar() + (withRefe
4040

4141
- (<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *)getWithCompletion:<#=writer.GetNetworkCompletionBlock(writer.GetPrefix() + entity.Name.ToUpperFirstChar(), "response")#>completionHandler
4242
{
43-
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *task = [self taskWithRequest:[self get]
43+
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *sessionDataTask = [self taskWithRequest:[self get]
4444
odObjectWithDictionary:^(NSDictionary *response){
4545
return [[<#=writer.GetPrefix() + entity.Name.ToUpperFirstChar()#> alloc] initWithDictionary:response];
4646
}
4747
completion:completionHandler];
48-
[task execute];
49-
return task;
48+
[sessionDataTask execute];
49+
return sessionDataTask;
5050
}
5151

5252
<# } #>
@@ -63,13 +63,13 @@ var entityName = writer.GetPrefix() + entity.Name.ToUpperFirstChar() + (withRefe
6363

6464
- (<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *)update:(<#=writer.GetPrefix() + entity.Name.ToUpperFirstChar()#> *)<#=entity.Name#> withCompletion:<#=writer.GetNetworkCompletionBlock(writer.GetPrefix() + entity.Name.ToUpperFirstChar(), "response")#>completionHandler
6565
{
66-
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *task = [self taskWithRequest:[self update:<#=entity.Name#>]
66+
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *sessionDataTask = [self taskWithRequest:[self update:<#=entity.Name#>]
6767
odObjectWithDictionary:^(NSDictionary *response){
6868
return [[<#=writer.GetPrefix() + entity.Name.ToUpperFirstChar()#> alloc] initWithDictionary:response];
6969
}
7070
completion:completionHandler];
71-
[task execute];
72-
return task;
71+
[sessionDataTask execute];
72+
return sessionDataTask;
7373
}
7474

7575
<# } #>
@@ -85,11 +85,11 @@ var entityName = writer.GetPrefix() + entity.Name.ToUpperFirstChar() + (withRefe
8585

8686
- (<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *)deleteWithCompletion:<#=writer.GetNetworkCompletionBlock(null, null)#>completionHandler
8787
{
88-
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *task = [self taskWithRequest:[self delete] completion:^(NSDictionary *response, NSError *error){
88+
<#=writer.GetStaticCodePrefix()#>URLSessionDataTask *sessionDataTask = [self taskWithRequest:[self delete] completion:^(NSDictionary *response, NSError *error){
8989
completionHandler(error);
9090
}];
91-
[task execute];
92-
return task;
91+
[sessionDataTask execute];
92+
return sessionDataTask;
9393
}
9494

9595
<# } #>

0 commit comments

Comments
 (0)