33
44using System . IO ;
55using System . Linq ;
6+ using Microsoft . OpenApi . Extensions ;
67using Microsoft . OpenApi . Models ;
78using Microsoft . OpenApi . Readers . Interface ;
9+ using Microsoft . OpenApi . Services ;
10+ using Microsoft . OpenApi . Validations ;
811using SharpYaml ;
912using SharpYaml . Serialization ;
1013
@@ -15,7 +18,17 @@ namespace Microsoft.OpenApi.Readers
1518 /// </summary>
1619 public class OpenApiStreamReader : IOpenApiReader < Stream , OpenApiDiagnostic >
1720 {
21+ private OpenApiReaderSettings _settings ;
1822
23+ /// <summary>
24+ /// Create stream reader with custom settings if desired.
25+ /// </summary>
26+ /// <param name="settings"></param>
27+ public OpenApiStreamReader ( OpenApiReaderSettings settings = null )
28+ {
29+ _settings = settings ?? new OpenApiReaderSettings ( ) ;
30+
31+ }
1932 /// <summary>
2033 /// Reads the stream input and parses it into an Open API document.
2134 /// </summary>
@@ -28,6 +41,7 @@ public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic)
2841 YamlDocument yamlDocument ;
2942 diagnostic = new OpenApiDiagnostic ( ) ;
3043
44+ // Parse the YAML/JSON
3145 try
3246 {
3347 yamlDocument = LoadYamlDocument ( input ) ;
@@ -38,8 +52,22 @@ public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic)
3852 return new OpenApiDocument ( ) ;
3953 }
4054
41- context = new ParsingContext ( ) ;
42- return context . Parse ( yamlDocument , diagnostic ) ;
55+ context = new ParsingContext
56+ {
57+ ExtensionParsers = _settings . ExtensionParsers
58+ } ;
59+
60+ // Parse the OpenAPI Document
61+ var document = context . Parse ( yamlDocument , diagnostic ) ;
62+
63+ // Validate the document
64+ var errors = document . Validate ( _settings . RuleSet ) ;
65+ foreach ( var item in errors )
66+ {
67+ diagnostic . Errors . Add ( new OpenApiError ( item . ErrorPath , item . ErrorMessage ) ) ;
68+ }
69+
70+ return document ;
4371 }
4472
4573 /// <summary>
0 commit comments