public void TestSchemaFragmentsIterator() { // arrange var counter = new UidPropertyCounter(); var iterator = new SchemaFragmentsIterator(counter); DocumentSchema schema; using (var sr = new StreamReader("TestData/schemas/rest.mixed.schema.json")) { schema = DocumentSchema.Load(sr, "rest.mixed"); } var yamlStream = new YamlStream(); using (var sr = new StreamReader("TestData/inputs/Suppressions.yml")) { yamlStream.Load(sr); } // act iterator.Traverse(yamlStream.Documents[0].RootNode, new Dictionary <string, MarkdownFragment>(), schema); // assert Assert.Single(counter.ExistingUids); Assert.Equal("management.azure.com.advisor.suppressions", counter.ExistingUids[0]); Assert.Single(counter.ExistingMarkdownProperties); Assert.Equal("definitions[name=\"Application 1\"]/properties[name=\"id\"]/description", counter.ExistingMarkdownProperties[0]); Assert.Equal(6, counter.MissingMarkdownProperties.Count); }
private IEnumerable <IDocumentProcessor> LoadSchemaDrivenDocumentProcessors(DocumentBuildParameters parameter) { using (var resource = parameter?.TemplateManager?.CreateTemplateResource()) { if (resource == null || resource.IsEmpty) { yield break; } foreach (var pair in resource.GetResourceStreams(@"^schemas/.*\.schema\.json")) { var fileName = Path.GetFileName(pair.Key); using (new LoggerFileScope(fileName)) { using (var stream = pair.Value) { using (var sr = new StreamReader(stream)) { var schema = DocumentSchema.Load(sr, fileName.Remove(fileName.Length - ".schema.json".Length)); var sdp = new SchemaDrivenDocumentProcessor(schema, new CompositionContainer(CompositionContainer.DefaultContainer)); Logger.LogVerbose($"\t{sdp.Name} with build steps ({string.Join(", ", from bs in sdp.BuildSteps orderby bs.BuildOrder select bs.Name)})"); yield return(sdp); } } } } } }
private List <IDocumentProcessor> LoadSchemaDrivenDocumentProcessors(DocumentBuildParameters parameter) { using (new LoggerPhaseScope(nameof(LoadSchemaDrivenDocumentProcessors))) { var result = new List <IDocumentProcessor>(); SchemaValidateService.RegisterLicense(parameter.SchemaLicense); using (var resource = parameter?.TemplateManager?.CreateTemplateResource()) { if (resource == null || resource.IsEmpty) { return(result); } var markdigMarkdownService = CreateMarkdigMarkdownService(parameter); foreach (var pair in resource.GetResourceStreams(@"^schemas/.*\.schema\.json")) { var fileName = Path.GetFileName(pair.Key); using (new LoggerFileScope(fileName)) { using (var stream = pair.Value) { using (var sr = new StreamReader(stream)) { DocumentSchema schema; try { schema = DocumentSchema.Load(sr, fileName.Remove(fileName.Length - ".schema.json".Length)); } catch (Exception e) { Logger.LogError(e.Message); throw; } var sdp = new SchemaDrivenDocumentProcessor( schema, new CompositionContainer(CompositionContainer.DefaultContainer), markdigMarkdownService, new FolderRedirectionManager(parameter.OverwriteFragmentsRedirectionRules)); Logger.LogVerbose($"\t{sdp.Name} with build steps ({string.Join(", ", from bs in sdp.BuildSteps orderby bs.BuildOrder select bs.Name)})"); result.Add(sdp); } } } } } if (result.Count > 0) { Logger.LogInfo($"{result.Count} schema driven document processor plug-in(s) loaded."); Processors = Processors.Union(result); } return(result); } }
private static Dictionary <string, DocumentSchema> LoadSchemas(string schemaFolderPath) { var schemas = new Dictionary <string, DocumentSchema>(); foreach (var schemaFile in Directory.EnumerateFiles(schemaFolderPath, "*.schema.json")) { using var sr = new StreamReader(schemaFile); var schema = DocumentSchema.Load(sr, schemaFile.Remove(schemaFile.Length - ".schema.json".Length)); schemas.Add(schema.Title, schema); } return(schemas); }