55using System ;
66using System . Collections . Generic ;
77using System . IO ;
8+ using System . Linq ;
9+ using System . Text . RegularExpressions ;
810
911namespace Microsoft . Kiota . Abstractions . Serialization
1012{
@@ -24,13 +26,14 @@ public string ValidContentType
2426 }
2527 }
2628 /// <summary>
27- /// Default singleton instance of the registry to be used when registring new factories that should be available by default.
29+ /// Default singleton instance of the registry to be used when registering new factories that should be available by default.
2830 /// </summary>
2931 public static readonly ParseNodeFactoryRegistry DefaultInstance = new ( ) ;
3032 /// <summary>
3133 /// List of factories that are registered by content type.
3234 /// </summary>
3335 public Dictionary < string , IParseNodeFactory > ContentTypeAssociatedFactories { get ; set ; } = new Dictionary < string , IParseNodeFactory > ( ) ;
36+ internal static readonly Regex contentTypeVendorCleanupRegex = new ( @"[^/]+\+" , RegexOptions . Compiled ) ;
3437 /// <summary>
3538 /// Get the <see cref="IParseNode"/> instance that is the root of the content
3639 /// </summary>
@@ -43,10 +46,15 @@ public IParseNode GetRootParseNode(string contentType, Stream content)
4346 throw new ArgumentNullException ( nameof ( contentType ) ) ;
4447 _ = content ?? throw new ArgumentNullException ( nameof ( content ) ) ;
4548
46- if ( ContentTypeAssociatedFactories . ContainsKey ( contentType ) )
47- return ContentTypeAssociatedFactories [ contentType ] . GetRootParseNode ( contentType , content ) ;
48- else
49- throw new InvalidOperationException ( $ "Content type { contentType } does not have a factory registered to be parsed") ;
49+ var vendorSpecificContentType = contentType . Split ( ";" , StringSplitOptions . RemoveEmptyEntries ) . First ( ) ;
50+ if ( ContentTypeAssociatedFactories . ContainsKey ( vendorSpecificContentType ) )
51+ return ContentTypeAssociatedFactories [ vendorSpecificContentType ] . GetRootParseNode ( vendorSpecificContentType , content ) ;
52+
53+ var cleanedContentType = contentTypeVendorCleanupRegex . Replace ( vendorSpecificContentType , string . Empty ) ;
54+ if ( ContentTypeAssociatedFactories . ContainsKey ( cleanedContentType ) )
55+ return ContentTypeAssociatedFactories [ cleanedContentType ] . GetRootParseNode ( cleanedContentType , content ) ;
56+
57+ throw new InvalidOperationException ( $ "Content type { cleanedContentType } does not have a factory registered to be parsed") ;
5058 }
5159 }
5260}
0 commit comments