9
9
using Microsoft . OpenApi . Extensions ;
10
10
using Microsoft . OpenApi . Models ;
11
11
using Microsoft . OpenApi . Readers ;
12
+ using Microsoft . OpenApi . Services ;
13
+ using Microsoft . OpenApi . Validations ;
12
14
13
15
namespace Microsoft . OpenApi . Workbench
14
16
{
@@ -19,6 +21,8 @@ public class MainModel : INotifyPropertyChanged
19
21
{
20
22
private string _input ;
21
23
24
+ private string _inputFile ;
25
+
22
26
private string _output ;
23
27
24
28
private string _errors ;
@@ -47,6 +51,16 @@ public string Input
47
51
}
48
52
}
49
53
54
+ public string InputFile
55
+ {
56
+ get => _inputFile ;
57
+ set
58
+ {
59
+ _inputFile = value ;
60
+ OnPropertyChanged ( nameof ( InputFile ) ) ;
61
+ }
62
+ }
63
+
50
64
public string Output
51
65
{
52
66
get => _output ;
@@ -149,16 +163,30 @@ protected void OnPropertyChanged(string propertyName)
149
163
/// The core method of the class.
150
164
/// Runs the parsing and serializing.
151
165
/// </summary>
152
- internal void Validate ( )
166
+ internal void ParseDocument ( )
153
167
{
154
168
try
155
169
{
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
+
157
180
158
181
var stopwatch = new Stopwatch ( ) ;
159
182
stopwatch . Start ( ) ;
160
183
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 ) ;
162
190
stopwatch . Stop ( ) ;
163
191
ParseTime = $ "{ stopwatch . ElapsedMilliseconds } ms";
164
192
@@ -184,6 +212,12 @@ internal void Validate()
184
212
stopwatch . Stop ( ) ;
185
213
186
214
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 ( ) ;
187
221
}
188
222
catch ( Exception ex )
189
223
{
0 commit comments