Skip to content

Commit 238cf05

Browse files
committed
merged master into typescript
2 parents 0baf0e4 + 28753a8 commit 238cf05

File tree

7 files changed

+184
-1
lines changed

7 files changed

+184
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<# // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. #>
2+
<#@ template debug="true" hostspecific="true" language="C#" #>
3+
<#@ output extension="\\" #>
4+
<#
5+
CustomT4Host host = (CustomT4Host) Host;
6+
CodeWriterGraphEndpointList writer = (CodeWriterGraphEndpointList) host.CodeWriter;
7+
8+
var model = host.CurrentModel;
9+
var entityTypes = model.GetEntityTypes();
10+
var entitySet = model.EntityContainer.Properties;
11+
#>
12+
<# foreach(var entity in entitySet) { #>
13+
<# foreach (var path in entity.GetNavigationPaths("", entityTypes, 0)) { #>
14+
<#= path #>
15+
<# } #>
16+
17+
18+
<# } #>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"TemplateMapping": {
3+
"GraphEndpointList": [
4+
{ "Template": "graph_endpoint_list", "SubProcessor": "Other", "Name": "graph_endpoint_list" }
5+
]
6+
}
7+
}

src/GraphODataTemplateWriter/.config/TemplateWriterSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"AvailableLanguages": [ "Android", "ObjC", "CSharp", "Python", "JavaScript", "TypeScript" ],
2+
"AvailableLanguages": [ "Android", "ObjC", "CSharp", "Python", "JavaScript", "TypeScript", "GraphEndpointList" ],
33
"TargetLanguage": "TypeScript",
44
"Plugins": [ ],
55
"PrimaryNamespaceName": "com",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
2+
3+
namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.GraphEndpointList
4+
{
5+
using System;
6+
using Vipr.Core.CodeModel;
7+
8+
public class CodeWriterGraphEndpointList : CodeWriterBase
9+
{
10+
public CodeWriterGraphEndpointList() : base() { }
11+
12+
public CodeWriterGraphEndpointList(OdcmModel model) : base(model) { }
13+
14+
public override string WriteClosingCommentLine()
15+
{
16+
throw new NotImplementedException();
17+
}
18+
19+
public override string WriteInlineCommentChar()
20+
{
21+
throw new NotImplementedException();
22+
}
23+
24+
public override string WriteOpeningCommentLine()
25+
{
26+
throw new NotImplementedException();
27+
}
28+
}
29+
30+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
2+
3+
namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.GraphEndpointList
4+
{
5+
using Vipr.Core.CodeModel;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
10+
public static class TypeHelperGraphEndpointList
11+
{
12+
13+
public static OdcmClass FindEntityByName(this IEnumerable<OdcmClass> entities, String name)
14+
{
15+
foreach (var entity in entities)
16+
{
17+
if (entity.Name.Equals(name))
18+
{
19+
return entity;
20+
}
21+
}
22+
return null;
23+
}
24+
25+
public static List<string> GetNavigationPaths(this OdcmProperty prop, string baseString, IEnumerable<OdcmClass> entities, int depth)
26+
{
27+
List<String> paths = new List<string>();
28+
if (depth > 5) return paths;
29+
OdcmClass entity = entities.FindEntityByName(prop.Type.Name);
30+
31+
string newBase;
32+
if (prop.IsCollection)
33+
{
34+
newBase = baseString + "/" + prop.Name + "/{" + prop.Type.Name + "Id}";
35+
paths.Add(baseString + "/" + prop.Name);
36+
}
37+
else
38+
{
39+
newBase = baseString + "/" + prop.Name;
40+
41+
}
42+
43+
paths.Add(newBase);
44+
if (entity.Methods.Any()) // check for actions
45+
{
46+
foreach (var method in entity.Methods)
47+
{
48+
paths.Add(newBase + "/" + method.Name);
49+
}
50+
}
51+
52+
foreach (var eprop in entity.Properties)
53+
{
54+
if (eprop.IsLink)
55+
{
56+
paths.AddRange(GetNavigationPaths(eprop, newBase, entities, depth + 1));
57+
}
58+
}
59+
60+
61+
return paths;
62+
}
63+
64+
}
65+
66+
}

src/GraphODataTemplateWriter/GraphODataTemplateWriter.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
<Compile Include="CodeHelpers\Android\CodeWriterAndroid.cs" />
7676
<Compile Include="CodeHelpers\TypeScript\CodeWriterTypeScript.cs" />
7777
<Compile Include="CodeHelpers\TypeScript\TypeHelperTypeScript.cs" />
78+
<Compile Include="CodeHelpers\GraphEndpointList\CodeWriterGraphEndpointList.cs" />
79+
<Compile Include="CodeHelpers\GraphEndpointList\TypeHelperGraphEndpointList.cs" />
7880
<Compile Include="CodeHelpers\JavaScript\CodeWriterJavaScript.cs" />
7981
<Compile Include="CodeHelpers\JavaScript\TypeHelperJavaScript.cs" />
8082
<Compile Include="CodeHelpers\ObjC\CodeWriterObjC.cs" />
@@ -83,6 +85,7 @@
8385
<Compile Include="Extensions\FeatureExtensions.cs" />
8486
<Compile Include="PathWriters\CSharpPathWriter.cs" />
8587
<Compile Include="PathWriters\TypeScriptPathWriter.cs" />
88+
<Compile Include="PathWriters\GraphEndpointListPathWriter.cs" />
8689
<Compile Include="PathWriters\JavaScriptPathWriter.cs" />
8790
<Compile Include="PathWriters\PythonPathWriter.cs" />
8891
<Compile Include="TemplateProcessor\CustomT4Host.cs" />
@@ -113,7 +116,11 @@
113116
<None Include=".config\CSharpSettings.json">
114117
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
115118
</None>
119+
<<<<<<< HEAD
116120
<None Include=".config\TypeScriptSettings.json">
121+
=======
122+
<None Include=".config\GraphEndpointListSettings.json">
123+
>>>>>>> master
117124
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
118125
</None>
119126
<None Include=".config\JavaScriptSettings.json">
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
2+
3+
namespace Microsoft.Graph.ODataTemplateWriter.PathWriters
4+
{
5+
using System;
6+
using System.IO;
7+
using System.Linq;
8+
using Microsoft.Graph.ODataTemplateWriter.Extensions;
9+
using Microsoft.Graph.ODataTemplateWriter.Settings;
10+
using Microsoft.Graph.ODataTemplateWriter.TemplateProcessor;
11+
12+
public class GraphEndpointListPathWriter : PathWriterBase
13+
{
14+
15+
public override string WritePath(ITemplateInfo template, String baseFileName)
16+
{
17+
var theNamespace = this.CreateNamespace(template.OutputParentDirectory.ToLower());
18+
var namespacePath = this.CreatePathFromNamespace(theNamespace);
19+
var fileName = this.TransformFileName(template, baseFileName);
20+
String filePath = Path.Combine(namespacePath, fileName);
21+
return filePath;
22+
}
23+
24+
private string CreateNamespace(string folderName)
25+
{
26+
var @namespace = this.Model.GetNamespace();
27+
var prefix = ConfigurationService.Settings.NamespacePrefix;
28+
29+
if (String.IsNullOrEmpty(ConfigurationService.Settings.NamespaceOverride))
30+
{
31+
if (string.IsNullOrEmpty(folderName))
32+
{
33+
return string.IsNullOrEmpty(prefix) ? @namespace
34+
: string.Format("{0}.{1}", prefix, @namespace);
35+
}
36+
37+
return string.IsNullOrEmpty(prefix) ? string.Format("{0}.{1}", @namespace, folderName)
38+
: string.Format("{0}.{1}.{2}", prefix, @namespace, folderName);
39+
}
40+
41+
@namespace = ConfigurationService.Settings.NamespaceOverride;
42+
return folderName != null ? string.Format("{0}.{1}", @namespace, folderName)
43+
: @namespace;
44+
}
45+
46+
private string CreatePathFromNamespace(string @namespace)
47+
{
48+
var splittedPaths = @namespace.Split('.');
49+
50+
var destinationPath = splittedPaths.Aggregate(string.Empty, (current, path) =>
51+
current + string.Format("{0}{1}", path, Path.DirectorySeparatorChar));
52+
return destinationPath;
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)