Skip to content

Adds support for generating Mermaid diagrams from APIs - #1113

Merged
Darrel (darrelmiller) merged 36 commits into
vnextfrom
dm/show
Jan 17, 2023
Merged

Adds support for generating Mermaid diagrams from APIs#1113
Darrel (darrelmiller) merged 36 commits into
vnextfrom
dm/show

Conversation

@darrelmiller

@darrelmillerDarrel (darrelmiller) commented Dec 23, 2022

Copy link
Copy Markdown
Member

Added a show command to the hidi command line and also added a WriteMermaid function to the OpenApiUriTreeNode class.

Examples of the output are here https://github.com/darrelmiller/openapi-collection/tree/main/ApiDiagrams

The show command wraps the mermaid in a markdown file with a legend to explain the coloring of the nodes. Each node is styled with a color that maps to the set of HTTP methods that are supported. This mapping is defined by the MermaidColorScheme dictionary on OpenApiUriTreeNode. That dictionary can be customized to change the colors or add new combinations of HTTP methods.

GitHub markdown does not render the HTML legend that the show command emits. However, the VS code markdown preview does.

This closes#820

Comment threadsrc/Microsoft.OpenApi.Hidi/OpenApiService.cs Fixed
Comment on lines +39 to +48
catch (Exception ex)
{
#if DEBUG
logger.LogCritical(ex, ex.Message);
throw; // so debug tools go straight to the source of the exception when attached
#else
logger.LogCritical( ex.Message);
return 1;
#endif
}

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.
Comment on lines +592 to +597
writer.WriteLine();
writer.WriteLine("OpenAPI: " + openapi);

writer.WriteLine(@"<div>");

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.

@baywetVincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple of comments on top of the ones already provided by codeql.
Also it seems you created your branch from master. I'd suggest rebasing from vnext for history sanity.

Comment threadsrc/Microsoft.OpenApi.Hidi/OpenApiService.cs Outdated
Comment threadsrc/Microsoft.OpenApi.Hidi/OpenApiService.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs Outdated
Comment threadsrc/Microsoft.OpenApi.Hidi/OpenApiService.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs Fixed
@darrelmiller

Copy link
Copy Markdown
MemberAuthor

Vincent Biret (@baywet) You tricked me with that .Order() method. It doesn't exist. At least my version of .NET doesn't know about it. I put the .OrderBy( o=>o) back.

@baywet

Copy link
Copy Markdown
Member

Vincent Biret (@baywet) You tricked me with that .Order() method. It doesn't exist. At least my version of .NET doesn't know about it. I put the .OrderBy( o=>o) back.

Darrel (@darrelmiller) ah right! it's an addition of .net 7, sorry about that, I'm in the future.
GlassesSunglassesGIF

Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
@darrelmiller

Copy link
Copy Markdown
MemberAuthor

OMG. I rebased successfully for the first time ever.

@baywetVincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on the rebase, I hope you used the CLI :P

@darrelmiller

Copy link
Copy Markdown
MemberAuthor

Vincent Biret (@baywet) The git CLI, yes. I was lucky because there were no merge conflicts.

@darrelmiller

Darrel (darrelmiller) commented Jan 12, 2023

Copy link
Copy Markdown
MemberAuthor

Code coverage metric achieved. :-) /cc Maggie Kimani (@MaggieKimani1)Vincent Biret (@baywet)

Comment threadsrc/Microsoft.OpenApi.Hidi/Program.cs Outdated
@baywet

Copy link
Copy Markdown
Member

good job on the coverage. I encourage you to check the code smells to wrap this up (+ the comment I left) https://sonarcloud.io/project/issues?id=microsoft_OpenAPI.NET&pullRequest=1113&resolved=false&types=CODE_SMELL

Comment threadsrc/Microsoft.OpenApi.Hidi/OpenApiService.cs Fixed
Comment threadsrc/Microsoft.OpenApi.Hidi/OpenApiService.cs Fixed
@darrelmiller

Copy link
Copy Markdown
MemberAuthor

This PR now also fixes #1124 and #1127

Comment threadsrc/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
Comment threadsrc/Microsoft.OpenApi.Hidi/OpenApiService.cs Fixed
@sonarqubecloud

Copy link
Copy Markdown

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants

@darrelmiller@baywet@MaggieKimani1@github-advanced-security