Skip to content

Commit 6e9b342

Browse files
authored
Nikithauc/typescript beta mainnamespace (#288)
* Reading postfix for typescript main namespace * format-document * Changes to getmainnamesace method
1 parent e47cc7c commit 6e9b342

File tree

7 files changed

+241
-10
lines changed

7 files changed

+241
-10
lines changed

Templates/TypeScript/src/entity_types.ts.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
1919
// TypeScript Version: 2.1
2020

21-
export as namespace microsoftgraph;
21+
export as namespace <#=typeScriptNamespaces.MainNamespace.GetMainNamespace()#>;
2222

2323
export type NullableOption<T> = T | null;
2424

src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeScriptNamespace.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Graph.ODataTemplateWriter.CodeHelpers.CSharp;
2+
using Microsoft.Graph.ODataTemplateWriter.Settings;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -35,9 +36,18 @@ public class TypeScriptNamespace
3536
// constants
3637
private const int MaxLineLength = 120;
3738
private const string MainNamespaceName = "Microsoft.Graph";
38-
private const string TypeScriptMainNamespaceName = "microsoftgraph";
39+
private const string TypeScriptMainNamespaceNamePrefix = "microsoftgraph";
3940
private const string TabSpace = " ";
4041

42+
/// <summary>
43+
/// Returns the main or top level namespace
44+
/// </summary>
45+
/// <returns></returns>
46+
public string GetMainNamespace()
47+
{
48+
return TypeScriptMainNamespaceNamePrefix + (ConfigurationService.Settings.Properties != null && ConfigurationService.Settings.Properties.ContainsKey("typescript.namespacePostfix") ? ConfigurationService.Settings.Properties["typescript.namespacePostfix"] : string.Empty);
49+
}
50+
4151
/// <summary>
4252
/// Groups entity, complex and enum types to be printed
4353
/// </summary>
@@ -263,7 +273,7 @@ private string GetFullyQualifiedTypeScriptTypeName(string type, string @namespac
263273

264274
if (@namespace == MainNamespaceName) // types in main namespace e.g. microsoftgraph.Entity
265275
{
266-
return TypeScriptMainNamespaceName + "." + type;
276+
return GetMainNamespace() + "." + type;
267277
}
268278

269279
// names in subnamespaces e.g. microsoftgraph.CallRecords.CallRecord

test/Typewriter.Test/MultipleNamespacesTestRunner.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static class MultipleNamespacesTestRunner
3131
// and generation process creates a single file with nested namespaces
3232
private const string MetadataWithSubNamespacesFile = "MetadataWithSubNamespaces.xml";
3333

34-
public static void Run(TestLanguage language, bool isPhpBeta = false)
34+
public static void Run(TestLanguage language, bool isBeta = false)
3535
{
3636
string getMetadataFile(TestLanguage testLanguage)
3737
{
@@ -54,7 +54,7 @@ string getMetadataFile(TestLanguage testLanguage)
5454

5555
// Arrange
5656
var languageStr = language.ToString();
57-
var directoryPostfix = isPhpBeta ? "PHPBeta" : languageStr;
57+
var directoryPostfix = languageStr + (isBeta ? "Beta" : string.Empty);
5858
var outputDirectoryName = OutputDirectoryPrefix + directoryPostfix;
5959
var testDataDirectoryName = TestDataDirectoryPrefix + directoryPostfix;
6060

@@ -74,9 +74,17 @@ string getMetadataFile(TestLanguage testLanguage)
7474
if (language == TestLanguage.Java)
7575
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
7676

77-
if (isPhpBeta)
77+
if (isBeta)
7878
{
79-
options.Properties = new List<string> { "php.namespacePrefix:Beta" };
79+
if (TestLanguage.PHP == language)
80+
{
81+
options.Properties = new List<string> { "php.namespacePrefix:Beta" };
82+
}
83+
84+
if (TestLanguage.TypeScript == language)
85+
{
86+
options.Properties = new List<string> { "typescript.namespacePostfix:beta" };
87+
}
8088
}
8189

8290
// Act

test/Typewriter.Test/PHPMultipleNamespacesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Test()
1414
[Test, RunInApplicationDomain]
1515
public void TestBeta()
1616
{
17-
MultipleNamespacesTestRunner.Run(TestLanguage.PHP, isPhpBeta: true);
17+
MultipleNamespacesTestRunner.Run(TestLanguage.PHP, isBeta: true);
1818
}
1919
}
2020
}
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
// Project: https://github.com/microsoftgraph/msgraph-typescript-typings
2+
// Definitions by: Microsoft Graph Team <https://github.com/microsoftgraph>
3+
// Michael Mainer <https://github.com/MIchaelMainer>
4+
// Peter Ombwa <https://github.com/peombwa>
5+
// Mustafa Zengin <https://github.com/zengin>
6+
// DeVere Dyett <https://github.com/ddyett>
7+
// Nikitha Udaykumar Chettiar <https://github.com/nikithauc>
8+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9+
// TypeScript Version: 2.1
10+
11+
export as namespace microsoftgraphbeta;
12+
13+
export type NullableOption<T> = T | null;
14+
15+
export type Enum1 = "value0" | "value1";
16+
export interface Entity {
17+
id?: string;
18+
}
19+
export interface TestType extends Entity {
20+
propertyAlpha?: NullableOption<DerivedComplexTypeRequest>;
21+
}
22+
// tslint:disable-next-line: no-empty-interface
23+
export interface EntityType2 extends Entity {}
24+
// tslint:disable-next-line: no-empty-interface
25+
export interface EntityType3 extends Entity {}
26+
export interface TestEntity extends Entity {
27+
testNav?: NullableOption<TestType>;
28+
testInvalidNav?: NullableOption<EntityType2>;
29+
testExplicitNav?: NullableOption<EntityType3>;
30+
}
31+
export interface Endpoint extends Entity {
32+
property1?: NullableOption<number>;
33+
}
34+
export interface SingletonEntity1 extends Entity {
35+
testSingleNav?: NullableOption<TestType>;
36+
}
37+
export interface SingletonEntity2 extends Entity {
38+
testSingleNav2?: NullableOption<EntityType3>;
39+
}
40+
export interface TimeOffRequest extends Entity {
41+
name?: NullableOption<string>;
42+
}
43+
export interface TimeOff extends Entity {
44+
name?: NullableOption<string>;
45+
}
46+
export interface Schedule extends Entity {
47+
enabled?: NullableOption<boolean>;
48+
timesOff?: NullableOption<TimeOff[]>;
49+
timeOffRequests?: NullableOption<TimeOffRequest[]>;
50+
}
51+
export interface Call extends Entity {
52+
subject?: NullableOption<string>;
53+
}
54+
export interface CloudCommunications extends Entity {
55+
calls?: NullableOption<Call[]>;
56+
callRecords?: NullableOption<CallRecords.CallRecord[]>;
57+
}
58+
export interface OnenotePage extends Entity {
59+
// The OneNotePage content.
60+
///
61+
/// Test token string
62+
content?: NullableOption<any>;
63+
}
64+
// tslint:disable-next-line: no-empty-interface
65+
export interface PlannerGroup extends Entity {}
66+
// tslint:disable-next-line: no-empty-interface
67+
export interface EmptyBaseComplexTypeRequest {}
68+
export interface DerivedComplexTypeRequest extends EmptyBaseComplexTypeRequest {
69+
property1?: NullableOption<string>;
70+
property2?: NullableOption<string>;
71+
enumProperty?: NullableOption<Enum1>;
72+
}
73+
// tslint:disable-next-line: no-empty-interface
74+
export interface ResponseObject {}
75+
export interface Recipient {
76+
name?: NullableOption<string>;
77+
email?: NullableOption<string>;
78+
}
79+
// tslint:disable-next-line: no-empty-interface
80+
export interface EmptyComplexType {}
81+
// tslint:disable-next-line: interface-name
82+
export interface Identity {
83+
displayName?: NullableOption<string>;
84+
id?: NullableOption<string>;
85+
}
86+
// tslint:disable-next-line: interface-name
87+
export interface IdentitySet {
88+
application?: NullableOption<Identity>;
89+
device?: NullableOption<Identity>;
90+
user?: NullableOption<Identity>;
91+
}
92+
93+
export namespace CallRecords {
94+
type CallType = "unknown" | "groupCall";
95+
type ClientPlatform = "unknown" | "windows";
96+
type FailureStage = "unknown" | "callSetup";
97+
type MediaStreamDirection = "callerToCallee" | "calleeToCaller";
98+
type NetworkConnectionType = "unknown" | "wired";
99+
type ProductFamily = "unknown" | "teams";
100+
type ServiceRole = "unknown" | "customBot";
101+
type UserFeedbackRating = "notRated" | "bad";
102+
type WifiBand = "unknown" | "frequency24GHz";
103+
type WifiRadioType = "unknown" | "wifi80211a";
104+
type Modality = "audio" | "video";
105+
interface SingletonEntity1 extends microsoftgraphbeta.Entity {
106+
testSingleNav?: NullableOption<microsoftgraphbeta.TestType>;
107+
}
108+
interface CallRecord extends microsoftgraphbeta.Entity {
109+
version?: number;
110+
type?: CallType;
111+
modalities?: Modality[];
112+
lastModifiedDateTime?: string;
113+
startDateTime?: string;
114+
endDateTime?: string;
115+
organizer?: NullableOption<microsoftgraphbeta.IdentitySet>;
116+
participants?: NullableOption<microsoftgraphbeta.IdentitySet[]>;
117+
joinWebUrl?: NullableOption<string>;
118+
sessions?: NullableOption<Session[]>;
119+
recipients?: NullableOption<microsoftgraphbeta.EntityType2[]>;
120+
}
121+
interface Session extends microsoftgraphbeta.Entity {
122+
modalities?: Modality[];
123+
startDateTime?: string;
124+
endDateTime?: string;
125+
caller?: NullableOption<Endpoint>;
126+
callee?: NullableOption<Endpoint>;
127+
failureInfo?: NullableOption<FailureInfo>;
128+
segments?: NullableOption<Segment[]>;
129+
}
130+
interface Segment extends microsoftgraphbeta.Entity {
131+
startDateTime?: string;
132+
endDateTime?: string;
133+
caller?: NullableOption<Endpoint>;
134+
callee?: NullableOption<Endpoint>;
135+
failureInfo?: NullableOption<FailureInfo>;
136+
media?: NullableOption<Media[]>;
137+
refTypes?: NullableOption<microsoftgraphbeta.EntityType3[]>;
138+
refType?: NullableOption<microsoftgraphbeta.Call>;
139+
sessionRef?: NullableOption<Session>;
140+
photo?: NullableOption<Photo>;
141+
}
142+
// tslint:disable-next-line: no-empty-interface
143+
interface Option extends microsoftgraphbeta.Entity {}
144+
interface Photo extends microsoftgraphbeta.Entity {
145+
failureInfo?: NullableOption<FailureInfo>;
146+
option?: NullableOption<Option>;
147+
}
148+
interface Endpoint {
149+
userAgent?: NullableOption<UserAgent>;
150+
}
151+
interface UserAgent {
152+
headerValue?: NullableOption<string>;
153+
applicationVersion?: NullableOption<string>;
154+
}
155+
interface FailureInfo {
156+
stage?: FailureStage;
157+
reason?: NullableOption<string>;
158+
}
159+
interface Media {
160+
label?: NullableOption<string>;
161+
callerNetwork?: NullableOption<NetworkInfo>;
162+
callerDevice?: NullableOption<DeviceInfo>;
163+
streams?: NullableOption<MediaStream[]>;
164+
}
165+
interface NetworkInfo {
166+
connectionType?: NetworkConnectionType;
167+
wifiBand?: WifiBand;
168+
basicServiceSetIdentifier?: NullableOption<string>;
169+
wifiRadioType?: WifiRadioType;
170+
wifiSignalStrength?: NullableOption<number>;
171+
bandwidthLowEventRatio?: NullableOption<number>;
172+
}
173+
interface DeviceInfo {
174+
captureDeviceName?: NullableOption<string>;
175+
sentSignalLevel?: NullableOption<number>;
176+
speakerGlitchRate?: NullableOption<number>;
177+
}
178+
interface MediaStream {
179+
streamId?: NullableOption<string>;
180+
startDateTime?: NullableOption<string>;
181+
streamDirection?: MediaStreamDirection;
182+
packetUtilization?: NullableOption<number>;
183+
wasMediaBypassed?: NullableOption<boolean>;
184+
lowVideoProcessingCapabilityRatio?: NullableOption<number>;
185+
averageAudioNetworkJitter?: NullableOption<string>;
186+
}
187+
interface ParticipantEndpoint extends Endpoint {
188+
identity?: NullableOption<microsoftgraphbeta.IdentitySet>;
189+
feedback?: NullableOption<UserFeedback>;
190+
}
191+
interface UserFeedback {
192+
text?: NullableOption<string>;
193+
rating?: UserFeedbackRating;
194+
tokens?: NullableOption<FeedbackTokenSet>;
195+
}
196+
// tslint:disable-next-line: no-empty-interface
197+
interface FeedbackTokenSet {}
198+
// tslint:disable-next-line: no-empty-interface
199+
interface ServiceEndpoint extends Endpoint {}
200+
interface ClientUserAgent extends UserAgent {
201+
platform?: ClientPlatform;
202+
productFamily?: ProductFamily;
203+
}
204+
interface ServiceUserAgent extends UserAgent {
205+
role?: ServiceRole;
206+
}
207+
}

test/Typewriter.Test/TypeScriptMultipeNamespacesTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ namespace Typewriter.Test
55
[TestFixture]
66
public class TypeScriptMultipeNamespacesTests
77
{
8-
[Test]
8+
[Test, RunInApplicationDomain]
99
public void Test()
1010
{
1111
MultipleNamespacesTestRunner.Run(TestLanguage.TypeScript);
1212
}
13+
14+
[Test, RunInApplicationDomain]
15+
public void TestBeta()
16+
{
17+
MultipleNamespacesTestRunner.Run(TestLanguage.TypeScript, isBeta: true);
18+
}
1319
}
1420
}

test/Typewriter.Test/Typewriter.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<Content Include="TestDataPHP*\**\*.php">
7474
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7575
</Content>
76-
<Content Include="TestDataTypeScript\**\*.ts">
76+
<Content Include="TestDataTypeScript*\**\*.ts">
7777
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7878
</Content>
7979
<Content Include="Metadata\MetadataMultipleNamespaces.xml">

0 commit comments

Comments
 (0)