diff --git a/src/GraphODataTemplateWriter/Settings/ConfigurationService.cs b/src/GraphODataTemplateWriter/Settings/ConfigurationService.cs index 0bb408899..ca578bdfd 100644 --- a/src/GraphODataTemplateWriter/Settings/ConfigurationService.cs +++ b/src/GraphODataTemplateWriter/Settings/ConfigurationService.cs @@ -17,10 +17,13 @@ public static class ConfigurationService private static IConfigurationProvider _configurationProvider; private static TemplateWriterSettings templateWriterSettings = null; private static string targetLanguage = null; + private static string endpointVersion = null; private static Dictionary properties = null; - public static void Initialize(IConfigurationProvider configurationProvider, string targetLanguage = null, IEnumerable properties = null) + public static void Initialize(IConfigurationProvider configurationProvider, string targetLanguage = null, IEnumerable properties = null, string endpointVersion = "v1.0") { + ConfigurationService.endpointVersion = endpointVersion; + _configurationProvider = configurationProvider; if (!String.IsNullOrEmpty(targetLanguage)) { @@ -58,6 +61,7 @@ private static TemplateWriterSettings LoadSettingsForLanguage() mainTWS.Properties = properties; } + mainTWS.DefaultBaseEndpointUrl = String.Format("https://graph.microsoft.com/{0}", endpointVersion); TemplateWriterSettings.mainSettingsObject = mainTWS; diff --git a/src/GraphODataTemplateWriter/TemplateProcessor/TemplateWriter.cs b/src/GraphODataTemplateWriter/TemplateProcessor/TemplateWriter.cs index 255a0025e..b77ac27de 100644 --- a/src/GraphODataTemplateWriter/TemplateProcessor/TemplateWriter.cs +++ b/src/GraphODataTemplateWriter/TemplateProcessor/TemplateWriter.cs @@ -27,6 +27,7 @@ public class TemplateWriter : IConfigurable, IOdcmWriter private string targetLanguage; private IEnumerable properties; + private string endpointVersion; public TemplateWriter() { @@ -43,6 +44,13 @@ public TemplateWriter(string targetLanguage, IEnumerable properties) this.properties = properties; } + public TemplateWriter(string targetLanguage, IEnumerable properties, string endpointVersion) + { + this.targetLanguage = targetLanguage; + this.properties = properties; + this.endpointVersion = endpointVersion; + } + private string PathWriterClassNameFormatString { get { @@ -98,7 +106,7 @@ IEnumerable ProcessTemplates() // IConfigurationProvider public void SetConfigurationProvider(IConfigurationProvider configurationProvider) { - ConfigurationService.Initialize(configurationProvider, this.targetLanguage, this.properties); + ConfigurationService.Initialize(configurationProvider, this.targetLanguage, this.properties, this.endpointVersion); FileNameCasing nameCasing; if(!Enum.TryParse(ConfigurationService.Settings.DefaultFileCasing, out nameCasing)) { diff --git a/src/Typewriter/Generator.cs b/src/Typewriter/Generator.cs index 40f237903..6a1bc6545 100644 --- a/src/Typewriter/Generator.cs +++ b/src/Typewriter/Generator.cs @@ -18,7 +18,7 @@ internal static class Generator /// The options bag static internal void GenerateFiles(string csdlContents, Options options) { - var filesToWrite = MetadataToClientSource(csdlContents, options.Language, options.Properties); + var filesToWrite = MetadataToClientSource(csdlContents, options.Language, options.Properties, options.EndpointVersion); FileWriter.WriteAsync(filesToWrite, options.Output); } @@ -65,13 +65,13 @@ static private string CleanMetadata(string csdlContents, Options options) /// The EDMX file as a string. /// Specifies the target language. Possible values are csharp, php, etc. /// - static private IEnumerable MetadataToClientSource(string edmxString, string targetLanguage, IEnumerable properties) + static private IEnumerable MetadataToClientSource(string edmxString, string targetLanguage, IEnumerable properties, string endpointVersion = "v1.0") { if (String.IsNullOrEmpty(edmxString)) throw new ArgumentNullException("edmxString", "The EDMX file string contains no content."); var reader = new OdcmReader(); - var writer = new TemplateWriter(targetLanguage, properties); + var writer = new TemplateWriter(targetLanguage, properties, endpointVersion); writer.SetConfigurationProvider(new ConfigurationProvider()); var model = reader.GenerateOdcmModel(new List { new TextFile("$metadata", edmxString) }); diff --git a/src/Typewriter/MetadataPreprocessor.cs b/src/Typewriter/MetadataPreprocessor.cs index 2d6611d71..64315d7a4 100644 --- a/src/Typewriter/MetadataPreprocessor.cs +++ b/src/Typewriter/MetadataPreprocessor.cs @@ -51,6 +51,15 @@ internal static string CleanMetadata(string csdlContents) AddContainsTarget("plannerPlan"); AddContainsTarget("plannerDelta"); + AddContainsTarget("teamsAppDefinition"); + AddContainsTarget("itemActivity"); + + // Intune + AddContainsTarget("windows81TrustedRootCertificate"); + AddContainsTarget("iosTrustedRootCertificate"); + AddContainsTarget("mobileContainedApp"); + AddContainsTarget("managedDeviceCertificateState"); + return xMetadata.ToString(); } diff --git a/test/Typewriter.Test/Given_a_valid_metadata_file_to_Typewriter.cs b/test/Typewriter.Test/Given_a_valid_metadata_file_to_Typewriter.cs index a34dbc37e..97441f9f5 100644 --- a/test/Typewriter.Test/Given_a_valid_metadata_file_to_Typewriter.cs +++ b/test/Typewriter.Test/Given_a_valid_metadata_file_to_Typewriter.cs @@ -72,5 +72,39 @@ public void It_generates_PHP_models_with_a_property() } Assert.IsTrue(isExpectedNamespaceSet, $"The expected namespace, {testNamespace}, was not set in the generated test file."); } + + [TestMethod] + public void It_generates_dotNet_client_with_default_beta_baseUrl() + { + const string outputDirectory = "output"; + + Options options = new Options() + { + Output = outputDirectory, + Language = "CSharp", + GenerationMode = GenerationMode.Files, + EndpointVersion = "beta" + }; + + Generator.GenerateFiles(testMetadata, options); + + FileInfo fileInfo = new FileInfo(outputDirectory + generatedOutputUrl + @"\Requests\GraphServiceClient.cs"); + Assert.IsTrue(fileInfo.Exists, $"Expected: {fileInfo.FullName}. File was not found."); + + // Check that the beta endpoint was set as the default endpoint. Otherwise it uses v1.0. + // https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/src/Microsoft.Graph/Requests/Generated/GraphServiceClient.cs#L25 + IEnumerable lines = File.ReadLines(fileInfo.FullName); + bool hasFoundBetaUrl = false; + string betaUrl = "https://graph.microsoft.com/beta"; + foreach (var line in lines) + { + if (line.Contains(betaUrl)) + { + hasFoundBetaUrl = true; + break; + } + } + Assert.IsTrue(hasFoundBetaUrl, $"The expected default base URL, {betaUrl}, was not set in the generated test file."); + } } }