Skip to content

Commit 3b7945b

Browse files
committed
updates
1 parent 4ac5e00 commit 3b7945b

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

Templates/TypeScript/src/entity_types.ts.tt

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,38 @@
1111
var complexTypes = model.GetComplexTypes();
1212
#>
1313
<#= writer.WriteHeader() #>
14-
declare module MicrosoftGraph {
14+
declare namespace MicrosoftGraph {
15+
16+
<# foreach(var enumType in enumTypes) { #>
17+
type <#= writer.UpperCaseFirstChar(enumType.Name) #> = <#= enumType.GetEnumValues() #>
18+
<# } #>
1519
<#
1620
foreach(var entityType in entityTypes)
1721
{
1822
var methods = entityType.Methods;
1923
#>
2024

21-
export interface <#= writer.UpperCaseFirstChar(entityType.Name) #><# if (entityType.Base != null) { #> extends <#= writer.UpperCaseFirstChar(entityType.Base.Name) #><# }#> {
22-
<#
23-
foreach(var prop in entityType.Properties.ToList()) {
24-
#>
25-
<#= prop.Name #>?: <#= prop.GetTypeString() #>
25+
interface <#= writer.UpperCaseFirstChar(entityType.Name) #><# if (entityType.Base != null) { #> extends <#= writer.UpperCaseFirstChar(entityType.Base.Name) #><# }#> {
26+
<# foreach(var prop in entityType.Properties.ToList()) { #>
27+
<#= prop.Name #>?: <#= prop.GetTypeString() #>
2628
<# } #>
27-
}
29+
}
2830
<#
2931
}
3032
#>
31-
32-
<#
33-
foreach(var enumType in enumTypes)
34-
{
35-
#>
36-
export const enum <#= writer.UpperCaseFirstChar(enumType.Name) #> {
37-
<#
38-
foreach(var member in enumType.Members)
39-
{
40-
#>
41-
<#= member.Name #> = <#= member.Value #>,
42-
<#
43-
}
44-
#>
45-
}
46-
4733
<#
48-
}
4934
foreach(var complexType in complexTypes)
5035
{
5136
#>
52-
export interface <#= writer.UpperCaseFirstChar(complexType.Name)#> {
53-
<#
54-
foreach(var prop in complexType.Properties)
55-
{
56-
#>
37+
38+
interface <#= writer.UpperCaseFirstChar(complexType.Name)#> {
39+
<# foreach(var prop in complexType.Properties) { #>
5740
<#= prop.Name #>?: <#= prop.GetTypeString() #>
58-
<#
59-
}
60-
#>
41+
<# } #>
6142
}
43+
<# } #>
44+
}
6245

63-
<#
64-
}
65-
#>
46+
declare module "msgraph" {
47+
export = MicrosoftGraph;
6648
}

src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeHelperTypeScript.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.TypeScript
77

88
public static class TypeHelperTypeScript
99
{
10+
11+
// enum value string, ex: "low" | "normal" | "high"
12+
public static String GetEnumValues(this OdcmEnum _enum) {
13+
String enumVals = null;
14+
foreach (var member in _enum.Members)
15+
{
16+
if (enumVals == null)
17+
{
18+
enumVals = '"' + member.Name + '"';
19+
} else
20+
{
21+
enumVals += " | " + '"' + member.Name + '"';
22+
}
23+
}
24+
25+
return enumVals;
26+
}
1027

1128
public static string GetTypeString(this OdcmProperty prop)
1229
{

0 commit comments

Comments
 (0)