99using Microsoft . OpenApi . Extensions ;
1010using Microsoft . OpenApi . Models ;
1111using Microsoft . OpenApi . Readers ;
12+ using Microsoft . OpenApi . Services ;
13+ using Microsoft . OpenApi . Validations ;
1214
1315namespace Microsoft . OpenApi . Workbench
1416{
@@ -19,6 +21,8 @@ public class MainModel : INotifyPropertyChanged
1921 {
2022 private string _input ;
2123
24+ private string _inputFile ;
25+
2226 private string _output ;
2327
2428 private string _errors ;
@@ -47,6 +51,16 @@ public string Input
4751 }
4852 }
4953
54+ public string InputFile
55+ {
56+ get => _inputFile ;
57+ set
58+ {
59+ _inputFile = value ;
60+ OnPropertyChanged ( nameof ( InputFile ) ) ;
61+ }
62+ }
63+
5064 public string Output
5165 {
5266 get => _output ;
@@ -149,16 +163,30 @@ protected void OnPropertyChanged(string propertyName)
149163 /// The core method of the class.
150164 /// Runs the parsing and serializing.
151165 /// </summary>
152- internal void Validate ( )
166+ internal void ParseDocument ( )
153167 {
154168 try
155169 {
156- var stream = CreateStream ( _input ) ;
170+ Stream stream ;
171+ if ( ! String . IsNullOrWhiteSpace ( _inputFile ) )
172+ {
173+ stream = new FileStream ( _inputFile , FileMode . Open ) ;
174+ }
175+ else
176+ {
177+ stream = CreateStream ( _input ) ;
178+ }
179+
157180
158181 var stopwatch = new Stopwatch ( ) ;
159182 stopwatch . Start ( ) ;
160183
161- var document = new OpenApiStreamReader ( ) . Read ( stream , out var context ) ;
184+ var document = new OpenApiStreamReader ( new OpenApiReaderSettings
185+ {
186+ ReferenceResolution = ReferenceResolutionSetting . ResolveLocalReferences ,
187+ RuleSet = ValidationRuleSet . GetDefaultRuleSet ( )
188+ }
189+ ) . Read ( stream , out var context ) ;
162190 stopwatch . Stop ( ) ;
163191 ParseTime = $ "{ stopwatch . ElapsedMilliseconds } ms";
164192
@@ -184,6 +212,12 @@ internal void Validate()
184212 stopwatch . Stop ( ) ;
185213
186214 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 ( ) ;
187221 }
188222 catch ( Exception ex )
189223 {
0 commit comments