Skip to content

Commit b8e13c6

Browse files
committed
Merge branch 'master' of https://github.com/microsoftgraph/MSGraph-SDK-Code-Generator into typescript
2 parents 5621cbf + 331c1dd commit b8e13c6

File tree

11 files changed

+4071
-51
lines changed

11 files changed

+4071
-51
lines changed

README.md

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

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

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

3938
1. Build the solution in Visual Studio.
40-
2. Go to the `src\T4TemplateWriter\bin\debug` folder to find all compiled components.
39+
2. Go to the `src\GraphODataTemplateWriter\bin\debug` folder to find all compiled components.
4140
3. In that folder, modify `.config\TemplateWriterSettings.json` to specify your template mapping see [Template Writer Settings](##Template-Writer-Settings) for more details.
42-
4. Open a command prompt as administrator in the same folder and run `Vipr.exe <path-or-url-to-metadata> --writer="GraphODataTemplateWriter"`
41+
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.
4342

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

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/CSharp/Base/EntityRequest.Base.template.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public string GetEntityCreateAsyncMethod(OdcmClass odcmClass)
156156
stringBuilder.Append(Environment.NewLine);
157157
stringBuilder.AppendFormat(" this.ContentType = \"{0}\";", templateWriter.jsonContentType);
158158
stringBuilder.Append(Environment.NewLine);
159-
stringBuilder.Append(" this.Method = \"PUT\";");
159+
stringBuilder.Append(" this.Method = \"POST\";");
160160
stringBuilder.Append(Environment.NewLine);
161161
stringBuilder.AppendFormat(" var newEntity = await this.SendAsync<{0}>({1}ToCreate, cancellationToken).ConfigureAwait(false);", entityName, lowerCaseEntityName);
162162
stringBuilder.Append(Environment.NewLine);

Templates/ObjC/Base/SharedObjC.template.tt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ private string GetObjCTypeIdentifier(OdcmObject o, bool getUnderlyingType=false)
2727
if(o is OdcmProperty)
2828
{
2929
OdcmProperty prop=(OdcmProperty)o;
30+
3031
if(prop.IsCollection && !getUnderlyingType)
3132
{
3233
return @"NSArray";
3334
}
3435

36+
if (prop.IsComplexCollectionOpenType(model) && !getUnderlyingType)
37+
{
38+
return @"NSDictionary";
39+
}
40+
3541
return GetObjCTypeIdentifier(prop.Projection.Type,getUnderlyingType);
3642
}
3743
else if(o is OdcmType)
@@ -136,6 +142,17 @@ private string GetJsonToObjCExpressionConversion(string expr,OdcmProperty prop)
136142
type.GetNSNumberValueMethod());
137143
}
138144

145+
private string GetObjCTypeIdentifierCollection(OdcmProperty prop)
146+
{
147+
var propName = GetObjCTypeIdentifier(prop,true);
148+
if (prop.IsComplexCollectionOpenType(model))
149+
{
150+
propName = propName.RemoveFromEnd("Collection");
151+
}
152+
153+
return propName;
154+
}
155+
139156
private string GetHydratedPropertyFromDictionary(OdcmProperty prop)
140157
{
141158
return GetJsonToObjCExpressionConversion(String.Format(@"self.dictionary[@""{0}""]",prop.Name),prop);
@@ -198,8 +215,39 @@ private string GetHydratedIVarFromDictionary(OdcmProperty prop)
198215
GetJsonToObjCExpressionConversion(prop.Projection.Type.Name.ToLowerFirstChar(), prop));
199216
}
200217

218+
if(prop.IsComplexCollectionOpenType(model))
219+
{
220+
return String.Format(@"
221+
NSMutableDictionary *{0}Result = [[NSMutableDictionary alloc] init];
222+
NSDictionary *{0} = self.dictionary[@""{1}""];
223+
224+
if ([{0} isKindOfClass:[NSDictionary class]]){{
225+
[{0} enumerateKeysAndObjectsUsingBlock:^(NSString* key, id value, BOOL* stop){{
226+
[{0}Result setValue:{3} forKey:key];
227+
}}];
228+
}}
229+
230+
_{0} = {0}Result;
231+
",
232+
GetObjCProperty(prop),
233+
prop.Name,
234+
prop.Projection.Type.Name.ToLowerFirstChar().RemoveFromEnd("Collection"),
235+
GetJsonToObjCExpressionConversionOpenType(prop));
236+
}
237+
201238
return String.Format(@"_{0} = {1};",GetObjCProperty(prop),GetHydratedPropertyFromDictionary(prop));
239+
}
240+
241+
private string GetJsonToObjCExpressionConversionOpenType(OdcmProperty prop)
242+
{
243+
string objCIdentifierType = GetObjCTypeIdentifierCollection(prop);
244+
245+
if(model.GetComplexTypes().Any(complexType => objCIdentifierType.Equals(writer.GetPrefix() + complexType.Name.ToUpperFirstChar())))
246+
{
247+
return String.Format("[[{0} alloc] initWithDictionary:value]", objCIdentifierType);
248+
}
202249

250+
return "value";
203251
}
204252

205253
public string GetFunctionParameterDictionary(List<OdcmParameter> parameters)

Templates/ObjC/Models/EntityType.h.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if (baseEntity == null)
1818
{
1919
#>
2020
@property (nullable, nonatomic, setter=setODataType:, getter=oDataType) NSString *oDataType;
21+
@property (nullable, nonatomic, setter=setODataEtag:, getter=oDataEtag) NSString *oDataEtag;
2122
<#
2223
}
2324

Templates/ObjC/Models/EntityType.m.tt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ if (entity.Base == null)
5757
{
5858
self.dictionary[@"@odata.type"] = val;
5959
}
60+
- (NSString*) oDataEtag
61+
{
62+
return self.dictionary[@"@odata.etag"];
63+
}
64+
- (void) setODataEtag: (NSString*) val
65+
{
66+
self.dictionary[@"@odata.etag"] = val;
67+
}
6068
<#
6169
}
6270

0 commit comments

Comments
 (0)