public void RemarksToDescriptionFilterShouldSucceed( string testName, XElement xElement, OpenApiOperation expectedOpenApiOperation) { var filter = new RemarksToDescriptionFilter(); var settings = new OperationFilterSettings(); var openApiOperation = new OpenApiOperation(); _output.WriteLine(testName); filter.Apply(openApiOperation, xElement, settings); // Operation should be populated with description openApiOperation.Should().BeEquivalentTo(expectedOpenApiOperation); }
/// <summary> /// Add operation and update the operation filter settings based on the given document variant info. /// </summary> private void AddOperation( IDictionary <DocumentVariantInfo, OpenApiDocument> specificationDocuments, IDictionary <DocumentVariantInfo, ReferenceRegistryManager> referenceRegistryManagerMap, IList <GenerationError> operationGenerationErrors, DocumentVariantInfo documentVariantInfo, XElement operationElement, XElement operationConfigElement, TypeFetcher typeFetcher) { var paths = new OpenApiPaths(); foreach (var preprocessingOperationFilter in _preProcessingOperationFilters) { try { preprocessingOperationFilter.Apply( paths, operationElement, new PreProcessingOperationFilterSettings()); } catch (Exception e) { operationGenerationErrors.Add( new GenerationError { ExceptionType = e.GetType().Name, Message = e.Message } ); } } if (!referenceRegistryManagerMap.ContainsKey(documentVariantInfo)) { referenceRegistryManagerMap[documentVariantInfo] = new ReferenceRegistryManager(_openApiDocumentGenerationSettings); } foreach (var pathToPathItem in paths) { var path = pathToPathItem.Key; var pathItem = pathToPathItem.Value; foreach (var operationMethodToOperation in pathItem.Operations) { var operationMethod = operationMethodToOperation.Key; var operation = operationMethodToOperation.Value; var operationFilterSettings = new OperationFilterSettings { TypeFetcher = typeFetcher, ReferenceRegistryManager = referenceRegistryManagerMap[documentVariantInfo], Path = path, OperationMethod = operationMethod.ToString() }; // Apply all the operation-related filters to extract information related to the operation. // It is important that these are applied before the config filters below // since the config filters may rely on information generated from operation filters. foreach (var operationFilter in _operationFilters) { try { operationFilter.Apply( operation, operationElement, operationFilterSettings); } catch (Exception e) { operationGenerationErrors.Add( new GenerationError { ExceptionType = e.GetType().Name, Message = e.Message } ); } } if (operationConfigElement != null) { // Apply the config-related filters to extract information from the config xml // that can be applied to the operations. foreach (var configFilter in _operationConfigFilters) { try { configFilter.Apply( operation, operationConfigElement, new OperationConfigFilterSettings { OperationFilterSettings = operationFilterSettings, OperationFilters = _operationFilters }); } catch (Exception e) { operationGenerationErrors.Add( new GenerationError { ExceptionType = e.GetType().Name, Message = e.Message } ); } } } // Add the processed operation to the specification document. if (!specificationDocuments.ContainsKey(documentVariantInfo)) { specificationDocuments.Add( documentVariantInfo, new OpenApiDocument { Components = new OpenApiComponents(), Paths = new OpenApiPaths() }); } // Copy operations from local Paths object to the Paths in the specification document. var documentPaths = specificationDocuments[documentVariantInfo].Paths; if (!documentPaths.ContainsKey(path)) { documentPaths.Add( path, new OpenApiPathItem { Operations = { [operationMethod] = operation } }); } else { if (documentPaths[path].Operations.ContainsKey(operationMethod)) { throw new DuplicateOperationException( path, operationMethod.ToString(), documentVariantInfo.Title); } documentPaths[path].Operations.Add(operationMethod, operation); } } } }