From afb020c98343ba502d5104673a3aa9c7d103caf3 Mon Sep 17 00:00:00 2001 From: Marcin Celej Date: Sat, 6 Jan 2024 18:40:51 +0100 Subject: [PATCH] #27: introduced ability to create api description for specific class with its nested classes. --- Documentation/README.md | 2 +- .../Debt/Todos.Technical.Debt.verified.md | 5 +- .../Architecture/Dependencies/Relations.cs | 7 +- .../Relations.of.Document.verified.md | 11 --- .../Relations.of.Markdown.verified.md | 91 +++++++++++++++++++ .../Api.of.Synergy.Documentation.verified.md | 7 +- .../Synergy.Documentation/Api/Dependencies.cs | 43 +++++++-- 7 files changed, 134 insertions(+), 32 deletions(-) delete mode 100644 Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Document.verified.md diff --git a/Documentation/README.md b/Documentation/README.md index 9b28a1e..aaa0cb6 100644 --- a/Documentation/README.md +++ b/Documentation/README.md @@ -95,7 +95,7 @@ public class Relations For sample code, please check: [Relations.cs](Synergy.Documentation.Tests/Architecture/Dependencies/Relations.cs) -To see the results, please check: [Relations.of.Document.verified.md](Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Document.verified.md) +To see the results, please check: [Relations.of.Markdown.verified.md](Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Markdown.verified.md) [//]: # (TODO Write the documentation of Dependencies genaretor) diff --git a/Documentation/Synergy.Documentation.Tests/Architecture/Debt/Todos.Technical.Debt.verified.md b/Documentation/Synergy.Documentation.Tests/Architecture/Debt/Todos.Technical.Debt.verified.md index 6e7e6bd..eee893d 100644 --- a/Documentation/Synergy.Documentation.Tests/Architecture/Debt/Todos.Technical.Debt.verified.md +++ b/Documentation/Synergy.Documentation.Tests/Architecture/Debt/Todos.Technical.Debt.verified.md @@ -1,9 +1,6 @@ # Technical Debt for Synergy.Documentation -Total: 8 - -## [Relations.cs](../Dependencies/Relations.cs) -- TODO: Marcin Celej [from: Marcin Celej on: 26-12-2023]: Doe not work for Markdown.Document +Total: 7 ## [MarkdownTests.cs](../../Markup/MarkdownTests.cs) - TODO: Marcin Celej [from: Marcin Celej on: 23-12-2023]: Add image test here diff --git a/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.cs b/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.cs index c123bd9..36c201e 100644 --- a/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.cs +++ b/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.cs @@ -8,17 +8,16 @@ public class Relations { [Theory] [InlineData(typeof(Markdown))] - [InlineData(typeof(Markdown.Document))] - public async Task Generate(Type type) + public async Task Generate(params Type[] type) { // ARRANGE - var dependencies = Synergy.Documentation.Api.Dependencies.Of(type); + var dependencies = Synergy.Documentation.Api.Dependencies.Of(type.First(), includeNested: true); // ACT var publicApi = ApiDescription.GenerateFor(dependencies); // ASSERT await Verifier.Verify(publicApi, "md") - .UseMethodName("of." + type.Name); + .UseMethodName("of." + type.First().Name); } } \ No newline at end of file diff --git a/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Document.verified.md b/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Document.verified.md deleted file mode 100644 index 1273195..0000000 --- a/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Document.verified.md +++ /dev/null @@ -1,11 +0,0 @@ -## Synergy.Documentation.Markup.Markdown+Document (class) : IEnumerable, IEnumerable - - ctor() - - Append( - element: Markdown+IElement - ) : Markdown+Document - - Append( - newElements: IEnumerable - ) : Markdown+Document - - GetEnumerator() : IEnumerator - - ToString() : string - diff --git a/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Markdown.verified.md b/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Markdown.verified.md index 8ccd1bd..a16afbb 100644 --- a/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Markdown.verified.md +++ b/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Markdown.verified.md @@ -1,3 +1,94 @@ ## Synergy.Documentation.Markup.Markdown (class) - ctor() +## Synergy.Documentation.Markup.Markdown+IElement (interface) + +## Synergy.Documentation.Markup.Markdown+Document (class) : IEnumerable, IEnumerable + - ctor() + - Append( + element: Markdown+IElement + ) : Markdown+Document + - Append( + newElements: IEnumerable + ) : Markdown+Document + - GetEnumerator() : IEnumerator + - ToString() : string + +## Synergy.Documentation.Markup.Markdown+Header (abstract class) : Markdown+IElement + - ToString() : string + +## Synergy.Documentation.Markup.Markdown+Header1 (class) : Markdown+Header, Markdown+IElement + - ctor( + header: string + ) + - ToString() : string + +## Synergy.Documentation.Markup.Markdown+Header2 (class) : Markdown+Header, Markdown+IElement + - ctor( + header: string + ) + - ToString() : string + +## Synergy.Documentation.Markup.Markdown+Header3 (class) : Markdown+Header, Markdown+IElement + - ctor( + header: string + ) + - ToString() : string + +## Synergy.Documentation.Markup.Markdown+Code (class) : Markdown+IElement + - ctor( + text: string? [Optional], + language: string? [Optional] + ) + - Line( + line: string + ) : Markdown+Code [NullableContext] + - ToString() : string [NullableContext] + +## Synergy.Documentation.Markup.Markdown+Paragraph (class) : Markdown+IElement + - ctor( + text: string + ) + - Line( + line: string + ) : Markdown+Paragraph + - ToString() : string + +## Synergy.Documentation.Markup.Markdown+Quote (class) : Markdown+IElement + - ctor( + text: string? + ) + - Line( + line: string + ) : Markdown+Quote + - ToString() : string + +## Synergy.Documentation.Markup.Markdown+Table (class) : Markdown+IElement + - ctor( + headers: params String[] [ParamArray] + ) + - Append( + cells: params String[] [ParamArray] + ) : void + - ToString() : string + +## Synergy.Documentation.Markup.Markdown+Image (class) : Markdown+IElement + - ctor( + filePath: CodeFile, + alternateText: string? [Nullable, Optional] + ) + - RelativeTo( + file: CodeFile + ) : Markdown+Image + - ToString() : string + +## Synergy.Documentation.Markup.Markdown+Link (class) + - ctor( + filePath: CodeFile, + text: string? [Nullable, Optional] + ) + - RelativeTo( + file: CodeFile + ) : Markdown+Link + - ToString() : string + diff --git a/Documentation/Synergy.Documentation.Tests/Architecture/Public/Api.of.Synergy.Documentation.verified.md b/Documentation/Synergy.Documentation.Tests/Architecture/Public/Api.of.Synergy.Documentation.verified.md index 8e2a8fb..da80659 100644 --- a/Documentation/Synergy.Documentation.Tests/Architecture/Public/Api.of.Synergy.Documentation.verified.md +++ b/Documentation/Synergy.Documentation.Tests/Architecture/Public/Api.of.Synergy.Documentation.verified.md @@ -38,10 +38,13 @@ - ToString() : string ## Api.Dependencies (class) - - ctor() - Dependencies.Of( - root: Type + root: Type, + includeNested: bool [Optional] ) : List + - DependenciesOf( + type: Type + ) : IEnumerable [IteratorStateMachine] ## Code.ClassReader (class) - ctor() diff --git a/Documentation/Synergy.Documentation/Api/Dependencies.cs b/Documentation/Synergy.Documentation/Api/Dependencies.cs index 85e2909..e12a74e 100644 --- a/Documentation/Synergy.Documentation/Api/Dependencies.cs +++ b/Documentation/Synergy.Documentation/Api/Dependencies.cs @@ -6,19 +6,41 @@ namespace Synergy.Documentation.Api; public class Dependencies { - public static List Of(Type root) + private readonly bool includeNested; + + public static List Of(Type root, bool includeNested = false) { - return new Dependencies().DependenciesOf(root) - .ToList(); + return new Dependencies(includeNested) + .DependenciesOf(root) + .ToList(); } private readonly List visited = new(100); - - private IEnumerable DependenciesOf(Type type) + + private Dependencies(bool includeNested) { - return this.DependenciesOf(type, 0); + this.includeNested = includeNested; } - + + public IEnumerable DependenciesOf(Type type) + { + var roots = new List(); + roots.Add(type); + + if (this.includeNested) + { + roots.AddRange(type.GetNestedTypes(BindingFlags.Public)); + } + + foreach (Type root in roots) + { + foreach (var dependency in this.DependenciesOf(root, 0)) + { + yield return dependency; + } + } + } + private IEnumerable DependenciesOf(Type type, int level) { var underlyingType = Nullable.GetUnderlyingType(type); @@ -36,14 +58,15 @@ private IEnumerable DependenciesOf(Type type, int level) this.visited.Add(type); yield return type; } - + if (type.IsArray) { type = type.GetElementType(); } else if (type.IsAssignableTo(typeof(IEnumerable))) { - if (type.GetGenericArguments().Length == 0) + if (type.GetGenericArguments() + .Length == 0) yield break; type = type.GetGenericArguments() @@ -64,7 +87,7 @@ private IEnumerable DependenciesOf(Type type, int level) foreach (var property in this.GetPropertiesOf(type)) { - foreach (var dependency in this.DependenciesOf(property.PropertyType)) + foreach (var dependency in this.DependenciesOf(property.PropertyType, level + 1)) { yield return dependency; }