static void Main(string[] args) { try { RefreshOutputDirectory(); // start building up the yaml file using (StreamReader sr = File.OpenText($"{_specDirectory}/swagger.yaml")) { using (TextWriter writer = File.CreateText(_yamlOutputFile)) { var s = ""; while ((s = sr.ReadLine()) != null) { writer.WriteLine(s); } } } // append paths and components to yaml file AddPaths(); AddAllComponents(); // use openapi.net to read yaml file var str = File.ReadAllText(_yamlOutputFile); var openApiDocument = new OpenApiStringReader().Read(str, out var diagnostic); // log any errors foreach (var error in diagnostic.Errors) { Console.WriteLine(error.Message); Console.WriteLine(error.Pointer); } // convert yaml file to json using (TextWriter writer = File.CreateText(_jsonOutputFile)) { openApiDocument.SerializeAsV3(new OpenApiJsonWriter(writer)); } } catch (Exception e) { Console.WriteLine(e); throw; } }