diff --git a/Templates/TypeScript/src/entity_types.ts.tt b/Templates/TypeScript/src/entity_types.ts.tt index c6d8a4863..ec240ef2b 100644 --- a/Templates/TypeScript/src/entity_types.ts.tt +++ b/Templates/TypeScript/src/entity_types.ts.tt @@ -23,12 +23,9 @@ export as namespace microsoftgraph; export type NullableOption = T | null; <#=typeScriptNamespaces.MainNamespace.ToString()#> - <# foreach (var subNamespace in typeScriptNamespaces.SubNamespaces) { -#> -<#=subNamespace.Value.ToString()#> -<# +#><#=subNamespace.Value.ToString()#><# } -#> +#> \ No newline at end of file diff --git a/src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeScriptNamespace.cs b/src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeScriptNamespace.cs index ebc6569fa..eac417d87 100644 --- a/src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeScriptNamespace.cs +++ b/src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeScriptNamespace.cs @@ -111,16 +111,17 @@ public override string ToString() /// enum private void AddEnum(OdcmEnum enumType) { + var export = IsMainNamespace ? "export " : string.Empty; var enumTypeName = enumType.Name.UpperCaseFirstChar(); var enumValues = enumType.GetEnumValues(); - var exportTypeLength = "export type".Length + enumTypeName.Length + enumValues.Length + 3; + var exportTypeLength = (export + "type").Length + enumTypeName.Length + enumValues.Length + 3; if (exportTypeLength < MaxLineLength) { - sb.AppendLine($"{NamespaceIndent}export type {enumTypeName} = {enumValues};"); + sb.AppendLine($"{NamespaceIndent}{export}type {enumTypeName} = {enumValues};"); } else { - sb.AppendLine($"{NamespaceIndent}export type {enumTypeName} ="); + sb.AppendLine($"{NamespaceIndent}{export}type {enumTypeName} ="); var enums = enumValues.Split('|'); sb.Append($"{NamespaceIndent}{TabSpace}| "); sb.Append(string.Join(Environment.NewLine + NamespaceIndent + TabSpace + "| ", enums.Select(@enum => @enum.Trim()))); @@ -141,6 +142,7 @@ private void AddEnum(OdcmEnum enumType) /// entity or complex type private void AddEntityOrComplexType(OdcmClass @class) { + var export = IsMainNamespace ? "export " : string.Empty; var propCount = @class.Properties.Count; var entityTypeName = @class.Name.UpperCaseFirstChar(); if (propCount == 0 && entityTypeName[0] == 'I') @@ -159,7 +161,7 @@ private void AddEntityOrComplexType(OdcmClass @class) var extendsStatement = @class.Base == null ? string.Empty : $" extends {GetFullyQualifiedTypeScriptTypeName(@class.Base.GetTypeString(), @class.Base.Namespace.GetNamespaceName())}"; - var exportInterfaceLine = NamespaceIndent + "export interface " + entityTypeName + extendsStatement + " {"; + var exportInterfaceLine = NamespaceIndent + $"{export}interface " + entityTypeName + extendsStatement + " {"; if (propCount == 0) { sb.AppendLine(exportInterfaceLine + "}"); diff --git a/test/Typewriter.Test/TestDataTypeScript/com/microsoft/graph/src/Microsoft-graph.d.ts b/test/Typewriter.Test/TestDataTypeScript/com/microsoft/graph/src/Microsoft-graph.d.ts index 07a25aa13..2d6f0d066 100644 --- a/test/Typewriter.Test/TestDataTypeScript/com/microsoft/graph/src/Microsoft-graph.d.ts +++ b/test/Typewriter.Test/TestDataTypeScript/com/microsoft/graph/src/Microsoft-graph.d.ts @@ -90,23 +90,22 @@ export interface IdentitySet { user?: NullableOption; } - export namespace CallRecords { - export type CallType = "unknown" | "groupCall"; - export type ClientPlatform = "unknown" | "windows"; - export type FailureStage = "unknown" | "callSetup"; - export type MediaStreamDirection = "callerToCallee" | "calleeToCaller"; - export type NetworkConnectionType = "unknown" | "wired"; - export type ProductFamily = "unknown" | "teams"; - export type ServiceRole = "unknown" | "customBot"; - export type UserFeedbackRating = "notRated" | "bad"; - export type WifiBand = "unknown" | "frequency24GHz"; - export type WifiRadioType = "unknown" | "wifi80211a"; - export type Modality = "audio" | "video"; - export interface SingletonEntity1 extends microsoftgraph.Entity { + type CallType = "unknown" | "groupCall"; + type ClientPlatform = "unknown" | "windows"; + type FailureStage = "unknown" | "callSetup"; + type MediaStreamDirection = "callerToCallee" | "calleeToCaller"; + type NetworkConnectionType = "unknown" | "wired"; + type ProductFamily = "unknown" | "teams"; + type ServiceRole = "unknown" | "customBot"; + type UserFeedbackRating = "notRated" | "bad"; + type WifiBand = "unknown" | "frequency24GHz"; + type WifiRadioType = "unknown" | "wifi80211a"; + type Modality = "audio" | "video"; + interface SingletonEntity1 extends microsoftgraph.Entity { testSingleNav?: NullableOption; } - export interface CallRecord extends microsoftgraph.Entity { + interface CallRecord extends microsoftgraph.Entity { version?: number; type?: CallType; modalities?: Modality[]; @@ -119,7 +118,7 @@ export namespace CallRecords { sessions?: NullableOption; recipients?: NullableOption; } - export interface Session extends microsoftgraph.Entity { + interface Session extends microsoftgraph.Entity { modalities?: Modality[]; startDateTime?: string; endDateTime?: string; @@ -128,7 +127,7 @@ export namespace CallRecords { failureInfo?: NullableOption; segments?: NullableOption; } - export interface Segment extends microsoftgraph.Entity { + interface Segment extends microsoftgraph.Entity { startDateTime?: string; endDateTime?: string; caller?: NullableOption; @@ -141,29 +140,29 @@ export namespace CallRecords { photo?: NullableOption; } // tslint:disable-next-line: no-empty-interface - export interface Option extends microsoftgraph.Entity {} - export interface Photo extends microsoftgraph.Entity { + interface Option extends microsoftgraph.Entity {} + interface Photo extends microsoftgraph.Entity { failureInfo?: NullableOption; option?: NullableOption