Skip to content

Commit cb95148

Browse files
committed
Generating path list
1 parent 8f81f91 commit cb95148

File tree

8 files changed

+316
-5
lines changed

8 files changed

+316
-5
lines changed

GraphODataTemplateWriter.sln

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25123.0
4+
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{6ACF6CEE-A594-4DFE-9286-C7154E91738B}"
77
ProjectSection(SolutionItems) = preProject
@@ -17,15 +17,25 @@ EndProject
1717
Global
1818
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1919
Debug|Any CPU = Debug|Any CPU
20+
Debug|x86 = Debug|x86
2021
Release|Any CPU = Release|Any CPU
22+
Release|x86 = Release|x86
2123
EndGlobalSection
2224
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2325
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2426
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Debug|x86.ActiveCfg = Debug|x86
28+
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Debug|x86.Build.0 = Debug|x86
2529
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
2630
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Release|x86.ActiveCfg = Release|x86
32+
{E6B5202F-4F66-428A-AB92-0AAA11BA81DE}.Release|x86.Build.0 = Release|x86
2733
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Debug|x86.ActiveCfg = Debug|Any CPU
35+
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Debug|x86.Build.0 = Debug|Any CPU
2836
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Release|x86.ActiveCfg = Release|Any CPU
38+
{5F526973-F69E-4C26-B8AD-612590A17A9E}.Release|x86.Build.0 = Release|Any CPU
2939
EndGlobalSection
3040
GlobalSection(SolutionProperties) = preSolution
3141
HideSolutionNode = FALSE

Templates/Templates.csproj

Lines changed: 212 additions & 1 deletion
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
CodeWriterTypeScript writer = (CodeWriterTypeScript) host.CodeWriter;
7+
8+
var model = host.CurrentModel;
9+
var entityTypes = model.GetEntityTypes();
10+
var complexTypes = model.GetComplexTypes();
11+
var entitySet = model.EntityContainer.Properties;
12+
#>
13+
<# foreach(var es in entitySet) { #>
14+
<# foreach (var path in es.GetNavigationPaths("", entityTypes, 0)) { #>
15+
<#= path #>
16+
<# } #>
17+
18+
19+
<# } #>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"TemplateMapping": {
33
"TypeScript": [
4-
{ "Template": "entity_types", "SubProcessor": "Other", "Name": "entity_types" }
4+
{ "Template": "entity_types", "SubProcessor": "Other", "Name": "entity_types" },
5+
{ "Template": "path_list", "SubProcessor": "Other", "Name": "path_list" }
56
]
67
}
78
}

src/GraphODataTemplateWriter/CodeHelpers/CSharp/CodeWriterCSharp.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.CSharp
44
{
55
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
68
using Vipr.Core.CodeModel;
79

810
public class CodeWriterCSharp : CodeWriterBase
@@ -25,5 +27,11 @@ public override string WriteInlineCommentChar()
2527
}
2628

2729
public string jsonContentType = "application/json";
30+
31+
32+
public static string GetPaths(OdcmProperty prop)
33+
{
34+
return "entities.First().Name";
35+
}
2836
}
2937
}

src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeHelperTypeScript.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.TypeScript
44
{
55
using Vipr.Core.CodeModel;
66
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
79

810
public static class TypeHelperTypeScript
911
{
@@ -24,7 +26,8 @@ public static String GetEnumValues(this OdcmEnum _enum) {
2426

2527
return enumVals;
2628
}
27-
29+
30+
2831
public static string GetTypeString(this OdcmProperty prop)
2932
{
3033
string typeStr = UpperCaseFirstChar(prop.Type.Name);
@@ -62,6 +65,47 @@ public static String UpperCaseFirstChar(String s)
6265
{
6366
return char.ToUpper(s[0]) + s.Substring(1);
6467
}
68+
69+
public static OdcmClass FindEntityByName(this IEnumerable<OdcmClass> entities, String name)
70+
{
71+
foreach (var entity in entities)
72+
{
73+
if (entity.Name.Equals(name))
74+
{
75+
return entity;
76+
}
77+
}
78+
return null;
79+
}
80+
81+
public static List<string> GetNavigationPaths(this OdcmProperty prop, string baseString, IEnumerable<OdcmClass> entities, int depth)
82+
{
83+
List<String> paths = new List<string>();
84+
if (depth > 5) return paths;
85+
OdcmClass entity = entities.FindEntityByName(prop.Type.Name);
86+
87+
string newBase;
88+
if (prop.IsCollection)
89+
{
90+
newBase = baseString + "/" + prop.Name + "/{" + prop.Type.Name + "Id}";
91+
paths.Add(baseString + "/" + prop.Name);
92+
}
93+
else
94+
{
95+
newBase = baseString + "/" + prop.Name;
96+
97+
}
98+
paths.Add(newBase);
99+
100+
foreach (var eprop in entity.Properties)
101+
{
102+
if (eprop.IsLink)
103+
{
104+
paths.AddRange(GetNavigationPaths(eprop, newBase, entities, depth + 1));
105+
}
106+
}
107+
return paths;
108+
}
65109

66110
}
67111
}

src/GraphODataTemplateWriter/GraphODataTemplateWriter.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@
3131
<ErrorReport>prompt</ErrorReport>
3232
<WarningLevel>4</WarningLevel>
3333
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
35+
<DebugSymbols>true</DebugSymbols>
36+
<OutputPath>bin\x86\Debug\</OutputPath>
37+
<DefineConstants>DEBUG;TRACE</DefineConstants>
38+
<DebugType>full</DebugType>
39+
<PlatformTarget>x86</PlatformTarget>
40+
<ErrorReport>prompt</ErrorReport>
41+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
44+
<OutputPath>bin\x86\Release\</OutputPath>
45+
<DefineConstants>TRACE</DefineConstants>
46+
<Optimize>true</Optimize>
47+
<DebugType>pdbonly</DebugType>
48+
<PlatformTarget>x86</PlatformTarget>
49+
<ErrorReport>prompt</ErrorReport>
50+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
51+
</PropertyGroup>
3452
<ItemGroup>
3553
<Reference Include="Inflector">
3654
<HintPath>..\..\packages\Inflector.1.0.0.0\lib\net45\Inflector.dll</HintPath>

0 commit comments

Comments
 (0)