@@ -32,8 +32,8 @@ public class ParsingContext
3232 /// <summary>
3333 /// Initiates the parsing process. Not thread safe and should only be called once on a parsing context
3434 /// </summary>
35- /// <param name="yamlDocument"></param>
36- /// <param name="diagnostic"></param>
35+ /// <param name="yamlDocument">Yaml document to parse. </param>
36+ /// <param name="diagnostic">Diagnostic object which will return diagnostic results of the operation. </param>
3737 /// <returns>An OpenApiDocument populated based on the passed yamlDocument </returns>
3838 internal OpenApiDocument Parse ( YamlDocument yamlDocument , OpenApiDiagnostic diagnostic )
3939 {
@@ -47,13 +47,13 @@ internal OpenApiDocument Parse(YamlDocument yamlDocument, OpenApiDiagnostic diag
4747 {
4848 case string version when version == "2.0" :
4949 VersionService = new OpenApiV2VersionService ( ) ;
50- doc = this . VersionService . LoadDocument ( this . RootNode ) ;
50+ doc = VersionService . LoadDocument ( RootNode ) ;
5151 diagnostic . SpecificationVersion = OpenApiSpecVersion . OpenApi2_0 ;
5252 break ;
5353
5454 case string version when version . StartsWith ( "3.0" ) :
55- this . VersionService = new OpenApiV3VersionService ( ) ;
56- doc = this . VersionService . LoadDocument ( this . RootNode ) ;
55+ VersionService = new OpenApiV3VersionService ( ) ;
56+ doc = VersionService . LoadDocument ( RootNode ) ;
5757 diagnostic . SpecificationVersion = OpenApiSpecVersion . OpenApi3_0 ;
5858 break ;
5959
@@ -64,6 +64,34 @@ internal OpenApiDocument Parse(YamlDocument yamlDocument, OpenApiDiagnostic diag
6464 return doc ;
6565 }
6666
67+ /// <summary>
68+ /// Initiates the parsing process of a fragment. Not thread safe and should only be called once on a parsing context
69+ /// </summary>
70+ /// <param name="yamlDocument"></param>
71+ /// <param name="version">OpenAPI version of the fragment</param>
72+ /// <param name="diagnostic">Diagnostic object which will return diagnostic results of the operation.</param>
73+ /// <returns>An OpenApiDocument populated based on the passed yamlDocument </returns>
74+ internal T ParseFragment < T > ( YamlDocument yamlDocument , OpenApiSpecVersion version , OpenApiDiagnostic diagnostic ) where T : IOpenApiElement
75+ {
76+ var node = ParseNode . Create ( this , diagnostic , yamlDocument . RootNode ) ;
77+
78+ T element = default ( T ) ;
79+
80+ switch ( version )
81+ {
82+ case OpenApiSpecVersion . OpenApi2_0 :
83+ VersionService = new OpenApiV2VersionService ( ) ;
84+ element = this . VersionService . LoadElement < T > ( node ) ;
85+ break ;
86+
87+ case OpenApiSpecVersion . OpenApi3_0 :
88+ this . VersionService = new OpenApiV3VersionService ( ) ;
89+ element = this . VersionService . LoadElement < T > ( node ) ;
90+ break ;
91+ }
92+
93+ return element ;
94+ }
6795
6896 /// <summary>
6997 /// Gets the version of the Open API document.
@@ -82,20 +110,6 @@ private static string GetVersion(RootNode rootNode)
82110 return versionNode ? . GetScalarValue ( ) ;
83111 }
84112
85- private void ComputeTags ( List < OpenApiTag > tags , Func < MapNode , OpenApiTag > loadTag )
86- {
87- // Precompute the tags array so that each tag reference does not require a new deserialization.
88- var tagListPointer = new JsonPointer ( "#/tags" ) ;
89-
90- var tagListNode = RootNode . Find ( tagListPointer ) ;
91-
92- if ( tagListNode != null && tagListNode is ListNode )
93- {
94- var tagListNodeAsListNode = ( ListNode ) tagListNode ;
95- tags . AddRange ( tagListNodeAsListNode . CreateList ( loadTag ) ) ;
96- }
97- }
98-
99113 /// <summary>
100114 /// Service providing all Version specific conversion functions
101115 /// </summary>
@@ -108,7 +122,6 @@ internal IOpenApiVersionService VersionService
108122 set
109123 {
110124 _versionService = value ;
111- ComputeTags ( Tags , VersionService . TagLoader ) ;
112125 }
113126 }
114127
0 commit comments