From fc7eea367f6d88aa23e5c94766ca64fffbb58180 Mon Sep 17 00:00:00 2001 From: Nikitha Chettiar Date: Wed, 9 Sep 2020 20:06:00 -0700 Subject: [PATCH 1/3] Reading postfix for typescript main namespace --- Templates/TypeScript/src/entity_types.ts.tt | 2 +- .../TypeScript/TypeScriptNamespace.cs | 11 +- .../MultipleNamespacesTestRunner.cs | 16 +- .../PHPMultipleNamespacesTests.cs | 2 +- .../microsoft/graph/src/Microsoft-graph.d.ts | 207 ++++++++++++++++++ .../TypeScriptMultipeNamespacesTests.cs | 8 +- test/Typewriter.Test/Typewriter.Test.csproj | 2 +- 7 files changed, 239 insertions(+), 9 deletions(-) create mode 100644 test/Typewriter.Test/TestDataTypeScriptBeta/com/microsoft/graph/src/Microsoft-graph.d.ts diff --git a/Templates/TypeScript/src/entity_types.ts.tt b/Templates/TypeScript/src/entity_types.ts.tt index ec240ef2b..2ea9aa670 100644 --- a/Templates/TypeScript/src/entity_types.ts.tt +++ b/Templates/TypeScript/src/entity_types.ts.tt @@ -18,7 +18,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 -export as namespace microsoftgraph; +export as namespace <#=typeScriptNamespaces.MainNamespace.GetMainNameSpace()#>; export type NullableOption = T | null; diff --git a/src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeScriptNamespace.cs b/src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeScriptNamespace.cs index eac417d87..c2cd52b94 100644 --- a/src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeScriptNamespace.cs +++ b/src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeScriptNamespace.cs @@ -1,4 +1,5 @@ using Microsoft.Graph.ODataTemplateWriter.CodeHelpers.CSharp; +using Microsoft.Graph.ODataTemplateWriter.Settings; using System; using System.Collections.Generic; using System.Linq; @@ -35,9 +36,17 @@ public class TypeScriptNamespace // constants private const int MaxLineLength = 120; private const string MainNamespaceName = "Microsoft.Graph"; - private const string TypeScriptMainNamespaceName = "microsoftgraph"; + private string TypeScriptMainNamespaceName = "microsoftgraph" + (ConfigurationService.Settings.Properties != null && ConfigurationService.Settings.Properties.ContainsKey("typescript.namespacePostfix") ? ConfigurationService.Settings.Properties["typescript.namespacePostfix"] : string.Empty); private const string TabSpace = " "; + /// + /// Returns the main or top level namespace + /// + /// + public string GetMainNameSpace() { + return TypeScriptMainNamespaceName; + } + /// /// Groups entity, complex and enum types to be printed /// diff --git a/test/Typewriter.Test/MultipleNamespacesTestRunner.cs b/test/Typewriter.Test/MultipleNamespacesTestRunner.cs index 4a4f168e9..1ef07557b 100644 --- a/test/Typewriter.Test/MultipleNamespacesTestRunner.cs +++ b/test/Typewriter.Test/MultipleNamespacesTestRunner.cs @@ -31,7 +31,7 @@ public static class MultipleNamespacesTestRunner // and generation process creates a single file with nested namespaces private const string MetadataWithSubNamespacesFile = "MetadataWithSubNamespaces.xml"; - public static void Run(TestLanguage language, bool isPhpBeta = false) + public static void Run(TestLanguage language, bool isBeta = false) { string getMetadataFile(TestLanguage testLanguage) { @@ -54,7 +54,7 @@ string getMetadataFile(TestLanguage testLanguage) // Arrange var languageStr = language.ToString(); - var directoryPostfix = isPhpBeta ? "PHPBeta" : languageStr; + var directoryPostfix = languageStr + (isBeta ? "Beta" : string.Empty); var outputDirectoryName = OutputDirectoryPrefix + directoryPostfix; var testDataDirectoryName = TestDataDirectoryPrefix + directoryPostfix; @@ -74,9 +74,17 @@ string getMetadataFile(TestLanguage testLanguage) if (language == TestLanguage.Java) options.EndpointVersion = "v1.0"; // fixes java generation test as the endpoint contains the version and the default options are not applied in this testing mode - if (isPhpBeta) + if (isBeta) { - options.Properties = new List { "php.namespacePrefix:Beta" }; + if (TestLanguage.PHP == language) + { + options.Properties = new List { "php.namespacePrefix:Beta" }; + } + + if (TestLanguage.TypeScript == language) + { + options.Properties = new List { "typescript.namespacePostfix:beta" }; + } } // Act diff --git a/test/Typewriter.Test/PHPMultipleNamespacesTests.cs b/test/Typewriter.Test/PHPMultipleNamespacesTests.cs index 0020f5c00..945ac4123 100644 --- a/test/Typewriter.Test/PHPMultipleNamespacesTests.cs +++ b/test/Typewriter.Test/PHPMultipleNamespacesTests.cs @@ -14,7 +14,7 @@ public void Test() [Test, RunInApplicationDomain] public void TestBeta() { - MultipleNamespacesTestRunner.Run(TestLanguage.PHP, isPhpBeta: true); + MultipleNamespacesTestRunner.Run(TestLanguage.PHP, isBeta: true); } } } diff --git a/test/Typewriter.Test/TestDataTypeScriptBeta/com/microsoft/graph/src/Microsoft-graph.d.ts b/test/Typewriter.Test/TestDataTypeScriptBeta/com/microsoft/graph/src/Microsoft-graph.d.ts new file mode 100644 index 000000000..3b0d0d05a --- /dev/null +++ b/test/Typewriter.Test/TestDataTypeScriptBeta/com/microsoft/graph/src/Microsoft-graph.d.ts @@ -0,0 +1,207 @@ +// Project: https://github.com/microsoftgraph/msgraph-typescript-typings +// Definitions by: Microsoft Graph Team +// Michael Mainer +// Peter Ombwa +// Mustafa Zengin +// DeVere Dyett +// Nikitha Udaykumar Chettiar +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export as namespace microsoftgraphbeta; + +export type NullableOption = T | null; + +export type Enum1 = "value0" | "value1"; +export interface Entity { + id?: string; +} +export interface TestType extends Entity { + propertyAlpha?: NullableOption; +} +// tslint:disable-next-line: no-empty-interface +export interface EntityType2 extends Entity {} +// tslint:disable-next-line: no-empty-interface +export interface EntityType3 extends Entity {} +export interface TestEntity extends Entity { + testNav?: NullableOption; + testInvalidNav?: NullableOption; + testExplicitNav?: NullableOption; +} +export interface Endpoint extends Entity { + property1?: NullableOption; +} +export interface SingletonEntity1 extends Entity { + testSingleNav?: NullableOption; +} +export interface SingletonEntity2 extends Entity { + testSingleNav2?: NullableOption; +} +export interface TimeOffRequest extends Entity { + name?: NullableOption; +} +export interface TimeOff extends Entity { + name?: NullableOption; +} +export interface Schedule extends Entity { + enabled?: NullableOption; + timesOff?: NullableOption; + timeOffRequests?: NullableOption; +} +export interface Call extends Entity { + subject?: NullableOption; +} +export interface CloudCommunications extends Entity { + calls?: NullableOption; + callRecords?: NullableOption; +} +export interface OnenotePage extends Entity { + // The OneNotePage content. +/// +/// Test token string + content?: NullableOption; +} +// tslint:disable-next-line: no-empty-interface +export interface PlannerGroup extends Entity {} +// tslint:disable-next-line: no-empty-interface +export interface EmptyBaseComplexTypeRequest {} +export interface DerivedComplexTypeRequest extends EmptyBaseComplexTypeRequest { + property1?: NullableOption; + property2?: NullableOption; + enumProperty?: NullableOption; +} +// tslint:disable-next-line: no-empty-interface +export interface ResponseObject {} +export interface Recipient { + name?: NullableOption; + email?: NullableOption; +} +// tslint:disable-next-line: no-empty-interface +export interface EmptyComplexType {} +// tslint:disable-next-line: interface-name +export interface Identity { + displayName?: NullableOption; + id?: NullableOption; +} +// tslint:disable-next-line: interface-name +export interface IdentitySet { + application?: NullableOption; + device?: NullableOption; + user?: NullableOption; +} + +export namespace CallRecords { + 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 microsoftgraphbeta.Entity { + testSingleNav?: NullableOption; + } + interface CallRecord extends microsoftgraphbeta.Entity { + version?: number; + type?: CallType; + modalities?: Modality[]; + lastModifiedDateTime?: string; + startDateTime?: string; + endDateTime?: string; + organizer?: NullableOption; + participants?: NullableOption; + joinWebUrl?: NullableOption; + sessions?: NullableOption; + recipients?: NullableOption; + } + interface Session extends microsoftgraphbeta.Entity { + modalities?: Modality[]; + startDateTime?: string; + endDateTime?: string; + caller?: NullableOption; + callee?: NullableOption; + failureInfo?: NullableOption; + segments?: NullableOption; + } + interface Segment extends microsoftgraphbeta.Entity { + startDateTime?: string; + endDateTime?: string; + caller?: NullableOption; + callee?: NullableOption; + failureInfo?: NullableOption; + media?: NullableOption; + refTypes?: NullableOption; + refType?: NullableOption; + sessionRef?: NullableOption; + photo?: NullableOption; + } +// tslint:disable-next-line: no-empty-interface + interface Option extends microsoftgraphbeta.Entity {} + interface Photo extends microsoftgraphbeta.Entity { + failureInfo?: NullableOption; + option?: NullableOption