Skip to content

Nikithauc/typescript beta mainnamespace #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Please consider splitting this into multiple lines. And if you use null-conditional operator:

Suggested change
return TypeScriptMainNamespaceNamePrefix + (ConfigurationService.Settings.Properties != null && ConfigurationService.Settings.Properties.ContainsKey("typescript.namespacePostfix") ? ConfigurationService.Settings.Properties["typescript.namespacePostfix"] : string.Empty);
var properties = ConfigurationService.Settings?.Properties;
return properties?.ContainsKey("typescript.namespacePostfix") == true
? TypeScriptMainNamespaceNamePrefix + properties["typescript.namespacePostfix"]
: TypeScriptMainNamespaceNamePrefix;

}

/// <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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if case sensitivity matters here but for php would languageStr be "PHP" so the string ends up exactly the same. Since it's a passed in parameter i don't know that's guaranteed and if it matters.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is answered looking at how it's called from the PHPMultipleNamespaces file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fed from an enum that is local to the tests, so nobody will be able to change it by changing a string parameter somewhere. The test caller needs to specify an enum value.

Also this is only used as part of a directory name where case doesn't matter as long as you are on Windows :)

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