Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for generating Mermaid diagrams from APIs #1113

Merged
merged 36 commits into from
Jan 17, 2023
Merged

Conversation

darrelmiller
Copy link
Member

@darrelmiller darrelmiller commented Dec 23, 2022

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

src/Microsoft.OpenApi.Hidi/OpenApiService.cs Fixed Show fixed Hide 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
}
}

private static void WriteTreeDocument(string openapi, OpenApiDocument document, StreamWriter writer)

Check notice

Code scanning / CodeQL

Generic catch clause

Generic catch clause.
Copy link
Member

@baywet baywet left a comment

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.

src/Microsoft.OpenApi.Hidi/OpenApiService.cs Outdated Show resolved Hide resolved
src/Microsoft.OpenApi.Hidi/OpenApiService.cs Outdated Show resolved Hide resolved
src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs Outdated Show resolved Hide resolved
src/Microsoft.OpenApi.Hidi/OpenApiService.cs Outdated Show resolved Hide resolved
@darrelmiller
Copy link
Member Author

@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
Member

baywet commented Dec 28, 2022

@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.

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

@darrelmiller
Copy link
Member Author

OMG. I rebased successfully for the first time ever.

baywet
baywet previously approved these changes Jan 4, 2023
Copy link
Member

@baywet baywet left a comment

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
Member Author

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

@darrelmiller
Copy link
Member Author

darrelmiller commented Jan 12, 2023

Code coverage metric achieved. :-) /cc @MaggieKimani1 @baywet

src/Microsoft.OpenApi.Hidi/Program.cs Outdated Show resolved Hide resolved
@baywet
Copy link
Member

baywet commented Jan 12, 2023

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

@darrelmiller
Copy link
Member Author

This PR now also fixes #1124 and #1127

baywet
baywet previously requested changes Jan 16, 2023
src/Microsoft.OpenApi.Hidi/OpenApiService.cs Fixed Show resolved Hide resolved
@darrelmiller darrelmiller dismissed baywet’s stale review January 16, 2023 22:17

Because the issue was addressed

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 8 Code Smells

82.5% 82.5% Coverage
0.0% 0.0% Duplication

@darrelmiller darrelmiller merged commit 95e598b into vnext Jan 17, 2023
@darrelmiller darrelmiller deleted the dm/show branch January 17, 2023 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants