- 
                Notifications
    You must be signed in to change notification settings 
- Fork 270
Adds support for generating Mermaid diagrams from APIs #1113
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            36 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      e517053
              
                Added show command
              
              
                darrelmiller 49a12f3
              
                Moved mermaid writer into OpenApiUrlTreeNode and fixed more sanitizat…
              
              
                darrelmiller 8781884
              
                Added shapes for better accessibility
              
              
                darrelmiller 0bc1726
              
                Update to do a unnecessary using
              
              
                darrelmiller e8061ac
              
                Update src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
              
              
                darrelmiller 5a7146c
              
                Update src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
              
              
                darrelmiller fc3ba5e
              
                Added a bunch of usings and removed an unnecessary flush to address c…
              
              
                darrelmiller 6c57e8d
              
                Fixed broken order method
              
              
                darrelmiller 9e2ff51
              
                Update src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
              
              
                darrelmiller efeeca7
              
                Update src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
              
              
                darrelmiller 5d87820
              
                Update src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs
              
              
                darrelmiller 674fe14
              
                Changed mermaid styles to make them readonly
              
              
                darrelmiller 931270f
              
                Fixed data in broken test
              
              
                darrelmiller 079da0f
              
                Updated public API
              
              
                darrelmiller 3f59784
              
                Refactored OpenAPIService to remove duplicate code
              
              
                darrelmiller e0d08f8
              
                Added tests for mermaid diagrams
              
              
                darrelmiller b61edcf
              
                Updated diagram test to cover more scenarios
              
              
                darrelmiller 6a53f24
              
                Merge remote-tracking branch 'origin/vnext' into dm/show
              
              
                darrelmiller 8a9305b
              
                Added test for show command
              
              
                darrelmiller b0af526
              
                Refactored to improve test coverage
              
              
                darrelmiller 776e98f
              
                Change test to call sync invoke
              
              
                darrelmiller 5bc0bd4
              
                Added back missing parameter config options in parseopenapi
              
              
                darrelmiller 5ee6095
              
                Updated SanitizeMermaidNode to handle cases found in Microsoft Graph …
              
              
                darrelmiller a7c4983
              
                Removed Task.Delay as no longer necessary. #1127
              
              
                darrelmiller 7aac03f
              
                Updated commands to enable reading from CSDL url for both transform a…
              
              
                darrelmiller 8e2d470
              
                Used random file in a hidi folder to address security concerns.
              
              
                darrelmiller c23694c
              
                Fixed code smell relating to LogError
              
              
                darrelmiller 6a3dd01
              
                Added test to call Transform command directly so that code coverage w…
              
              
                darrelmiller 8ff70a1
              
                Removed unnecessary test that was breaking
              
              
                darrelmiller b95cda3
              
                This time I included the change
              
              
                darrelmiller 230af2f
              
                Added missing comments for public APIs
              
              
                darrelmiller 2b82a74
              
                Added more tests to meet the coverage gods
              
              
                darrelmiller 4537239
              
                More sacrifices made
              
              
                darrelmiller 96fae88
              
                Will these be the tests that achieve the magical goal?
              
              
                darrelmiller 7638805
              
                I am confidence I have enough tests now
              
              
                darrelmiller a8a693d
              
                Added a using to dispose a StreamReader
              
              
                darrelmiller File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|  | ||
| using System; | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using System.IO; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.Logging; | ||
|  | ||
| namespace Microsoft.OpenApi.Hidi.Handlers | ||
| { | ||
| internal class ShowCommandHandler : ICommandHandler | ||
| { | ||
| public Option<string> DescriptionOption { get; set; } | ||
| public Option<FileInfo> OutputOption { get; set; } | ||
| public Option<LogLevel> LogLevelOption { get; set; } | ||
| public Option<string> CsdlOption { get; set; } | ||
| public Option<string> CsdlFilterOption { get; set; } | ||
|  | ||
|  | ||
| public int Invoke(InvocationContext context) | ||
| { | ||
| return InvokeAsync(context).GetAwaiter().GetResult(); | ||
| } | ||
| public async Task<int> InvokeAsync(InvocationContext context) | ||
| { | ||
| string openapi = context.ParseResult.GetValueForOption(DescriptionOption); | ||
| FileInfo output = context.ParseResult.GetValueForOption(OutputOption); | ||
| LogLevel logLevel = context.ParseResult.GetValueForOption(LogLevelOption); | ||
| string csdlFilter = context.ParseResult.GetValueForOption(CsdlFilterOption); | ||
| string csdl = context.ParseResult.GetValueForOption(CsdlOption); | ||
| CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken)); | ||
|  | ||
| using var loggerFactory = Logger.ConfigureLogger(logLevel); | ||
| var logger = loggerFactory.CreateLogger<OpenApiService>(); | ||
| try | ||
| { | ||
| await OpenApiService.ShowOpenApiDocument(openapi, csdl, csdlFilter, output, logger, cancellationToken); | ||
|  | ||
| return 0; | ||
| } | ||
| 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 | ||
| } | ||
| } | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Check notice
Code scanning / CodeQL
Generic catch clause