private IDictionary <string, XsdFileInformation> ParseAssemblies() { var assemblies = _assembliesProvider.GetAssemblies() .Where(x => !x.IsDynamic) .ToList(); var assemblySchemaInformationByUriSegment = new Dictionary <string, XsdFileInformation>(StringComparer.InvariantCultureIgnoreCase); foreach (var assembly in assemblies) { string[] manifestResourceNames = assembly.GetManifestResourceNames(); string assemblyName = assembly.GetName().Name; _logger.Debug($"Checking assembly '{assemblyName}'"); string apiModelFileName = $"{assemblyName}.Artifacts.Metadata.ApiModel.json"; string extensionApiModelFileName = $"{assemblyName}.Artifacts.Metadata.ApiModel-EXTENSION.json"; if (!manifestResourceNames.Any( x => x.ContainsIgnoreCase(apiModelFileName) || x.ContainsIgnoreCase(extensionApiModelFileName))) { continue; } _logger.Debug($"Assembly '{assemblyName} has an 'ApiModel.json'"); var stream = manifestResourceNames.Any(x => x.ContainsIgnoreCase(apiModelFileName)) ? new StreamReader(assembly.GetManifestResourceStream(apiModelFileName)) : new StreamReader(assembly.GetManifestResourceStream(extensionApiModelFileName)); var apiModel = JsonConvert.DeserializeObject <Dictionary <string, object> >(stream.ReadToEnd()); var schemaInfo = apiModel["schemaDefinition"].ToDictionary(); var assemblySchemaInformation = new XsdFileInformation( assemblyName, schemaInfo["version"].ToString(), _schemaNameMapProvider.GetSchemaMapByLogicalName(schemaInfo["logicalName"].ToString()), manifestResourceNames .Where(x => x.StartsWithIgnoreCase($"{assemblyName}.Artifacts.Schemas")) .Select(x => x.Replace($"{assemblyName}.Artifacts.Schemas.", string.Empty)) .ToArray() ); _logger.Debug(assemblySchemaInformation); assemblySchemaInformationByUriSegment.Add( assemblySchemaInformation.SchemaNameMap.UriSegment, assemblySchemaInformation); } return(assemblySchemaInformationByUriSegment); }
public void Should_be_a_valid_swagger_document_for_each_extension_schema_in_the_domain_model() { var extensionUriSegments = DomainModelProvider.GetDomainModel() .Schemas.Select( d => _schemaNameMapProvider.GetSchemaMapByLogicalName(d.LogicalName) .UriSegment) .Where( s => !s.Equals(EdFiConventions.UriSegment)); Assert.That(_actualMetadata.Select(m => m.Name), Is.EquivalentTo(extensionUriSegments)); }
private IEnumerable <OpenApiContent> CreateSchemaSpecificSections() { return(new[] { new OpenApiContent( OpenApiMetadataSections.SdkGen, EdFi, new Lazy <string>( () => new SwaggerDocumentFactory( new SwaggerDocumentContext(_resourceModelProvider.GetResourceModel()) { RenderType = RenderType.GeneralizedExtensions, IsIncludedExtension = x => x.FullName.Schema.Equals(EdFiConventions.PhysicalSchemaName) }).Create(_openApiMetadataResourceFilters[EdFi])), _odsDataBasePath) }.Concat( _domainModelProvider.GetDomainModel() // All the extension schemas. .Schemas.Where( x => !x.LogicalName.EqualsIgnoreCase(EdFiConventions.LogicalName)) .Select( schema => new { UriSegment = _schemaNameMapProvider.GetSchemaMapByLogicalName(schema.LogicalName) .UriSegment, Factory = SwaggerDocumentFactoryHelper.GetExtensionOnlySwaggerDocumentFactory( _resourceModelProvider.GetResourceModel(), schema) }) .Select( sf => new OpenApiContent( OpenApiMetadataSections.Extensions, sf.UriSegment, new Lazy <string>(() => sf.Factory.Create(_openApiMetadataResourceFilters[Extensions])), _odsDataBasePath)) )); }
public void Should_Contain_Resource_Definitions_For_All_Schemas() { var expectedSchemaPrefixes = DomainModelDefinitionsProviderHelper .DomainModelProvider .GetDomainModel() .Schemas .Select( d => _schemaNameMapProvider.GetSchemaMapByLogicalName(d.LogicalName) .ProperCaseName) .Select(p => $"{p}".ToCamelCase()) .ToList(); var actualSchemaPrefixes = _actualDefinitions.Select(d => d.Key) .Where( d => !d.EndsWithIgnoreCase( "Extensions")) .Except( new[] { "link" }) .Select( d => d.Split('_') .First()) .Distinct() .ToList(); var missingSchemaPrefixes = expectedSchemaPrefixes.Except(actualSchemaPrefixes); var extraSchemaPrefixes = actualSchemaPrefixes.Except(expectedSchemaPrefixes); Assert.That( missingSchemaPrefixes, Is.Empty, $"The following schemas were not found in actual definitions: {string.Join(", ", missingSchemaPrefixes)}"); Assert.That( extraSchemaPrefixes, Is.Empty, $"The following schemas should not have been included in actual definitions: {string.Join(", ", extraSchemaPrefixes)}"); }