Skip to content

Commit

Permalink
Nikithauc/typescript beta mainnamespace (#288)
Browse files Browse the repository at this point in the history
* Reading postfix for typescript main namespace

* format-document

* Changes to getmainnamesace method
  • Loading branch information
nikithauc authored Sep 10, 2020
1 parent e47cc7c commit 6e9b342
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Templates/TypeScript/src/entity_types.ts.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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> = T | null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Graph.ODataTemplateWriter.CodeHelpers.CSharp;
using Microsoft.Graph.ODataTemplateWriter.Settings;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -35,9 +36,18 @@ public class TypeScriptNamespace
// constants
private const int MaxLineLength = 120;
private const string MainNamespaceName = "Microsoft.Graph";
private const string TypeScriptMainNamespaceName = "microsoftgraph";
private const string TypeScriptMainNamespaceNamePrefix = "microsoftgraph";
private const string TabSpace = " ";

/// <summary>
/// Returns the main or top level namespace
/// </summary>
/// <returns></returns>
public string GetMainNamespace()
{
return TypeScriptMainNamespaceNamePrefix + (ConfigurationService.Settings.Properties != null && ConfigurationService.Settings.Properties.ContainsKey("typescript.namespacePostfix") ? ConfigurationService.Settings.Properties["typescript.namespacePostfix"] : string.Empty);
}

/// <summary>
/// Groups entity, complex and enum types to be printed
/// </summary>
Expand Down Expand Up @@ -263,7 +273,7 @@ private string GetFullyQualifiedTypeScriptTypeName(string type, string @namespac

if (@namespace == MainNamespaceName) // types in main namespace e.g. microsoftgraph.Entity
{
return TypeScriptMainNamespaceName + "." + type;
return GetMainNamespace() + "." + type;
}

// names in subnamespaces e.g. microsoftgraph.CallRecords.CallRecord
Expand Down
16 changes: 12 additions & 4 deletions test/Typewriter.Test/MultipleNamespacesTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;

Expand All @@ -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<string> { "php.namespacePrefix:Beta" };
if (TestLanguage.PHP == language)
{
options.Properties = new List<string> { "php.namespacePrefix:Beta" };
}

if (TestLanguage.TypeScript == language)
{
options.Properties = new List<string> { "typescript.namespacePostfix:beta" };
}
}

// Act
Expand Down
2 changes: 1 addition & 1 deletion test/Typewriter.Test/PHPMultipleNamespacesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Test()
[Test, RunInApplicationDomain]
public void TestBeta()
{
MultipleNamespacesTestRunner.Run(TestLanguage.PHP, isPhpBeta: true);
MultipleNamespacesTestRunner.Run(TestLanguage.PHP, isBeta: true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
// Project: https://github.com/microsoftgraph/msgraph-typescript-typings
// Definitions by: Microsoft Graph Team <https://github.com/microsoftgraph>
// Michael Mainer <https://github.com/MIchaelMainer>
// Peter Ombwa <https://github.com/peombwa>
// Mustafa Zengin <https://github.com/zengin>
// DeVere Dyett <https://github.com/ddyett>
// Nikitha Udaykumar Chettiar <https://github.com/nikithauc>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1

export as namespace microsoftgraphbeta;

export type NullableOption<T> = T | null;

export type Enum1 = "value0" | "value1";
export interface Entity {
id?: string;
}
export interface TestType extends Entity {
propertyAlpha?: NullableOption<DerivedComplexTypeRequest>;
}
// 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<TestType>;
testInvalidNav?: NullableOption<EntityType2>;
testExplicitNav?: NullableOption<EntityType3>;
}
export interface Endpoint extends Entity {
property1?: NullableOption<number>;
}
export interface SingletonEntity1 extends Entity {
testSingleNav?: NullableOption<TestType>;
}
export interface SingletonEntity2 extends Entity {
testSingleNav2?: NullableOption<EntityType3>;
}
export interface TimeOffRequest extends Entity {
name?: NullableOption<string>;
}
export interface TimeOff extends Entity {
name?: NullableOption<string>;
}
export interface Schedule extends Entity {
enabled?: NullableOption<boolean>;
timesOff?: NullableOption<TimeOff[]>;
timeOffRequests?: NullableOption<TimeOffRequest[]>;
}
export interface Call extends Entity {
subject?: NullableOption<string>;
}
export interface CloudCommunications extends Entity {
calls?: NullableOption<Call[]>;
callRecords?: NullableOption<CallRecords.CallRecord[]>;
}
export interface OnenotePage extends Entity {
// The OneNotePage content.
///
/// Test token string
content?: NullableOption<any>;
}
// 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<string>;
property2?: NullableOption<string>;
enumProperty?: NullableOption<Enum1>;
}
// tslint:disable-next-line: no-empty-interface
export interface ResponseObject {}
export interface Recipient {
name?: NullableOption<string>;
email?: NullableOption<string>;
}
// tslint:disable-next-line: no-empty-interface
export interface EmptyComplexType {}
// tslint:disable-next-line: interface-name
export interface Identity {
displayName?: NullableOption<string>;
id?: NullableOption<string>;
}
// tslint:disable-next-line: interface-name
export interface IdentitySet {
application?: NullableOption<Identity>;
device?: NullableOption<Identity>;
user?: NullableOption<Identity>;
}

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<microsoftgraphbeta.TestType>;
}
interface CallRecord extends microsoftgraphbeta.Entity {
version?: number;
type?: CallType;
modalities?: Modality[];
lastModifiedDateTime?: string;
startDateTime?: string;
endDateTime?: string;
organizer?: NullableOption<microsoftgraphbeta.IdentitySet>;
participants?: NullableOption<microsoftgraphbeta.IdentitySet[]>;
joinWebUrl?: NullableOption<string>;
sessions?: NullableOption<Session[]>;
recipients?: NullableOption<microsoftgraphbeta.EntityType2[]>;
}
interface Session extends microsoftgraphbeta.Entity {
modalities?: Modality[];
startDateTime?: string;
endDateTime?: string;
caller?: NullableOption<Endpoint>;
callee?: NullableOption<Endpoint>;
failureInfo?: NullableOption<FailureInfo>;
segments?: NullableOption<Segment[]>;
}
interface Segment extends microsoftgraphbeta.Entity {
startDateTime?: string;
endDateTime?: string;
caller?: NullableOption<Endpoint>;
callee?: NullableOption<Endpoint>;
failureInfo?: NullableOption<FailureInfo>;
media?: NullableOption<Media[]>;
refTypes?: NullableOption<microsoftgraphbeta.EntityType3[]>;
refType?: NullableOption<microsoftgraphbeta.Call>;
sessionRef?: NullableOption<Session>;
photo?: NullableOption<Photo>;
}
// tslint:disable-next-line: no-empty-interface
interface Option extends microsoftgraphbeta.Entity {}
interface Photo extends microsoftgraphbeta.Entity {
failureInfo?: NullableOption<FailureInfo>;
option?: NullableOption<Option>;
}
interface Endpoint {
userAgent?: NullableOption<UserAgent>;
}
interface UserAgent {
headerValue?: NullableOption<string>;
applicationVersion?: NullableOption<string>;
}
interface FailureInfo {
stage?: FailureStage;
reason?: NullableOption<string>;
}
interface Media {
label?: NullableOption<string>;
callerNetwork?: NullableOption<NetworkInfo>;
callerDevice?: NullableOption<DeviceInfo>;
streams?: NullableOption<MediaStream[]>;
}
interface NetworkInfo {
connectionType?: NetworkConnectionType;
wifiBand?: WifiBand;
basicServiceSetIdentifier?: NullableOption<string>;
wifiRadioType?: WifiRadioType;
wifiSignalStrength?: NullableOption<number>;
bandwidthLowEventRatio?: NullableOption<number>;
}
interface DeviceInfo {
captureDeviceName?: NullableOption<string>;
sentSignalLevel?: NullableOption<number>;
speakerGlitchRate?: NullableOption<number>;
}
interface MediaStream {
streamId?: NullableOption<string>;
startDateTime?: NullableOption<string>;
streamDirection?: MediaStreamDirection;
packetUtilization?: NullableOption<number>;
wasMediaBypassed?: NullableOption<boolean>;
lowVideoProcessingCapabilityRatio?: NullableOption<number>;
averageAudioNetworkJitter?: NullableOption<string>;
}
interface ParticipantEndpoint extends Endpoint {
identity?: NullableOption<microsoftgraphbeta.IdentitySet>;
feedback?: NullableOption<UserFeedback>;
}
interface UserFeedback {
text?: NullableOption<string>;
rating?: UserFeedbackRating;
tokens?: NullableOption<FeedbackTokenSet>;
}
// tslint:disable-next-line: no-empty-interface
interface FeedbackTokenSet {}
// tslint:disable-next-line: no-empty-interface
interface ServiceEndpoint extends Endpoint {}
interface ClientUserAgent extends UserAgent {
platform?: ClientPlatform;
productFamily?: ProductFamily;
}
interface ServiceUserAgent extends UserAgent {
role?: ServiceRole;
}
}
8 changes: 7 additions & 1 deletion test/Typewriter.Test/TypeScriptMultipeNamespacesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ namespace Typewriter.Test
[TestFixture]
public class TypeScriptMultipeNamespacesTests
{
[Test]
[Test, RunInApplicationDomain]
public void Test()
{
MultipleNamespacesTestRunner.Run(TestLanguage.TypeScript);
}

[Test, RunInApplicationDomain]
public void TestBeta()
{
MultipleNamespacesTestRunner.Run(TestLanguage.TypeScript, isBeta: true);
}
}
}
2 changes: 1 addition & 1 deletion test/Typewriter.Test/Typewriter.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<Content Include="TestDataPHP*\**\*.php">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="TestDataTypeScript\**\*.ts">
<Content Include="TestDataTypeScript*\**\*.ts">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Metadata\MetadataMultipleNamespaces.xml">
Expand Down

0 comments on commit 6e9b342

Please sign in to comment.