/// <summary> /// Fetches the annotations specified in the operation-level config and applies them to the specified operations. /// </summary> /// <param name="operation">The operation to be updated.</param> /// <param name="element">The xml element containing operation-level config in the config xml.</param> /// <param name="settings">The operation config filter settings.</param> public void Apply(OpenApiOperation operation, XElement element, OperationConfigFilterSettings settings) { var annotationElements = element.Descendants().Where(i => i.Name == KnownXmlStrings.Annotation); foreach (var annotationElement in annotationElements) { var targetedTag = annotationElement.Attribute(KnownXmlStrings.Tag); // Only proceed if the target tag is null (indicating that the annotation applies to all operations) // or if the target tag matches with tags in this operation. if (targetedTag != null && !operation.Tags.Select(t => t.Name) .Contains(targetedTag.Value.Trim(), StringComparer.InvariantCultureIgnoreCase)) { continue; } foreach (var operationFilter in settings.OperationFilters) { operationFilter.Apply( operation, annotationElement, settings.OperationFilterSettings); } } }
/// <summary> /// Fetches the annotations specified in the operation-level config and applies them to the specified operations. /// </summary> /// <param name="operation">The operation to be updated.</param> /// <param name="element">The xml element containing operation-level config in the config xml.</param> /// <param name="settings">The operation config filter settings.</param> /// <returns>The list of generation errors, if any produced when processing the filter.</returns> public IList <GenerationError> Apply( OpenApiOperation operation, XElement element, OperationConfigFilterSettings settings) { var generationErrors = new List <GenerationError>(); try { var annotationElements = element.Descendants().Where(i => i.Name == KnownXmlStrings.Annotation); foreach (var annotationElement in annotationElements) { var targetedTag = annotationElement.Attribute(KnownXmlStrings.Tag); // Only proceed if the target tag is null (indicating that the annotation applies to all operations) // or if the target tag matches with tags in this operation. if (targetedTag != null && !operation.Tags.Select(t => t.Name) .Contains(targetedTag.Value.Trim(), StringComparer.InvariantCultureIgnoreCase)) { continue; } foreach (var operationFilter in settings.OperationFilters) { operationFilter.Apply( operation, annotationElement, settings.OperationFilterSettings); } } } catch (Exception ex) { generationErrors.Add( new GenerationError { Message = ex.Message, ExceptionType = ex.GetType().Name }); } return(generationErrors); }