internal static Dictionary ToOpenApiHeaders()

in src/Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration/Extensions/XElementExtensions.cs [525:587]


        internal static Dictionary<string, OpenApiHeader> ToOpenApiHeaders(
            this XElement xElement,
            Dictionary<string, SchemaGenerationInfo> crefSchemaMap,
            IList<GenerationError> generationErrors)
        {
            var headerElements = xElement.Elements()
                .Where(
                    p => p.Name == KnownXmlStrings.Header)
                .ToList();

            var openApiHeaders = new Dictionary<string, OpenApiHeader>();

            foreach (var headerElement in headerElements)
            {
                var name = headerElement.Attribute(KnownXmlStrings.Name)?.Value.Trim();
                if (string.IsNullOrWhiteSpace(name))
                {
                    generationErrors.Add(new GenerationError
                    {
                        ExceptionType = nameof(InvalidHeaderException),
                        Message = string.Format(SpecificationGenerationMessages.UndocumentedName, "header")
                    });

                    return null;
                }

                var description = headerElement
                    .Elements()
                    .FirstOrDefault(p => p.Name == KnownXmlStrings.Description)?.Value.Trim().RemoveBlankLines();

                var listedTypes = headerElement.GetListedTypes();
                var crefKey = listedTypes.ToCrefKey();

                var schema = new OpenApiSchema
                {
                    Type = "string"
                };

                if (crefSchemaMap.ContainsKey(crefKey))
                {
                    var schemaInfo = crefSchemaMap[crefKey];

                    if (schemaInfo.Error != null)
                    {
                        generationErrors.Add(schemaInfo.Error);

                        return null;
                    }

                    schema = schemaInfo.Schema;
                }

                openApiHeaders.Add(
                    name,
                    new OpenApiHeader
                    {
                        Description = description,
                        Schema = schema
                    });
            }

            return openApiHeaders;
        }