Skip to content

Commit

Permalink
#27: introduced ability to create api description for specific class …
Browse files Browse the repository at this point in the history
…with its nested classes.
  • Loading branch information
MarcinCelej committed Jan 6, 2024
1 parent f39e788 commit afb020c
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,94 @@
## Synergy.Documentation.Markup.Markdown (class)
- ctor()

## Synergy.Documentation.Markup.Markdown+IElement (interface)

## Synergy.Documentation.Markup.Markdown+Document (class) : IEnumerable<Markdown+IElement>, IEnumerable
- ctor()
- Append(
element: Markdown+IElement
) : Markdown+Document
- Append(
newElements: IEnumerable<Markdown+IElement>
) : Markdown+Document
- GetEnumerator() : IEnumerator<Markdown+IElement>
- 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

Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@
- ToString() : string

## Api.Dependencies (class)
- ctor()
- Dependencies.Of(
root: Type
root: Type,
includeNested: bool [Optional]
) : List<Type>
- DependenciesOf(
type: Type
) : IEnumerable<Type> [IteratorStateMachine]

## Code.ClassReader (class)
- ctor()
Expand Down
43 changes: 33 additions & 10 deletions Documentation/Synergy.Documentation/Api/Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,41 @@ namespace Synergy.Documentation.Api;

public class Dependencies
{
public static List<Type> Of(Type root)
private readonly bool includeNested;

public static List<Type> Of(Type root, bool includeNested = false)
{
return new Dependencies().DependenciesOf(root)
.ToList();
return new Dependencies(includeNested)
.DependenciesOf(root)
.ToList();
}

private readonly List<Type> visited = new(100);
private IEnumerable<Type> DependenciesOf(Type type)

private Dependencies(bool includeNested)
{
return this.DependenciesOf(type, 0);
this.includeNested = includeNested;
}


public IEnumerable<Type> DependenciesOf(Type type)
{
var roots = new List<Type>();
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<Type> DependenciesOf(Type type, int level)
{
var underlyingType = Nullable.GetUnderlyingType(type);
Expand All @@ -36,14 +58,15 @@ private IEnumerable<Type> 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()
Expand All @@ -64,7 +87,7 @@ private IEnumerable<Type> 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;
}
Expand Down

0 comments on commit afb020c

Please sign in to comment.