@@ -29,19 +29,6 @@ static OpenApiModelFactory()
2929 OpenApiReaderRegistry . RegisterReader ( OpenApiConstants . Json , new OpenApiJsonReader ( ) ) ;
3030 }
3131
32- /// <summary>
33- /// Loads the input URL and parses it into an Open API document.
34- /// </summary>
35- /// <param name="url">The path to the OpenAPI file.</param>
36- /// <param name="settings"> The OpenApi reader settings.</param>
37- /// <returns>An OpenAPI document instance.</returns>
38- public static ReadResult Load ( string url , OpenApiReaderSettings settings = null )
39- {
40- #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
41- return LoadAsync ( url , settings ) . GetAwaiter ( ) . GetResult ( ) ;
42- #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
43- }
44-
4532 /// <summary>
4633 /// Loads the input stream and parses it into an Open API document.
4734 /// </summary>
@@ -114,19 +101,24 @@ public static T Load<T>(MemoryStream input, OpenApiSpecVersion version, string f
114101 /// <param name="settings"> The OpenApi reader settings.</param>
115102 /// <returns></returns>
116103 public static async Task < ReadResult > LoadAsync ( string url , OpenApiReaderSettings settings = null )
117- {
118- // If url is HTTP
119- // Get the response object.
120- // Select format based on MediaType
121- // Get the stream from the response object.
122- // Load the stream.
123- // Else
124- // Determine the format from the file extension.
125- // Load the file from the local file system.
104+ {
105+ var result = await RetrieveStreamAndFormatAsync ( url ) ;
106+ return await LoadAsync ( result . Item1 , result . Item2 , settings ) ;
107+ }
126108
127- var format = GetFormat ( url ) ;
128- var stream = await GetStreamAsync ( url ) ; // Get response back and then get Content
129- return await LoadAsync ( stream , format , settings ) ;
109+ /// <summary>
110+ /// Reads the stream input and parses the fragment of an OpenAPI description into an Open API Element.
111+ /// </summary>
112+ /// <typeparam name="T"></typeparam>
113+ /// <param name="url">The path to the OpenAPI file</param>
114+ /// <param name="version">Version of the OpenAPI specification that the fragment conforms to.</param>
115+ /// <param name="settings">The OpenApiReader settings.</param>
116+ /// <returns>Instance of newly created IOpenApiElement.</returns>
117+ /// <returns>The OpenAPI element.</returns>
118+ public static async Task < T > LoadAsync < T > ( string url , OpenApiSpecVersion version , OpenApiReaderSettings settings = null ) where T : IOpenApiElement
119+ {
120+ var result = await RetrieveStreamAndFormatAsync ( url ) ;
121+ return Load < T > ( result . Item1 as MemoryStream , version , result . Item2 , out var diagnostic , settings ) ;
130122 }
131123
132124 /// <summary>
0 commit comments