@@ -39,7 +39,11 @@ public static ReadResult Load(MemoryStream stream,
3939 string format = null ,
4040 OpenApiReaderSettings settings = null )
4141 {
42+ #if NET6_0_OR_GREATER
43+ ArgumentNullException . ThrowIfNull ( stream ) ;
44+ #else
4245 if ( stream is null ) throw new ArgumentNullException ( nameof ( stream ) ) ;
46+ #endif
4347 settings ??= new OpenApiReaderSettings ( ) ;
4448
4549 // Get the format of the stream if not provided
@@ -112,7 +116,11 @@ public static async Task<T> LoadAsync<T>(string url, OpenApiSpecVersion version,
112116 /// <returns></returns>
113117 public static async Task < ReadResult > LoadAsync ( Stream input , string format = null , OpenApiReaderSettings settings = null , CancellationToken cancellationToken = default )
114118 {
119+ #if NET6_0_OR_GREATER
120+ ArgumentNullException . ThrowIfNull ( input ) ;
121+ #else
115122 if ( input is null ) throw new ArgumentNullException ( nameof ( input ) ) ;
123+ #endif
116124 settings ??= new OpenApiReaderSettings ( ) ;
117125
118126 Stream preparedStream ;
@@ -160,7 +168,11 @@ public static async Task<T> LoadAsync<T>(Stream input,
160168 CancellationToken token = default ) where T : IOpenApiElement
161169 {
162170 Utils . CheckArgumentNull ( openApiDocument ) ;
171+ #if NET6_0_OR_GREATER
172+ ArgumentNullException . ThrowIfNull ( input ) ;
173+ #else
163174 if ( input is null ) throw new ArgumentNullException ( nameof ( input ) ) ;
175+ #endif
164176 if ( input is MemoryStream memoryStream )
165177 {
166178 return Load < T > ( memoryStream , version , format , openApiDocument , out var _ , settings ) ;
@@ -185,7 +197,11 @@ public static ReadResult Parse(string input,
185197 string format = null ,
186198 OpenApiReaderSettings settings = null )
187199 {
188- if ( input is null ) throw new ArgumentNullException ( nameof ( input ) ) ;
200+ #if NET6_0_OR_GREATER
201+ ArgumentException . ThrowIfNullOrEmpty ( input ) ;
202+ #else
203+ if ( string . IsNullOrEmpty ( input ) ) throw new ArgumentNullException ( nameof ( input ) ) ;
204+ #endif
189205 format ??= InspectInputFormat ( input ) ;
190206 settings ??= new OpenApiReaderSettings ( ) ;
191207
@@ -212,7 +228,11 @@ public static T Parse<T>(string input,
212228 string format = null ,
213229 OpenApiReaderSettings settings = null ) where T : IOpenApiElement
214230 {
215- if ( input is null ) throw new ArgumentNullException ( nameof ( input ) ) ;
231+ #if NET6_0_OR_GREATER
232+ ArgumentException . ThrowIfNullOrEmpty ( input ) ;
233+ #else
234+ if ( string . IsNullOrEmpty ( input ) ) throw new ArgumentNullException ( nameof ( input ) ) ;
235+ #endif
216236 format ??= InspectInputFormat ( input ) ;
217237 settings ??= new OpenApiReaderSettings ( ) ;
218238 using var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( input ) ) ;
@@ -278,11 +298,12 @@ private static ReadResult InternalLoad(MemoryStream input, string format, OpenAp
278298 var response = await _httpClient . GetAsync ( url , token ) . ConfigureAwait ( false ) ;
279299 var mediaType = response . Content . Headers . ContentType . MediaType ;
280300 var contentType = mediaType . Split ( ";" . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) [ 0 ] ;
281- format = contentType . Split ( '/' ) . LastOrDefault ( ) ;
301+ format = contentType . Split ( '/' ) . Last ( ) . Split ( '+' ) . Last ( ) . Split ( '-' ) . Last ( ) ;
302+ // for non-standard MIME types e.g. text/x-yaml used in older libs or apps
282303#if NETSTANDARD2_0
283304 stream = await response . Content . ReadAsStreamAsync ( ) ;
284305#else
285- stream = await response . Content . ReadAsStreamAsync ( token ) . ConfigureAwait ( false ) ; ;
306+ stream = await response . Content . ReadAsStreamAsync ( token ) . ConfigureAwait ( false ) ;
286307#endif
287308 return ( stream , format ) ;
288309 }
@@ -321,8 +342,12 @@ private static string InspectInputFormat(string input)
321342
322343 private static string InspectStreamFormat ( Stream stream )
323344 {
324- if ( stream == null ) throw new ArgumentNullException ( nameof ( stream ) ) ;
325-
345+ #if NET6_0_OR_GREATER
346+ ArgumentNullException . ThrowIfNull ( stream ) ;
347+ #else
348+ if ( stream is null ) throw new ArgumentNullException ( nameof ( stream ) ) ;
349+ #endif
350+
326351 long initialPosition = stream . Position ;
327352 int firstByte = stream . ReadByte ( ) ;
328353
0 commit comments