Skip to content

Commit

Permalink
Added Use Flow Expression validation for YAML AaC (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
SlavaVedernikov authored Mar 16, 2024
2 parents 8f787fc + 3c86406 commit fcc757a
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 6 deletions.
4 changes: 2 additions & 2 deletions C4InterFlow.Automation/C4InterFlow.Automation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<Deterministic>true</Deterministic>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>0.36.0-rc</Version>
<Version>0.37.0</Version>
</PropertyGroup>

<PropertyGroup>
<PackageId>C4InterFlow.Automation</PackageId>
<PackageVersion>0.36.0-rc</PackageVersion>
<PackageVersion>0.37.0</PackageVersion>
<Authors>Slava Vedernikov</Authors>
<Description>Revolutionise your Application Architecture Documentation with C4InterFlow. Designed for Architects and Engineers, this tool leverages the widely-recognised C4 Model (Architecture Visualisation framework), enhanced with unique features like Interface and Flow, to describe your Application Architecture as Code. Experience an intuitive, efficient way to document complex systems, ensuring clarity and consistency across your teams and products.</Description>
<Copyright>Copyright 2024 Slava Vedernikov</Copyright>
Expand Down
47 changes: 47 additions & 0 deletions C4InterFlow.Automation/Readers/JObjectStructuresResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,52 @@ public IEnumerable<T> GetNestedInstances<T>(string? alias) where T : Structure

return result;
}

public void Validate(out IEnumerable<string> errors)
{
var errorsInternal = new List<string>();

var interfaces = RootJObject.SelectTokens("..Interfaces.*");

foreach (var @interface in interfaces)
{
var useFlows = @interface.SelectTokens("..[?(@.Type=='Use')]");

foreach(var useFlow in useFlows)
{
var usesInterfaceAlias = useFlow["Expression"].ToString();
var usesInterface = RootJObject.SelectToken(usesInterfaceAlias);

if (usesInterface == null)
{
errorsInternal.Add($"Cannot resolve Interface '{usesInterfaceAlias}' referenced in Use Flow(s) of '{@interface.Path}' Interface.");
}
}
}

var activitiesTokens = RootJObject.SelectTokens("..Activities");

foreach (var activities in activitiesTokens)
{
foreach(var activity in activities)
{
var useFlows = activity.SelectTokens("..[?(@.Type=='Use')]");

foreach (var useFlow in useFlows)
{
var usesInterfaceAlias = useFlow["Expression"].ToString();
var usesInterface = RootJObject.SelectToken(usesInterfaceAlias);

if (usesInterface == null)
{
errorsInternal.Add($"Cannot resolve Interface '{usesInterfaceAlias}' referenced in Use Flow(s) of '{activity.Path} - {activity["Label"]}' Activity.");
}
}
}

}

errors = errorsInternal;
}
}
}
6 changes: 6 additions & 0 deletions C4InterFlow.Automation/Readers/NetStructuresResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,11 @@ public IEnumerable<T> GetNestedInstances<T>(string? alias) where T : Structure

return result;
}

public void Validate(out IEnumerable<string> errors)
{
//TODO: Implement Use Flow Expressions validation
errors = new List<string>();
}
}
}
2 changes: 1 addition & 1 deletion C4InterFlow.Cli/C4InterFlow.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.36.0-rc</Version>
<Version>0.37.0</Version>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
Expand Down
2 changes: 1 addition & 1 deletion C4InterFlow.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"C4InterFlow.Cli": {
"commandName": "Project",
"commandLineArgs": "draw-diagrams --aac-input-paths \"C:\\C4InterFlow\\Samples\\E-Commerce Platform\\Yaml\\Architecture\" --aac-reader-strategy \"C4InterFlow.Automation.Readers.YamlAaCReaderStrategy,C4InterFlow.Automation\" --interfaces ECommercePlatform.SoftwareSystems.*.Containers.*.Interfaces.* --output-dir \"C:\\C4InterFlow\\Samples\\E-Commerce Platform\\Yaml\\Diagrams\"\r\n",
"commandLineArgs": "draw-diagrams --aac-input-paths \"C:\\C4InterFlow\\Samples\\Internet Banking System\\CSV\\Architecture\\Yaml\" --aac-reader-strategy \"C4InterFlow.Automation.Readers.YamlAaCReaderStrategy,C4InterFlow.Automation\" --interfaces BigBankPlc.SoftwareSystems.*.Containers.*.Interfaces.* --business-processes BigBankPlc.BusinessProcesses.* --levels-of-details context container --output-dir \"C:\\C4InterFlow\\Samples\\Internet Banking System\\CSV\\Diagrams\"\r\n",
"workingDirectory": "C:\\C4InterFlow\\Samples\\Internet Banking System\\CSV"
}
}
Expand Down
5 changes: 5 additions & 0 deletions C4InterFlow/Automation/AaCReaderStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ public IEnumerable<T> GetNestedInstances<T>(string? alias) where T : Structure
{
return ElementsResolver.GetNestedInstances<T>(alias);
}

public void Validate(out IEnumerable<string> errors)
{
ElementsResolver.Validate(out errors);
}
}
}
4 changes: 2 additions & 2 deletions C4InterFlow/C4InterFlow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<Deterministic>true</Deterministic>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>0.36.0-rc</Version>
<Version>0.37.0</Version>
</PropertyGroup>

<PropertyGroup>
<PackageId>C4InterFlow</PackageId>
<PackageVersion>0.36.0-rc</PackageVersion>
<PackageVersion>0.37.0</PackageVersion>
<Authors>Slava Vedernikov</Authors>
<Description>Revolutionise your Application Architecture Documentation with C4InterFlow. Designed for Architects and Engineers, this tool leverages the widely-recognised C4 Model (Architecture Visualisation framework), enhanced with unique features like Interface and Flow, to describe your Application Architecture as Code. Experience an intuitive, efficient way to document complex systems, ensuring clarity and consistency across your teams and products.</Description>
<Copyright>Copyright 2024 Slava Vedernikov</Copyright>
Expand Down
10 changes: 10 additions & 0 deletions C4InterFlow/Cli/Commands/DrawDiagramsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ public static async Task<int> Execute(DiagramOptions diagramOptions, string[]? i
{
Utils.SetArchitectureAsCodeReaderContext(architectureAsCodeInputPaths, architectureAsCodeReaderStrategyType);
}
AaCReaderContext.Strategy.Validate(out var errors);

if(errors.Any())
{
foreach(var error in errors)
{
Console.WriteLine(error);
}

throw new InvalidDataException("AaC has errors. Please resolve and retry.");
}
var resolvedInterfaceAliases = new List<string>();
resolvedInterfaceAliases.AddRange(Utils.ResolveStructures(interfaceAliases));

Expand Down
1 change: 1 addition & 0 deletions C4InterFlow/Structures/Interfaces/IStructuresResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public interface IStructuresResolver
public T? GetInstance<T>(string? alias) where T : Structure;
public IEnumerable<string> ResolveStructures(IEnumerable<string> structures);
public IEnumerable<Interface> GetAllInterfaces();
public void Validate(out IEnumerable<string> errors);
}
}

0 comments on commit fcc757a

Please sign in to comment.