/// <summary> /// Reads the stream input and parses it into an Open API document. /// </summary> public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic) { RootNode rootNode; var context = new ParsingContext(); diagnostic = new OpenApiDiagnostic(); try { using (var streamReader = new StreamReader(input)) { var yamlStream = new YamlStream(); yamlStream.Load(streamReader); var yamlDocument = yamlStream.Documents.First(); rootNode = new RootNode(context, diagnostic, yamlDocument); } } catch (SyntaxErrorException ex) { diagnostic.Errors.Add(new OpenApiError(string.Empty, ex.Message)); return(new OpenApiDocument()); } var inputVersion = GetVersion(rootNode); switch (inputVersion) { case "2.0": context.ReferenceService = new OpenApiV2ReferenceService(rootNode); return(OpenApiV2Deserializer.LoadOpenApi(rootNode)); default: context.ReferenceService = new OpenApiV3ReferenceService(rootNode); return(OpenApiV3Deserializer.LoadOpenApi(rootNode)); } }