Example #1
0
 public static IEnumerable <ILocatedOpenApiElement> GetElementAnnotations(this SyntaxNode node,
                                                                          IOpenApiElementRegistry elementRegistry)
 {
     foreach (SyntaxAnnotation annotation in node.GetAnnotations(_annotationTypes.Keys)
              .Where(p => p.Data != null))
     {
         Type elementType = _annotationTypes[annotation.Kind !];
Example #2
0
        public static string GetMessageWithSource(this Diagnostic diagnostic, IOpenApiElementRegistry elementRegistry)
        {
            string?source = diagnostic.GetSource(elementRegistry);

            return(source == null
                ? diagnostic.ToString()
                : $"{source} {diagnostic}");
        }
Example #3
0
        public static string?GetSource(this Diagnostic diagnostic, IOpenApiElementRegistry elementRegistry)
        {
            if (diagnostic == null)
            {
                throw new ArgumentNullException(nameof(diagnostic));
            }
            if (elementRegistry == null)
            {
                throw new ArgumentNullException(nameof(elementRegistry));
            }

            SyntaxTree?syntaxTree = diagnostic.Location.SourceTree;

            if (syntaxTree == null)
            {
                return(null);
            }

            CompilationUnitSyntax compilationUnit = syntaxTree.GetCompilationUnitRoot();

            return(compilationUnit.GetResourceNameAnnotation()
                   ?? compilationUnit.GetElementAnnotations(elementRegistry).FirstOrDefault()?.ToString());
        }
 public OpenApiCompilationEnricher(IOpenApiElementRegistry elementRegistry,
                                   IEnumerable <IOpenApiSyntaxNodeEnricher> enrichers)
 {
     _elementRegistry = elementRegistry ?? throw new ArgumentNullException(nameof(elementRegistry));
     _enrichers       = enrichers.ToArray();
 }
Example #5
0
 public static TSyntaxNode AddElementAnnotation <TSyntaxNode, TElement>(this TSyntaxNode node,
                                                                        ILocatedOpenApiElement <TElement> element, IOpenApiElementRegistry elementRegistry)
     where TSyntaxNode : SyntaxNode
     where TElement : IOpenApiElement =>
 node.WithAdditionalAnnotations(
     new SyntaxAnnotation(typeof(TElement).Name, elementRegistry.Add(element)));
Example #6
0
        public static ILocatedOpenApiElement <TElement>?GetElementAnnotation <TElement>(this SyntaxNode node,
                                                                                        IOpenApiElementRegistry elementRegistry)
            where TElement : IOpenApiElement
        {
            string?key = node.GetAnnotations(typeof(TElement).Name).FirstOrDefault()?.Data;

            if (key == null)
            {
                return(null);
            }

            return(elementRegistry.TryGet <TElement>(key, out var element)
                ? element
                : null);
        }
 public JsonOptionalPropertyEnricher(IOpenApiElementRegistry elementRegistry)
 {
     _elementRegistry = elementRegistry ?? throw new ArgumentNullException(nameof(elementRegistry));
 }