public string BuildInternalGenerationContext()

in src/Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration/AssemblyLoader/AssemblyLoader.cs [151:255]


        public string BuildInternalGenerationContext(
            IList<string> contractAssembliesPaths,
            IList<string> operationElements,
            IList<string> propertyElements,
            string documentVariantElementName,
            InternalSchemaGenerationSettings internalSchemaGenerationSettings)
        {
            var crefSchemaMap = new Dictionary<string, InternalSchemaGenerationInfo>();

            List<XElement> xPropertyElements = propertyElements.Select(XElement.Parse).ToList();

            var propertyMap = new Dictionary<string, string>();

            foreach (var xPropertyElement in xPropertyElements)
            {
                var name = xPropertyElement
                    .Attributes(KnownXmlStrings.Name)?.FirstOrDefault()?.Value?.Split(':')[1];
                var description = xPropertyElement.Element(KnownXmlStrings.Summary)?.Value.RemoveBlankLines();

                if (!propertyMap.ContainsKey(name))
                {
                    propertyMap.Add(name, description);
                }
            }

            var referenceRegistryMap = new Dictionary<DocumentVariantInfo, SchemaReferenceRegistry>();

            var schemaGenerationSettings = new SchemaGenerationSettings(new DefaultPropertyNameResolver());

            if (internalSchemaGenerationSettings.PropertyNameResolverName ==
                 typeof(CamelCasePropertyNameResolver).FullName)
            {
                schemaGenerationSettings = new SchemaGenerationSettings(new CamelCasePropertyNameResolver());
            }

            var internalGenerationContext = new InternalGenerationContext();

#if !NETFRAMEWORK
            var typeFetcher = new TypeFetcher(contractAssembliesPaths, Context);
#else
            var typeFetcher = new TypeFetcher(contractAssembliesPaths);           
#endif

            List<XElement> xOperationElements = operationElements.Select(XElement.Parse).ToList();

            foreach (var xOperationElement in xOperationElements)
            {
                if(!referenceRegistryMap.ContainsKey(DocumentVariantInfo.Default))
                {
                    referenceRegistryMap.Add(
                        DocumentVariantInfo.Default,
                        new SchemaReferenceRegistry(schemaGenerationSettings, propertyMap));
                }

                // Recursively build the various cref-schema, cref-fieldValue map.
                BuildMap(
                    xOperationElement,
                    crefSchemaMap,
                    internalGenerationContext.CrefToFieldValueMap,
                    typeFetcher,
                    referenceRegistryMap[DocumentVariantInfo.Default]);

                var customElements = xOperationElement.Descendants(documentVariantElementName);

                // Build the various cref-schema, cref-fieldValue map for each customElement.
                foreach (var customElement in customElements)
                {
                    var documentVariantInfo = new DocumentVariantInfo
                    {
                        Categorizer = customElement.Name.LocalName.Trim(),
                        Title = customElement.Value.Trim()
                    };

                    if (!referenceRegistryMap.ContainsKey(documentVariantInfo))
                    {
                        referenceRegistryMap.Add(
                            documentVariantInfo,
                            new SchemaReferenceRegistry(schemaGenerationSettings, propertyMap));
                    }

                    BuildMap(
                        xOperationElement,
                        crefSchemaMap,
                        internalGenerationContext.CrefToFieldValueMap,
                        typeFetcher,
                        referenceRegistryMap[documentVariantInfo]);
                }          
            }

            foreach(var key in referenceRegistryMap.Keys)
            {
                var references = referenceRegistryMap[key].References;

                internalGenerationContext.VariantSchemaReferenceMap.Add(
                    key.ToString(),
                    references.ToDictionary(k => k.Key, k => k.Value.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0)));
            }

            internalGenerationContext.CrefToSchemaMap = crefSchemaMap;

            // Serialize the context to transfer across app domain.
            var document = JsonConvert.SerializeObject(internalGenerationContext);

            return document;
        }