Skip to content

Commit b532b1a

Browse files
committed
Added stats to workbench
1 parent 9436718 commit b532b1a

File tree

3 files changed

+228
-132
lines changed

3 files changed

+228
-132
lines changed

src/Microsoft.OpenApi.Workbench/MainModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.OpenApi.Extensions;
1010
using Microsoft.OpenApi.Models;
1111
using Microsoft.OpenApi.Readers;
12+
using Microsoft.OpenApi.Services;
1213
using Microsoft.OpenApi.Validations;
1314

1415
namespace Microsoft.OpenApi.Workbench
@@ -211,6 +212,12 @@ internal void Validate()
211212
stopwatch.Stop();
212213

213214
RenderTime = $"{stopwatch.ElapsedMilliseconds} ms";
215+
216+
var statsVisitor = new StatsVisitor();
217+
var walker = new OpenApiWalker(statsVisitor);
218+
walker.Walk(document);
219+
220+
Errors += Environment.NewLine + "Statistics:" + Environment.NewLine + statsVisitor.GetStatisticsReport();
214221
}
215222
catch (Exception ex)
216223
{
Lines changed: 133 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,136 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4-
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{6A5E91E5-0441-46EE-AEB9-8334981B7F08}</ProjectGuid>
8-
<OutputType>WinExe</OutputType>
9-
<RootNamespace>Microsoft.OpenApi.Workbench</RootNamespace>
10-
<AssemblyName>Microsoft.OpenApi.Workbench</AssemblyName>
11-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12-
<FileAlignment>512</FileAlignment>
13-
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14-
<WarningLevel>4</WarningLevel>
15-
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16-
<TargetFrameworkProfile />
17-
<NuGetPackageImportStamp>
18-
</NuGetPackageImportStamp>
19-
</PropertyGroup>
20-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21-
<PlatformTarget>AnyCPU</PlatformTarget>
22-
<DebugSymbols>true</DebugSymbols>
23-
<DebugType>full</DebugType>
24-
<Optimize>false</Optimize>
25-
<OutputPath>bin\Debug\</OutputPath>
26-
<DefineConstants>DEBUG;TRACE</DefineConstants>
27-
<ErrorReport>prompt</ErrorReport>
28-
<WarningLevel>4</WarningLevel>
29-
</PropertyGroup>
30-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
31-
<PlatformTarget>AnyCPU</PlatformTarget>
32-
<DebugType>pdbonly</DebugType>
33-
<Optimize>true</Optimize>
34-
<OutputPath>bin\Release\</OutputPath>
35-
<DefineConstants>TRACE</DefineConstants>
36-
<ErrorReport>prompt</ErrorReport>
37-
<WarningLevel>4</WarningLevel>
38-
</PropertyGroup>
39-
<ItemGroup>
40-
<Reference Include="System" />
41-
<Reference Include="System.Data" />
42-
<Reference Include="System.Xml" />
43-
<Reference Include="Microsoft.CSharp" />
44-
<Reference Include="System.Core" />
45-
<Reference Include="System.Xml.Linq" />
46-
<Reference Include="System.Data.DataSetExtensions" />
47-
<Reference Include="System.Net.Http" />
48-
<Reference Include="System.Xaml">
49-
<RequiredTargetFramework>4.0</RequiredTargetFramework>
50-
</Reference>
51-
<Reference Include="WindowsBase" />
52-
<Reference Include="PresentationCore" />
53-
<Reference Include="PresentationFramework" />
54-
<PackageReference Include="Infragistics.Themes.MetroLight.Wpf" Version="1.0.0" />
55-
</ItemGroup>
56-
<ItemGroup>
57-
<ApplicationDefinition Include="App.xaml">
58-
<Generator>MSBuild:Compile</Generator>
59-
<SubType>Designer</SubType>
60-
</ApplicationDefinition>
61-
<Page Include="MainWindow.xaml">
62-
<Generator>MSBuild:Compile</Generator>
63-
<SubType>Designer</SubType>
64-
</Page>
65-
<Compile Include="App.xaml.cs">
66-
<DependentUpon>App.xaml</DependentUpon>
67-
<SubType>Code</SubType>
68-
</Compile>
69-
<Compile Include="MainModel.cs" />
70-
<Compile Include="MainWindow.xaml.cs">
71-
<DependentUpon>MainWindow.xaml</DependentUpon>
72-
<SubType>Code</SubType>
73-
</Compile>
74-
<Resource Include="Themes\Metro\Metro.MSControls.Core.Implicit.xaml">
75-
<Generator>MSBuild:Compile</Generator>
76-
<SubType>Designer</SubType>
77-
</Resource>
78-
<Resource Include="Themes\Metro\Metro.MSControls.Toolkit.Implicit.xaml">
79-
<Generator>MSBuild:Compile</Generator>
80-
<SubType>Designer</SubType>
81-
</Resource>
82-
<Resource Include="Themes\Metro\Styles.Shared.xaml">
83-
<Generator>MSBuild:Compile</Generator>
84-
<SubType>Designer</SubType>
85-
</Resource>
86-
<Resource Include="Themes\Metro\Styles.WPF.xaml">
87-
<Generator>MSBuild:Compile</Generator>
88-
<SubType>Designer</SubType>
89-
</Resource>
90-
<Resource Include="Themes\Metro\Theme.Colors.xaml">
91-
<Generator>MSBuild:Compile</Generator>
92-
<SubType>Designer</SubType>
93-
</Resource>
94-
</ItemGroup>
95-
<ItemGroup>
96-
<Compile Include="Properties\AssemblyInfo.cs">
97-
<SubType>Code</SubType>
98-
</Compile>
99-
<Compile Include="Properties\Resources.Designer.cs">
100-
<AutoGen>True</AutoGen>
101-
<DesignTime>True</DesignTime>
102-
<DependentUpon>Resources.resx</DependentUpon>
103-
</Compile>
104-
<Compile Include="Properties\Settings.Designer.cs">
105-
<AutoGen>True</AutoGen>
106-
<DependentUpon>Settings.settings</DependentUpon>
107-
<DesignTimeSharedInput>True</DesignTimeSharedInput>
108-
</Compile>
109-
<EmbeddedResource Include="Properties\Resources.resx">
110-
<Generator>ResXFileCodeGenerator</Generator>
111-
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
112-
</EmbeddedResource>
113-
<None Include="Properties\Settings.settings">
114-
<Generator>SettingsSingleFileGenerator</Generator>
115-
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
116-
</None>
117-
</ItemGroup>
118-
<ItemGroup>
119-
<None Include="App.config" />
120-
</ItemGroup>
121-
<ItemGroup>
122-
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />
123-
</ItemGroup>
124-
<ItemGroup>
125-
<ProjectReference Include="..\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj">
126-
<Project>{79933258-0126-4382-8755-d50820ecc483}</Project>
127-
<Name>Microsoft.OpenApi.Readers</Name>
128-
</ProjectReference>
129-
<ProjectReference Include="..\Microsoft.OpenApi\Microsoft.OpenApi.csproj">
130-
<Project>{a8e50143-69b2-472a-9d45-3f9a05d13202}</Project>
131-
<Name>Microsoft.OpenApi.Core</Name>
132-
</ProjectReference>
133-
</ItemGroup>
134-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{6A5E91E5-0441-46EE-AEB9-8334981B7F08}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>Microsoft.OpenApi.Workbench</RootNamespace>
10+
<AssemblyName>Microsoft.OpenApi.Workbench</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
<TargetFrameworkProfile />
17+
<NuGetPackageImportStamp>
18+
</NuGetPackageImportStamp>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<PlatformTarget>AnyCPU</PlatformTarget>
22+
<DebugSymbols>true</DebugSymbols>
23+
<DebugType>full</DebugType>
24+
<Optimize>false</Optimize>
25+
<OutputPath>bin\Debug\</OutputPath>
26+
<DefineConstants>DEBUG;TRACE</DefineConstants>
27+
<ErrorReport>prompt</ErrorReport>
28+
<WarningLevel>4</WarningLevel>
29+
</PropertyGroup>
30+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
31+
<PlatformTarget>AnyCPU</PlatformTarget>
32+
<DebugType>pdbonly</DebugType>
33+
<Optimize>true</Optimize>
34+
<OutputPath>bin\Release\</OutputPath>
35+
<DefineConstants>TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Reference Include="System" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Xml" />
43+
<Reference Include="Microsoft.CSharp" />
44+
<Reference Include="System.Core" />
45+
<Reference Include="System.Xml.Linq" />
46+
<Reference Include="System.Data.DataSetExtensions" />
47+
<Reference Include="System.Net.Http" />
48+
<Reference Include="System.Xaml">
49+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
50+
</Reference>
51+
<Reference Include="WindowsBase" />
52+
<Reference Include="PresentationCore" />
53+
<Reference Include="PresentationFramework" />
54+
<PackageReference Include="Infragistics.Themes.MetroLight.Wpf" Version="1.0.0" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<ApplicationDefinition Include="App.xaml">
58+
<Generator>MSBuild:Compile</Generator>
59+
<SubType>Designer</SubType>
60+
</ApplicationDefinition>
61+
<Compile Include="StatsVisitor.cs" />
62+
<Page Include="MainWindow.xaml">
63+
<Generator>MSBuild:Compile</Generator>
64+
<SubType>Designer</SubType>
65+
</Page>
66+
<Compile Include="App.xaml.cs">
67+
<DependentUpon>App.xaml</DependentUpon>
68+
<SubType>Code</SubType>
69+
</Compile>
70+
<Compile Include="MainModel.cs" />
71+
<Compile Include="MainWindow.xaml.cs">
72+
<DependentUpon>MainWindow.xaml</DependentUpon>
73+
<SubType>Code</SubType>
74+
</Compile>
75+
<Resource Include="Themes\Metro\Metro.MSControls.Core.Implicit.xaml">
76+
<Generator>MSBuild:Compile</Generator>
77+
<SubType>Designer</SubType>
78+
</Resource>
79+
<Resource Include="Themes\Metro\Metro.MSControls.Toolkit.Implicit.xaml">
80+
<Generator>MSBuild:Compile</Generator>
81+
<SubType>Designer</SubType>
82+
</Resource>
83+
<Resource Include="Themes\Metro\Styles.Shared.xaml">
84+
<Generator>MSBuild:Compile</Generator>
85+
<SubType>Designer</SubType>
86+
</Resource>
87+
<Resource Include="Themes\Metro\Styles.WPF.xaml">
88+
<Generator>MSBuild:Compile</Generator>
89+
<SubType>Designer</SubType>
90+
</Resource>
91+
<Resource Include="Themes\Metro\Theme.Colors.xaml">
92+
<Generator>MSBuild:Compile</Generator>
93+
<SubType>Designer</SubType>
94+
</Resource>
95+
</ItemGroup>
96+
<ItemGroup>
97+
<Compile Include="Properties\AssemblyInfo.cs">
98+
<SubType>Code</SubType>
99+
</Compile>
100+
<Compile Include="Properties\Resources.Designer.cs">
101+
<AutoGen>True</AutoGen>
102+
<DesignTime>True</DesignTime>
103+
<DependentUpon>Resources.resx</DependentUpon>
104+
</Compile>
105+
<Compile Include="Properties\Settings.Designer.cs">
106+
<AutoGen>True</AutoGen>
107+
<DependentUpon>Settings.settings</DependentUpon>
108+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
109+
</Compile>
110+
<EmbeddedResource Include="Properties\Resources.resx">
111+
<Generator>ResXFileCodeGenerator</Generator>
112+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
113+
</EmbeddedResource>
114+
<None Include="Properties\Settings.settings">
115+
<Generator>SettingsSingleFileGenerator</Generator>
116+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
117+
</None>
118+
</ItemGroup>
119+
<ItemGroup>
120+
<None Include="App.config" />
121+
</ItemGroup>
122+
<ItemGroup>
123+
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />
124+
</ItemGroup>
125+
<ItemGroup>
126+
<ProjectReference Include="..\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj">
127+
<Project>{79933258-0126-4382-8755-d50820ecc483}</Project>
128+
<Name>Microsoft.OpenApi.Readers</Name>
129+
</ProjectReference>
130+
<ProjectReference Include="..\Microsoft.OpenApi\Microsoft.OpenApi.csproj">
131+
<Project>{a8e50143-69b2-472a-9d45-3f9a05d13202}</Project>
132+
<Name>Microsoft.OpenApi.Core</Name>
133+
</ProjectReference>
134+
</ItemGroup>
135+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
135136
</Project>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.OpenApi.Models;
7+
using Microsoft.OpenApi.Services;
8+
9+
namespace Microsoft.OpenApi.Workbench
10+
{
11+
public class StatsVisitor : OpenApiVisitorBase
12+
{
13+
public int ParameterCount { get; set; } = 0;
14+
15+
public override void Visit(OpenApiParameter parameter)
16+
{
17+
ParameterCount++;
18+
}
19+
20+
public int SchemaCount { get; set; } = 0;
21+
22+
public override void Visit(OpenApiSchema schema)
23+
{
24+
SchemaCount++;
25+
}
26+
27+
public int HeaderCount { get; set; } = 0;
28+
29+
public override void Visit(IDictionary<string, OpenApiHeader> headers)
30+
{
31+
HeaderCount++;
32+
}
33+
34+
public int PathItemCount { get; set; } = 0;
35+
36+
public override void Visit(OpenApiPathItem pathItem)
37+
{
38+
PathItemCount++;
39+
}
40+
41+
public int RequestBodyCount { get; set; } = 0;
42+
43+
public override void Visit(OpenApiRequestBody requestBody)
44+
{
45+
RequestBodyCount++;
46+
}
47+
48+
public int ResponseCount { get; set; } = 0;
49+
50+
public override void Visit(OpenApiResponses response)
51+
{
52+
ResponseCount++;
53+
}
54+
55+
public int OperationCount { get; set; } = 0;
56+
57+
public override void Visit(OpenApiOperation operation)
58+
{
59+
OperationCount++;
60+
}
61+
62+
public int LinkCount { get; set; } = 0;
63+
64+
public override void Visit(OpenApiLink operation)
65+
{
66+
LinkCount++;
67+
}
68+
69+
public int CallbackCount { get; set; } = 0;
70+
71+
public override void Visit(OpenApiCallback callback)
72+
{
73+
CallbackCount++;
74+
}
75+
76+
public string GetStatisticsReport()
77+
{
78+
return $"Path Items: {PathItemCount}" + Environment.NewLine
79+
+ $"Operations: {OperationCount}" + Environment.NewLine
80+
+ $"Parameters: {ParameterCount}" + Environment.NewLine
81+
+ $"Request Bodies: {RequestBodyCount}" + Environment.NewLine
82+
+ $"Responses: {ResponseCount}" + Environment.NewLine
83+
+ $"Links: {LinkCount}" + Environment.NewLine
84+
+ $"Callbacks: {CallbackCount}" + Environment.NewLine
85+
+ $"Schemas: {SchemaCount}" + Environment.NewLine;
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)