public IList Apply()

in src/Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration/PostProcessingDocumentFilters/RemoveFailedGenerationOperationFilter.cs [26:77]


        public IList<GenerationError> Apply(
            OpenApiDocument openApiDocument,
            PostProcessingDocumentFilterSettings settings)
        {
            var generationErrors = new List<GenerationError>();

            try
            {
                if (openApiDocument == null || settings == null)
                {
                    return generationErrors;
                }

                // Remove all operations with generation errors except for with DuplicateOperationException as only the
                // first occurrence of the duplicate paths added to the document and rest all are never added to the document.
                foreach (var operationDiagnostic in
                    settings.OperationGenerationDiagnostics.Where(
                        operationDiagnostic => operationDiagnostic.Errors.Any()
                        && operationDiagnostic.Errors.Any(i => i.ExceptionType
                        != typeof(DuplicateOperationException).Name)))
                {
                    if (!Enum.TryParse(operationDiagnostic.OperationMethod, true, out OperationType operationMethod) ||
                        !openApiDocument.Paths.ContainsKey(operationDiagnostic.Path))
                    {
                        continue;
                    }

                    var operations = openApiDocument.Paths[operationDiagnostic.Path].Operations;

                    if (operations.Count == 1)
                    {
                        // If there is only one operation under the path and it failed generation, remove complete path.
                        openApiDocument.Paths.Remove(operationDiagnostic.Path);
                    }
                    else
                    {
                        openApiDocument.Paths[operationDiagnostic.Path].Operations.Remove(operationMethod);
                    }
                }
            }
            catch(Exception ex)
            {
                generationErrors.Add(
                   new GenerationError
                   {
                       Message = ex.Message,
                       ExceptionType = ex.GetType().Name
                   });
            }

            return generationErrors;
        }