protected override void Arrange() { _compositesMetadataProvider = Stub <ICompositesMetadataProvider>(); var routes = new List <XElement>(OpenApiCompositeHelper.Routes).ToReadOnlyList(); var definitions = new List <XElement>(OpenApiCompositeHelper.CompositeDefinitions).ToReadOnlyList(); A.CallTo(() => _compositesMetadataProvider.TryGetRoutes( A <string> ._, A <string> ._, out routes)) .Returns(true); A.CallTo(() => _compositesMetadataProvider.TryGetCompositeDefinitions( A <string> ._, A <string> ._, out definitions)) .Returns(true); _swaggerDocumentContext = new SwaggerDocumentContext( _resourceModelProvider.GetResourceModel()) { CompositeContext = new SwaggerCompositeContext { CategoryName = OpenApiCompositeHelper.CategoryName } }; }
protected override void Arrange() { _compositesMetadataProvider = Stub <ICompositesMetadataProvider>(); var definitions = new List <XElement>(OpenApiCompositeHelper.CompositeDefinitions).ToReadOnlyList(); var routes = new List <XElement>(OpenApiCompositeHelper.Routes).ToReadOnlyList(); A.CallTo( () => _compositesMetadataProvider.TryGetCompositeDefinitions( A <string> ._, A <string> ._, out definitions)) .Returns(true); A.CallTo( () => _compositesMetadataProvider.TryGetRoutes( A <string> ._, A <string> ._, out routes)) .Returns(true); _swaggerDocumentContext = new SwaggerDocumentContext( _resourceModelProvider.GetResourceModel()) { CompositeContext = new SwaggerCompositeContext { CategoryName = OpenApiCompositeHelper .CategoryName } }; _filteredResources = new OpenApiCompositeStrategy(_compositesMetadataProvider) .GetFilteredResources(_swaggerDocumentContext); var assessmentResource = _resourceModelProvider .GetResourceModel() .GetResourceByFullName(new FullName(EdFiConventions.PhysicalSchemaName, "Assessment")); _expectedStrategyAppliedResources = OpenApiCompositeHelper.Routes .Where(r => !IsBaseResourceRoute(r)) .Select( r => new SwaggerPathsResource(assessmentResource) { CompositeResourceContext = new CompositeResourceContext(), Path = GetCompositeResourcePath( assessmentResource, r) .ToCamelCase(), OperationId = GetCompositeResourceOperationId( assessmentResource, r), Readable = true, Writable = false }) .Concat( new[] { new SwaggerPathsResource(assessmentResource) { CompositeResourceContext = new CompositeResourceContext(), Path = $"{_swaggerDocumentContext.CompositeContext.CategoryName}/{assessmentResource.PluralName}", OperationId = "getAssessments", Readable = true, Writable = false } }); }
public IEnumerable <OpenApiMetadataResource> GetFilteredResources(OpenApiMetadataDocumentContext openApiMetadataDocumentContext) { var compositeContext = openApiMetadataDocumentContext.CompositeContext; var definitionProcessor = new CompositeDefinitionProcessor <CompositeResourceModelBuilderContext, Resource>( new CompositeResourceModelBuilder()); IReadOnlyList <XElement> compositeDefinitions; if (!_compositesMetadataProvider.TryGetCompositeDefinitions( compositeContext.OrganizationCode, compositeContext.CategoryName, out compositeDefinitions)) { return(null); } var compositeResources = new List <OpenApiMetadataResource>(); foreach (var compositeDefinition in compositeDefinitions) { // Enable this for composite xml validation. definitionProcessor.UseCompositeValidation(); var compositeResource = definitionProcessor.Process( compositeDefinition, openApiMetadataDocumentContext.ResourceModel, new CompositeResourceModelBuilderContext()); compositeResources.Add( new OpenApiMetadataResource(compositeResource) { Readable = true, CompositeResourceContext = new CompositeResourceContext { OrganizationCode = openApiMetadataDocumentContext.CompositeContext.OrganizationCode, Specification = compositeDefinition.Element("Specification"), BaseResource = compositeDefinition.Element("BaseResource").AttributeValue("name") } }); } var defaultCompositeRoutes = new List <XElement> { XElement.Parse( "<Route relativeRouteTemplate='/{compositeName}' />"), XElement.Parse( "<Route relativeRouteTemplate='/{compositeName}/{id}' />") }; // Get all route definitions for the category IReadOnlyList <XElement> routes; if (!_compositesMetadataProvider.TryGetRoutes(compositeContext.OrganizationCode, compositeContext.CategoryName, out routes)) { throw new Exception($"Composite category '{compositeContext.CategoryName}' does not have any routes defined."); } compositeContext.RouteElements = defaultCompositeRoutes.Concat(routes) .ToList(); return(compositeResources.ToList()); }