diff --git a/dtdl-tools/src/dtdl-validator/DtdlValidator.cs b/dtdl-tools/src/dtdl-validator/DtdlValidator.cs
index 0b03882c..f9089c29 100644
--- a/dtdl-tools/src/dtdl-validator/DtdlValidator.cs
+++ b/dtdl-tools/src/dtdl-validator/DtdlValidator.cs
@@ -22,10 +22,19 @@ class Program
private const int EXIT_SUCCESS = 0;
private const int EXIT_FAILURE = 1;
- static string ConvertToDTMI(string filepath, string dirpath, string extension)
+ ///
+ /// Convert a DTDL file's path to a DTMI.
+ ///
+ /// The DTDL file's full path.
+ /// The DTDL directory's path.
+ /// The extensin used by the DTDL files.
+ /// The corresponding DTMI.
+ static string ConvertToDTMI(string dtdlFilePath, string dtdlDirPath, string extension)
{
- string relativepath = filepath.Substring(dirpath.Length + 1, filepath.Length - dirpath.Length - extension.Length - 2);
- string dtmi = relativepath.Replace('/', ':').Replace('-', ';'); // .ToLower();
+ // Strip off the directory path and the extension.
+ string dtmiPpath = dtdlFilePath.Substring(dtdlDirPath.Length + 1, dtdlFilePath.Length - dtdlDirPath.Length - extension.Length - 2);
+ // Replace each directory separator with a colon and the hyphen with a semicolon.
+ string dtmi = dtmiPpath.Replace('/', ':').Replace('-', ';');
return dtmi;
}
@@ -33,33 +42,33 @@ static string ConvertToDTMI(string filepath, string dirpath, string extension)
/// This method validates all of the DTDL files with the provided extension that are located
/// under the provided directory.
///
- /// The directory that contains the DTDL files that we wish to validate.
+ /// The directory that contains the DTDL files that we wish to validate.
/// The extension used by the DTDL files.
///
/// EXIT_SUCCESS when all if the DTDL files are valid.
/// EXIT_FAILURE when any of the DTDL files are NOT valid.
///
- static int ValidateDtdl(DirectoryInfo directory, String extension)
+ static int ValidateDtdl(DirectoryInfo dtdlDirectory, String extension)
{
- if (!directory.Exists)
+ if (!dtdlDirectory.Exists)
{
- Console.WriteLine($"Directory {directory.FullName} does not exist.");
+ Console.WriteLine($"Directory {dtdlDirectory.FullName} does not exist.");
return EXIT_FAILURE;
}
- var files = Directory.GetFiles(directory.FullName, $"*.{extension}", SearchOption.AllDirectories);
+ var files = Directory.GetFiles(dtdlDirectory.FullName, $"*.{extension}", SearchOption.AllDirectories);
if (!files.Any())
{
- Console.WriteLine($"No files with extension .{extension} found in directory {directory}");
+ Console.WriteLine($"No files with extension .{extension} found in directory {dtdlDirectory}");
return EXIT_FAILURE;
}
- var dmrClient = new ModelsRepositoryClient(new Uri(directory.FullName));
+ var modelRepoClient = new ModelsRepositoryClient(new Uri(dtdlDirectory.FullName));
var parser = new ModelParser(new ParsingOptions()
{
- DtmiResolverAsync = dmrClient.ParserDtmiResolverAsync
+ DtmiResolverAsync = modelRepoClient.ParserDtmiResolverAsync
});
bool failureOccured = false;
@@ -67,8 +76,8 @@ static int ValidateDtdl(DirectoryInfo directory, String extension)
{
try
{
- string dtmi = ConvertToDTMI(file, directory.FullName, extension);
- var model = dmrClient.GetModelAsync(dtmi).GetAwaiter().GetResult();
+ string dtmi = ConvertToDTMI(file, dtdlDirectory.FullName, extension);
+ var model = modelRepoClient.GetModelAsync(dtmi).GetAwaiter().GetResult();
var dictParsed = parser.ParseAsync(model.Content[dtmi]).GetAwaiter().GetResult();
Console.WriteLine($"{file} - ok");
}
diff --git a/dtdl-tools/src/dtdl-validator/ModelsRepositoryClientExtensions.cs b/dtdl-tools/src/dtdl-validator/ModelsRepositoryClientExtensions.cs
index 89ff5f1f..a28e00f8 100644
--- a/dtdl-tools/src/dtdl-validator/ModelsRepositoryClientExtensions.cs
+++ b/dtdl-tools/src/dtdl-validator/ModelsRepositoryClientExtensions.cs
@@ -1,3 +1,6 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT license.
+// SPDX-License-Identifier: MIT
using Azure.IoT.ModelsRepository;
using DTDLParser;
@@ -5,13 +8,20 @@
internal static class ModelsRepositoryClientExtensions
{
+ ///
+ /// The Parser's DTMI resolver.
+ ///
+ /// The model's repository client.
+ ///
+ /// The cancellation topken.
+ /// The model definitions for the provided DTMIs.
public static async IAsyncEnumerable ParserDtmiResolverAsync(
- this ModelsRepositoryClient client, IReadOnlyCollection dtmis,
- [EnumeratorCancellation] CancellationToken ct = default)
+ this ModelsRepositoryClient modelRepoClient, IReadOnlyCollection dtmis,
+ [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
foreach (var dtmi in dtmis.Select(s => s.AbsoluteUri))
{
- var result = await client.GetModelAsync(dtmi, ModelDependencyResolution.Disabled, ct);
+ var result = await modelRepoClient.GetModelAsync(dtmi, ModelDependencyResolution.Disabled, cancellationToken);
yield return result.Content[dtmi];
}
}